Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add draw controls test #1178

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
ci: add draw controls test
This is using solara to run the test with a live
frontend.
maartenbreddels committed Feb 29, 2024
commit 4dc6665c44bbac671f16e41d3d7c51b5573e6f7f
8 changes: 8 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -55,3 +55,11 @@ jobs:

- name: Import check
run: python -c 'import ipyleaflet'

- name: Install playwright
run: |
pip install "solara[pytest]"
playwright install chromium
- name: Run tests
run: pytest tests -vv
1 change: 1 addition & 0 deletions environment-dev.yml
Original file line number Diff line number Diff line change
@@ -14,3 +14,4 @@ dependencies:
- pandas
- yarn~=3.0
- ruff
- pytest
68 changes: 68 additions & 0 deletions tests/draw_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from concurrent.futures import Future
from playwright.sync_api import Page, Position
from IPython.display import display

from ipyleaflet import (
Map,
DrawControl,
)


def future_trait_change(widget, attribute, timeout=2000):
future = Future()

def on_change(change):
value = change["new"]
future.set_result(value)

widget.observe(on_change, attribute)
return future


def test_draw_basics(solara_test, page_session: Page, assert_solara_snapshot):
# this all runs in process, which only works with solara
# also, this test is only with pure ipywidgets
center = [34.6252978589571, -77.34580993652344]
zoom = 10

m = Map(center=center, zoom=zoom)

dc = DrawControl(
marker={"shapeOptions": {"color": "#0000FF"}},
rectangle={"shapeOptions": {"color": "#00FF00"}},
circle={"shapeOptions": {"color": "#FF0000"}},
circlemarker={},
)
m.add(dc)

display(m)

last_draw_future = future_trait_change(dc, "last_draw")

# click around to create a rectangle
leaflet = page_session.locator(".leaflet-container")
leaflet.locator(".leaflet-draw-draw-polygon").click()
leaflet.wait_for()
x_offset = 200
leaflet.click(position=Position(x=x_offset + 100, y=100))
page_session.wait_for_timeout(100) # too fast, and it removes to wrong point
leaflet.click(position=Position(x=x_offset + 200, y=100))
page_session.wait_for_timeout(100)
leaflet.click(position=Position(x=x_offset + 300, y=150)) # lets remove this
page_session.wait_for_timeout(100)
leaflet.locator("text=Delete last point").click()
leaflet.click(position=Position(x=x_offset + 200, y=200))
page_session.wait_for_timeout(100)
leaflet.click(position=Position(x=x_offset + 100, y=200))
leaflet.locator("text=Finish").click()

# solara runs in a different thread, so we can block the pytest thread
last_draw = last_draw_future.result(timeout=1)
assert last_draw["type"] == "Feature"
geometry = last_draw["geometry"]
coordinates = geometry["coordinates"]
assert len(coordinates) == 1
assert len(coordinates[0]) == 5
assert len(coordinates[0][0]) == 2
assert coordinates[0][0] == coordinates[0][-1]
assert coordinates[0][0] != coordinates[0][1]

Unchanged files with check annotations Beta

