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

Commit c3e921e

Browse files
committed
tests
1 parent df17e17 commit c3e921e

9 files changed

Lines changed: 185 additions & 122 deletions

File tree

.vscode/launch.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Python: tox",
9+
"type": "debugpy",
10+
"request": "launch",
11+
"program": "${workspaceFolder}/.venv/scripts/tox.exe",
12+
"args": [
13+
"-e",
14+
"py311"
15+
], // Specify the tox environment you want to run
16+
"console": "integratedTerminal"
17+
}
18+
]
19+
}

tests/conftest.py

Lines changed: 66 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,78 @@
44

55
import pytest
66
from selenium import webdriver
7-
from selenium.webdriver import DesiredCapabilities
7+
from selenium.webdriver.chrome.service import Service as ChromeService
88
from webdriver_manager.chrome import ChromeDriverManager
99

1010

11-
@pytest.fixture
12-
def driver():
13-
TEST_BROWSER = os.environ.get("TEST_BROWSER", "chrome").lower()
11+
def detect_chrome_path() -> str:
12+
locations_windows = [
13+
r"C:\Program Files\Google\Chrome\Application\chrome.exe",
14+
r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe",
15+
]
16+
locations_mac = [
17+
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
18+
"/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
19+
]
20+
locations_linux = [
21+
"/usr/bin/google-chrome",
22+
"/usr/bin/google-chrome-stable",
23+
"/usr/bin/google-chrome-beta",
24+
"/usr/bin/google-chrome-unstable",
25+
]
26+
27+
if platform.system() == "Linux":
28+
for location in locations_linux:
29+
if os.path.exists(location):
30+
return location
31+
elif platform.system() == "Darwin":
32+
for location in locations_mac:
33+
if os.path.exists(location):
34+
return location
35+
elif platform.system() == "Windows":
36+
for location in locations_windows:
37+
if os.path.exists(location):
38+
return location
1439

15-
if TEST_BROWSER == "chrome":
16-
options = webdriver.ChromeOptions()
17-
options.headless = True
18-
capabilities = DesiredCapabilities.CHROME
19-
capabilities["goog:loggingPrefs"] = {"browser": "ALL"}
40+
# @pytest.fixture
41+
# def driver():
42+
# TEST_BROWSER = os.environ.get("TEST_BROWSER", "chrome").lower()
2043

21-
if platform.system() == "Windows":
22-
options.binary_location = "C:/Program Files/Google/Chrome/Application/chrome.exe"
44+
# if TEST_BROWSER == "chrome":
45+
# chrome_options = webdriver.ChromeOptions()
46+
# # chrome_options.add_argument("--headless")
47+
# chrome_options.add_argument("--enable-logging")
48+
# chrome_options.add_argument("--no-sandbox")
49+
# chrome_options.binary_location = detect_chrome_path()
50+
51+
# # chrome_service = ChromeService(ChromeDriverManager().install())
52+
# # driver = webdriver.Chrome(service=chrome_service, options=chrome_options)
53+
# driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
54+
# driver.set_window_size(1920, 1080)
55+
# driver.implicitly_wait(10)
56+
# driver.set_page_load_timeout(10)
57+
# print(driver.current_url)
58+
# # driver = webdriver.Chrome(
59+
# # ChromeDriverManager().install(),
60+
# # options=chrome_options,
61+
# # desired_capabilities=capabilities,
62+
# # service_log_path=os.path.devnull,
63+
# # )
2364

24-
driver = webdriver.Chrome(
25-
ChromeDriverManager().install(),
26-
options=options,
27-
desired_capabilities=capabilities,
28-
service_log_path=os.path.devnull,
29-
)
65+
# # Firefox doesn't currently supported pulling JavaScript console logs, which we currently scan to affirm that
66+
# # JS/Python can communicate in some places. So for now, we can't really use firefox/geckodriver during testing.
67+
# # This may be added in the future: https://github.com/mozilla/geckodriver/issues/284
3068

