Skip to content
This repository was archived by the owner on Jul 26, 2024. It is now read-only.

Commit 0935329

Browse files
authored
Merge pull request #19 from python-paling:tests
Refactor test_examples.py and test_paling.py for Paling server integration tests
2 parents 7c0b368 + 0f3c37f commit 0935329

3 files changed

Lines changed: 24 additions & 24 deletions

File tree

tests/integration/test_examples.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
from selenium.webdriver.support import expected_conditions
88
from selenium.webdriver.support.wait import WebDriverWait
99

10-
from tests.utils import get_eel_server, get_console_logs
10+
from tests.utils import get_paling_server, get_console_logs
1111

1212

1313
def test_01_hello_world(driver):
14-
with get_eel_server('examples/01 - hello_world/hello.py', 'hello.html') as eel_url:
15-
driver.get(eel_url)
14+
with get_paling_server('examples/01 - hello_world/hello.py', 'hello.html') as paling_url:
15+
driver.get(paling_url)
1616
assert driver.title == "Hello, World!"
1717

1818
console_logs = get_console_logs(driver, minimum_logs=2)
@@ -21,8 +21,8 @@ def test_01_hello_world(driver):
2121

2222

2323
def test_02_callbacks(driver):
24-
with get_eel_server('examples/02 - callbacks/callbacks.py', 'callbacks.html') as eel_url:
25-
driver.get(eel_url)
24+
with get_paling_server('examples/02 - callbacks/callbacks.py', 'callbacks.html') as paling_url:
25+
driver.get(paling_url)
2626
assert driver.title == "Callbacks Demo"
2727

2828
console_logs = get_console_logs(driver, minimum_logs=1)
@@ -31,8 +31,8 @@ def test_02_callbacks(driver):
3131

3232

3333
def test_03_callbacks(driver):
34-
with get_eel_server('examples/03 - sync_callbacks/sync_callbacks.py', 'sync_callbacks.html') as eel_url:
35-
driver.get(eel_url)
34+
with get_paling_server('examples/03 - sync_callbacks/sync_callbacks.py', 'sync_callbacks.html') as paling_url:
35+
driver.get(paling_url)
3636
assert driver.title == "Synchronous callbacks"
3737

3838
console_logs = get_console_logs(driver, minimum_logs=1)
@@ -41,9 +41,9 @@ def test_03_callbacks(driver):
4141

4242

4343
def test_04_file_access(driver: webdriver.Remote):
44-
with get_eel_server('examples/04 - file_access/file_access.py', 'file_access.html') as eel_url:
45-
driver.get(eel_url)
46-
assert driver.title == "Eel Demo"
44+
with get_paling_server('examples/04 - file_access/file_access.py', 'file_access.html') as paling_url:
45+
driver.get(paling_url)
46+
assert driver.title == "Paling Demo"
4747

4848
with TemporaryDirectory() as temp_dir, NamedTemporaryFile(dir=temp_dir) as temp_file:
4949
driver.find_element_by_id('input-box').clear()
@@ -55,23 +55,23 @@ def test_04_file_access(driver: webdriver.Remote):
5555

5656

5757
def test_06_jinja_templates(driver: webdriver.Remote):
58-
with get_eel_server('examples/06 - jinja_templates/hello.py', 'templates/hello.html') as eel_url:
59-
driver.get(eel_url)
58+
with get_paling_server('examples/06 - jinja_templates/hello.py', 'templates/hello.html') as paling_url:
59+
driver.get(paling_url)
6060
assert driver.title == "Hello, World!"
6161

6262
driver.find_element_by_css_selector('a').click()
6363
WebDriverWait(driver, 2.0).until(expected_conditions.presence_of_element_located((By.XPATH, '//h1[text()="This is page 2"]')))
6464

6565

6666
def test_10_custom_app(driver: webdriver.Remote):
67-
# test default eel routes are working
68-
with get_eel_server('examples/10 - custom_app_routes/custom_app.py', 'index.html') as eel_url:
69-
driver.get(eel_url)
67+
# test default paling routes are working
68+
with get_paling_server('examples/10 - custom_app_routes/custom_app.py', 'index.html') as paling_url:
69+
driver.get(paling_url)
7070
# we really need to test if the page 404s, but selenium has no support for status codes
7171
# so we just test if we can get our page title
7272
assert driver.title == 'Hello, World!'
7373

7474
# test custom routes are working
75-
with get_eel_server('examples/10 - custom_app_routes/custom_app.py', 'custom') as eel_url:
76-
driver.get(eel_url)
75+
with get_paling_server('examples/10 - custom_app_routes/custom_app.py', 'custom') as paling_url:
76+
driver.get(paling_url)
7777
assert 'Hello, World!' in driver.page_source

tests/utils.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ def get_process_listening_port(proc):
3838

3939

4040
@contextlib.contextmanager
41-
def get_eel_server(example_py, start_html):
42-
"""Run an Eel example with the mode/port overridden so that no browser is launched and a random port is assigned"""
41+
def get_paling_server(example_py, start_html):
42+
"""Run an Paling example with the mode/port overridden so that no browser is launched and a random port is assigned"""
4343
test = None
4444

4545
try:
4646
with tempfile.NamedTemporaryFile(mode='w', dir=os.path.dirname(example_py), delete=False) as test:
4747
# We want to run the examples unmodified to keep the test as realistic as possible, but all of the examples
48-
# want to launch browsers, which won't be supported in CI. The below script will configure eel to open on
48+
# want to launch browsers, which won't be supported in CI. The below script will configure paling to open on
4949
# a random port and not open a browser, before importing the Python example file - which will then
50-
# do the rest of the set up and start the eel server. This is definitely hacky, and means we can't
50+
# do the rest of the set up and start the paling server. This is definitely hacky, and means we can't
5151
# test mode/port settings for examples ... but this is OK for now.
5252
test.write(f"""
53-
import eel
53+
import paling
5454
5555
paling._start_args['mode'] = None
5656
paling._start_args['port'] = 0
@@ -61,9 +61,9 @@ def get_eel_server(example_py, start_html):
6161
[sys.executable, test.name],
6262
cwd=os.path.dirname(example_py),
6363
)
64-
eel_port = get_process_listening_port(proc)
64+
paling_port = get_process_listening_port(proc)
6565

66-
yield f"http://localhost:{eel_port}/{start_html}"
66+
yield f"http://localhost:{paling_port}/{start_html}"
6767

6868
proc.terminate()
6969

0 commit comments

Comments
 (0)