await page.notebook.save();
for (let c = 0; c < numCellImages; ++c) {
expect(results[c]).toMatchSnapshot(

Check failure on line 74 in ui-tests/tests/ipyleaflet.test.ts

GitHub Actions / Visual Regression (3.8)

tests/ipyleaflet.test.ts:92:7 › ipyleaflet Visual Regression › Light theme: Check ipyleaflet renders

1) tests/ipyleaflet.test.ts:92:7 › ipyleaflet Visual Regression › Light theme: Check ipyleaflet renders Error: Screenshot comparison failed: 3 pixels (ratio 0.01 of all image pixels) are different. Expected: /home/runner/work/ipyleaflet/ipyleaflet/ui-tests/tests/ipyleaflet.test.ts-snapshots/light--LayerIndex-ipynb-cell-0-linux.png Received: /home/runner/work/ipyleaflet/ipyleaflet/ui-tests/test-results/tests-ipyleaflet-ipyleaflet-Visual-Regression-Light-theme-Check-ipyleaflet-renders/light--LayerIndex-ipynb-cell-0-actual.png Diff: /home/runner/work/ipyleaflet/ipyleaflet/ui-tests/test-results/tests-ipyleaflet-ipyleaflet-Visual-Regression-Light-theme-Check-ipyleaflet-renders/light--LayerIndex-ipynb-cell-0-diff.png 72 | 73 | for (let c = 0; c < numCellImages; ++c) { > 74 | expect(results[c]).toMatchSnapshot( | ^ 75 | getCaptureImageName(contextPrefix, notebook, c) 76 | ); 77 | } at testCellOutputs (/home/runner/work/ipyleaflet/ipyleaflet/ui-tests/tests/ipyleaflet.test.ts:74:26) at /home/runner/work/ipyleaflet/ipyleaflet/ui-tests/tests/ipyleaflet.test.ts:93:5

Check failure on line 74 in ui-tests/tests/ipyleaflet.test.ts

GitHub Actions / Visual Regression (3.8)

tests/ipyleaflet.test.ts:96:7 › ipyleaflet Visual Regression › Dark theme: Check ipyleaflet renders

2) tests/ipyleaflet.test.ts:96:7 › ipyleaflet Visual Regression › Dark theme: Check ipyleaflet renders Error: Screenshot comparison failed: 3 pixels (ratio 0.01 of all image pixels) are different. Expected: /home/runner/work/ipyleaflet/ipyleaflet/ui-tests/tests/ipyleaflet.test.ts-snapshots/dark--LayerIndex-ipynb-cell-0-linux.png Received: /home/runner/work/ipyleaflet/ipyleaflet/ui-tests/test-results/tests-ipyleaflet-ipyleaflet-Visual-Regression-Dark-theme-Check-ipyleaflet-renders/dark--LayerIndex-ipynb-cell-0-actual.png Diff: /home/runner/work/ipyleaflet/ipyleaflet/ui-tests/test-results/tests-ipyleaflet-ipyleaflet-Visual-Regression-Dark-theme-Check-ipyleaflet-renders/dark--LayerIndex-ipynb-cell-0-diff.png 72 | 73 | for (let c = 0; c < numCellImages; ++c) { > 74 | expect(results[c]).toMatchSnapshot( | ^ 75 | getCaptureImageName(contextPrefix, notebook, c) 76 | ); 77 | } at testCellOutputs (/home/runner/work/ipyleaflet/ipyleaflet/ui-tests/tests/ipyleaflet.test.ts:74:26) at /home/runner/work/ipyleaflet/ipyleaflet/ui-tests/tests/ipyleaflet.test.ts:97:5
getCaptureImageName(contextPrefix, notebook, c)
);
}
await page.notebook.close(true);

Check failure on line 79 in ui-tests/tests/ipyleaflet.test.ts

GitHub Actions / Visual Regression (3.8)

tests/ipyleaflet.test.ts:92:7 › ipyleaflet Visual Regression › Light theme: Check ipyleaflet renders

1) tests/ipyleaflet.test.ts:92:7 › ipyleaflet Visual Regression › Light theme: Check ipyleaflet renders Error: page.evaluate: Execution context was destroyed, most likely because of a navigation. 77 | } 78 | > 79 | await page.notebook.close(true); | ^ 80 | } 81 | }; 82 | at NotebookHelper.revertChanges (/home/runner/work/ipyleaflet/ipyleaflet/ui-tests/node_modules/@jupyterlab/galata/src/helpers/notebook.ts:253:21) at NotebookHelper.close (/home/runner/work/ipyleaflet/ipyleaflet/ui-tests/node_modules/@jupyterlab/galata/src/helpers/notebook.ts:416:13) at testCellOutputs (/home/runner/work/ipyleaflet/ipyleaflet/ui-tests/tests/ipyleaflet.test.ts:79:5) at /home/runner/work/ipyleaflet/ipyleaflet/ui-tests/tests/ipyleaflet.test.ts:93:5
}
};