Skip to content

Commit 7e0f104

Browse files
committed
Separate test server module
1 parent 02b0334 commit 7e0f104

File tree

4 files changed

+54
-37
lines changed

4 files changed

+54
-37
lines changed

.noserc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[nosetests]
22
logging-level=INFO
3-
no-path-adjustment=true
3+
# no-path-adjustment=true
44
# with-coverage=true
55
# cover-package=pyppeteer

tests/__init__.py

-2
This file was deleted.

tests/server.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
from tornado import web
5+
6+
7+
BASE_HTML = '''
8+
<html>
9+
<head><title>main</title></head>
10+
<body>
11+
<h1 id="hello">Hello</h1>
12+
<a id="link1" href="./1">link1</a>
13+
<a id="link2" href="./2">link2</a>
14+
</body>
15+
</html>
16+
'''
17+
18+
19+
class MainHandler(web.RequestHandler):
20+
def get(self) -> None:
21+
self.write(BASE_HTML)
22+
23+
24+
class LinkHandler1(web.RequestHandler):
25+
def get(self) -> None:
26+
self.write('''
27+
<head><title>link1</title></head>
28+
<h1 id="link1">Link1</h1>
29+
<a id="back1" href="./">back1</a>
30+
''')
31+
32+
33+
class RedirectHandler1(web.RequestHandler):
34+
def get(self) -> None:
35+
self.redirect('/redirect2')
36+
37+
38+
class RedirectHandler2(web.RequestHandler):
39+
def get(self) -> None:
40+
self.write('<h1 id="red2">redirect2</h1>')
41+
42+
43+
def get_application() -> web.Application:
44+
return web.Application([
45+
('/', MainHandler),
46+
('/1', LinkHandler1),
47+
('/redirect1', RedirectHandler1),
48+
('/redirect2', RedirectHandler2),
49+
], logging='error')

tests/test_pyppeteer.py

+4-34
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,24 @@
88
Tests for `pyppeteer` module.
99
"""
1010

11-
import logging
1211
import unittest
1312

1413
from syncer import sync
15-
from tornado import web
1614

1715
from pyppeteer.launcher import launch
1816
from pyppeteer.util import install_asyncio, get_free_port
17+
from server import get_application, BASE_HTML
1918

2019

2120
def setUpModule():
22-
logging.getLogger('tornado').setLevel(logging.ERROR)
2321
install_asyncio()
2422

2523

26-
BASE_HTML = '''
27-
<html>
28-
<head><title>main</title></head>
29-
<body>
30-
<h1 id="hello">Hello</h1>
31-
<a id="link1" href="./1">link1</a>
32-
<a id="link2" href="./2">link2</a>
33-
</body>
34-
</html>
35-
'''
36-
37-
38-
class MainHandler(web.RequestHandler):
39-
def get(self):
40-
self.write(BASE_HTML)
41-
42-
43-
class LinkHandler1(web.RequestHandler):
44-
def get(self):
45-
self.write('''
46-
<head><title>link1</title></head>
47-
<h1 id="link1">Link1</h1>
48-
<a id="back1" href="./">back1</a>
49-
''')
50-
51-
5224
class TestPyppeteer(unittest.TestCase):
5325
@classmethod
5426
def setUpClass(cls):
5527
cls.port = get_free_port()
56-
cls.app = web.Application([
57-
('/', MainHandler),
58-
('/1', LinkHandler1),
59-
], logging='error')
28+
cls.app = get_application()
6029
cls.server = cls.app.listen(cls.port)
6130
cls.browser = launch()
6231
cls.page = sync(cls.browser.newPage())
@@ -67,7 +36,8 @@ def tearDownModule(cls):
6736
cls.server.stop()
6837

6938
def setUp(self):
70-
sync(self.page.goto('http://localhost:' + str(self.port)))
39+
self.url = 'http://localhost:' + str(self.port)
40+
sync(self.page.goto(self.url))
7141

7242
@sync
7343
async def test_get(self):

0 commit comments

Comments
 (0)