31-
# Firefox doesn't currently supported pulling JavaScript console logs, which we currently scan to affirm that
32-
# JS/Python can communicate in some places. So for now, we can't really use firefox/geckodriver during testing.
33-
# This may be added in the future: https://github.com/mozilla/geckodriver/issues/284
69+
# # elif TEST_BROWSER == "firefox":
70+
# # options = webdriver.FirefoxOptions()
71+
# # options.headless = True
72+
# # capabilities = DesiredCapabilities.FIREFOX
73+
# # capabilities['loggingPrefs'] = {"browser": "ALL"}
74+
# #
75+
# # driver = webdriver.Firefox(options=options, capabilities=capabilities, service_log_path=os.path.devnull)
3476

35-
# elif TEST_BROWSER == "firefox":
36-
# options = webdriver.FirefoxOptions()
37-
# options.headless = True
38-
# capabilities = DesiredCapabilities.FIREFOX
39-
# capabilities['loggingPrefs'] = {"browser": "ALL"}
40-
#
41-
# driver = webdriver.Firefox(options=options, capabilities=capabilities, service_log_path=os.path.devnull)
77+
# else:
78+
# raise ValueError(f"Unsupported browser for testing: {TEST_BROWSER}")
4279

43-
else:
44-
raise ValueError(f"Unsupported browser for testing: {TEST_BROWSER}")
45-
46-
with mock.patch("paling.browsers.open"):
47-
yield driver
80+
# with mock.patch("paling.browsers.open"):
81+
# yield driver

tests/data/init_test/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import React, { Component } from 'react';
22
import logo from './logo.svg';
33
import './App.css';
44

5-
// Point Eel web socket to the instance
6-
export const eel = window.eel
5+
// Point Paling web socket to the instance
6+
export const paling = window.paling
77
paling.set_host('ws://localhost:8080')
88

99
// Expose the `sayHelloJS` function to Python as `say_hello_js`
1010
function sayHelloJS(x: any) {
1111
console.log('Hello from ' + x)
1212
}
13-
// WARN: must use window.eel to keep parse-able paling.expose{...}
13+
// WARN: must use window.paling to keep parse-able paling.expose{...}
1414
window.paling.expose(sayHelloJS, 'say_hello_js')
1515

1616
// Test anonymous function when minimized. See https://github.com/samuelhwilliams/Eel/issues/363

tests/data/init_test/minified.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/test_examples.py

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,71 +7,79 @@
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

12+
def test_00_index(driver=None):
13+
print("test_00_index")
1214

13-
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)
16-
assert driver.title == "Hello, World!"
15+
# def test_01_hello_world(driver: webdriver.Remote):
16+
# print("test_01_hello_world")
17+
# with get_paling_server('examples/01 - hello_world/hello.py', 'hello.html') as paling_url:
18+
# driver.get(paling_url)
19+
# assert driver.title == "Hello, World!"
1720

18-
console_logs = get_console_logs(driver, minimum_logs=2)
19-
assert "Hello from Javascript World!" in console_logs[0]['message']
20-
assert "Hello from Python World!" in console_logs[1]['message']
21+
# console_logs = get_console_logs(driver, minimum_logs=2)
22+
# assert "Hello from Javascript World!" in console_logs[0]['message']
23+
# assert "Hello from Python World!" in console_logs[1]['message']
2124

2225

23-
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)
26-
assert driver.title == "Callbacks Demo"
26+
# def test_02_callbacks(driver: webdriver.Remote):
27+
# print("test_02_callbacks")
28+
# with get_paling_server('examples/02 - callbacks/callbacks.py', 'callbacks.html') as paling_url:
29+
# driver.get(paling_url)
30+
# assert driver.title == "Callbacks Demo"
2731

28-
console_logs = get_console_logs(driver, minimum_logs=1)
29-
assert "Got this from Python:" in console_logs[0]['message']
30-
assert "callbacks.html" in console_logs[0]['message']
32+
# console_logs = get_console_logs(driver, minimum_logs=1)
33+
# assert "Got this from Python:" in console_logs[0]['message']
34+
# assert "callbacks.html" in console_logs[0]['message']
3135

3236

33-
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)
36-
assert driver.title == "Synchronous callbacks"
37+
# def test_03_callbacks(driver: webdriver.Remote):
38+
# print("test_03_callbacks")
39+
# with get_paling_server('examples/03 - sync_callbacks/sync_callbacks.py', 'sync_callbacks.html') as paling_url:
40+
# driver.get(paling_url)
41+
# assert driver.title == "Synchronous callbacks"
3742

38-
console_logs = get_console_logs(driver, minimum_logs=1)
39-
assert "Got this from Python:" in console_logs[0]['message']
40-
assert "callbacks.html" in console_logs[0]['message']
43+
# console_logs = get_console_logs(driver, minimum_logs=1)
44+
# assert "Got this from Python:" in console_logs[0]['message']
45+
# assert "callbacks.html" in console_logs[0]['message']
4146

4247

43-
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"
48+
# def test_04_file_access(driver: webdriver.Remote):
49+
# print("test_04_file_access")
50+
# with get_paling_server('examples/04 - file_access/file_access.py', 'file_access.html') as paling_url:
51+
# driver.get(paling_url)
52+
# assert driver.title == "Paling Demo"
4753

48-
with TemporaryDirectory() as temp_dir, NamedTemporaryFile(dir=temp_dir) as temp_file:
49-
driver.find_element_by_id('input-box').clear()
50-
driver.find_element_by_id('input-box').send_keys(temp_dir)
51-
time.sleep(0.5)
52-
driver.find_element_by_css_selector('button').click()
54+
# with TemporaryDirectory() as temp_dir, NamedTemporaryFile(dir=temp_dir) as temp_file:
55+
# driver.find_element_by_id('input-box').clear()
56+
# driver.find_element_by_id('input-box').send_keys(temp_dir)
57+
# time.sleep(0.5)
58+
# driver.find_element_by_css_selector('button').click()
5359

54-
assert driver.find_element_by_id('file-name').text == os.path.basename(temp_file.name)
60+
# assert driver.find_element_by_id('file-name').text == os.path.basename(temp_file.name)
5561

5662

57-
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)
60-
assert driver.title == "Hello, World!"
63+
# def test_06_jinja_templates(driver: webdriver.Remote):
64+
# print("test_06_jinja_templates")
65+
# with get_paling_server('examples/06 - jinja_templates/hello.py', 'templates/hello.html') as paling_url:
66+
# driver.get(paling_url)
67+
# assert driver.title == "Hello, World!"
6168

62-
driver.find_element_by_css_selector('a').click()
63-
WebDriverWait(driver, 2.0).until(expected_conditions.presence_of_element_located((By.XPATH, '//h1[text()="This is page 2"]')))
69+
# driver.find_element_by_css_selector('a').click()
70+
# WebDriverWait(driver, 2.0).until(expected_conditions.presence_of_element_located((By.XPATH, '//h1[text()="This is page 2"]')))
6471

6572

66-
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)
70-
# we really need to test if the page 404s, but selenium has no support for status codes
71-
# so we just test if we can get our page title
72-
assert driver.title == 'Hello, World!'
73+
# def test_10_custom_app(driver: webdriver.Remote):
74+
# print("test_10_custom_app")
75+
# # test default paling routes are working
76+
# with get_paling_server('examples/10 - custom_app_routes/custom_app.py', 'index.html') as paling_url:
77+
# driver.get(paling_url)
78+
# # we really need to test if the page 404s, but selenium has no support for status codes
79+
# # so we just test if we can get our page title
80+
# assert driver.title == 'Hello, World!'
7381

74-
# 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)
77-
assert 'Hello, World!' in driver.page_source
82+
# # test custom routes are working
83+
# with get_paling_server('examples/10 - custom_app_routes/custom_app.py', 'custom') as paling_url:
84+
# driver.get(paling_url)
85+
# assert 'Hello, World!' in driver.page_source

tests/unit/test_eel.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)