Skip to content
This repository was archived by the owner on May 14, 2026. It is now read-only.

Commit c750aa8

Browse files
authored
better visual tests (#3)
* better visual tests * support watching slow tests * fix everything * fix test * coverage * format * simplify logging shot * make image production cross platform * format * show image diff * mark comment outdated if no diff * only run failed tests twice * unmark comment as outdated when necessary * actually dont * fr dont
1 parent 163ca74 commit c750aa8

23 files changed

Lines changed: 884 additions & 558 deletions

.github/workflows/ci.yaml

Lines changed: 130 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ jobs:
120120
body-path: pytest-summary.md
121121
edit-mode: replace
122122

123-
- name: Run slow tests
123+
- name: Run slow tests (original snapshots)
124+
id: slow-tests-original
124125
run: |
125126
uv run pytest -q --junit-xml=results/pytest-slow-junit.xml -m "slow"
126127
if: ${{ github.event_name == 'pull_request' && !cancelled() }}
@@ -164,6 +165,134 @@ jobs:
164165
body-path: combined-test-summary.md
165166
edit-mode: replace
166167

168+
- name: Copy original snapshots for comparison
169+
if: ${{ github.event_name == 'pull_request' && !cancelled() && steps.slow-tests-original.outcome == 'failure' }}
170+
run: |
171+
mkdir -p original-snapshots
172+
cp tests/map/__snapshots__/test_visual/*.png original-snapshots/
173+
174+
- name: Run slow tests with snapshot update (only failed tests)
175+
id: slow-tests-updated
176+
run: |
177+
uv run pytest -q --junit-xml=results/pytest-slow-updated-junit.xml --last-failed --snapshot-update
178+
if: ${{ github.event_name == 'pull_request' && !cancelled() && steps.slow-tests-original.outcome == 'failure' }}
179+
180+
- name: Upload images to imgur and create comparison comment
181+
if: ${{ github.event_name == 'pull_request' && !cancelled() && steps.slow-tests-original.outcome == 'failure' }}
182+
run: |
183+
echo "# 📸 Visual Test Snapshots Comparison" > visual-snapshots-comment.md
184+
echo "" >> visual-snapshots-comment.md
185+
echo "Generated image snapshots from visual tests - showing original vs updated:" >> visual-snapshots-comment.md
186+
echo "" >> visual-snapshots-comment.md
187+
188+
# Function to upload image to imgur and get URL
189+
upload_to_imgur() {
190+
local image_path="$1"
191+
local response=$(curl -s -X POST \
192+
-H "Authorization: Client-ID 546c25a59c58ad7" \
193+
-F "image=@$image_path" \
194+
https://api.imgur.com/3/image)
195+
echo "$response" | jq -r '.data.link'
196+
}
197+
198+
echo "## Munich Boundary Basemap Overlays" >> visual-snapshots-comment.md
199+
echo "" >> visual-snapshots-comment.md
200+
201+
echo "### Munich Boundary Basemap Overlay" >> visual-snapshots-comment.md
202+
echo "| Original | Updated |" >> visual-snapshots-comment.md
203+
echo "|----------|---------|" >> visual-snapshots-comment.md
204+
205+
# Upload original and updated images to imgur
206+
ORIGINAL_URL=$(upload_to_imgur "original-snapshots/TestMunichBasemap.test_munich_boundary_basemap_overlay.png")
207+
UPDATED_URL=$(upload_to_imgur "tests/map/__snapshots__/test_visual/TestMunichBasemap.test_munich_boundary_basemap_overlay.png")
208+
echo "| ![Original]($ORIGINAL_URL) | ![Updated]($UPDATED_URL) |" >> visual-snapshots-comment.md
209+
echo "" >> visual-snapshots-comment.md
210+
211+
echo "### Munich Boundary Different Providers" >> visual-snapshots-comment.md
212+
echo "| Original | Updated |" >> visual-snapshots-comment.md
213+
echo "|----------|---------|" >> visual-snapshots-comment.md
214+
215+
# Upload different providers images
216+
ORIGINAL_PROVIDERS_URL=$(upload_to_imgur "original-snapshots/TestMunichBasemap.test_munich_boundary_different_providers.png")
217+
UPDATED_PROVIDERS_URL=$(upload_to_imgur "tests/map/__snapshots__/test_visual/TestMunichBasemap.test_munich_boundary_different_providers.png")
218+
echo "| ![Original]($ORIGINAL_PROVIDERS_URL) | ![Updated]($UPDATED_PROVIDERS_URL) |" >> visual-snapshots-comment.md
219+
echo "" >> visual-snapshots-comment.md
220+
221+
echo "## Individual Transit Systems" >> visual-snapshots-comment.md
222+
echo "" >> visual-snapshots-comment.md
223+
224+
echo "### U-Bahn (Subway) System" >> visual-snapshots-comment.md
225+
echo "| Original | Updated |" >> visual-snapshots-comment.md
226+
echo "|----------|---------|" >> visual-snapshots-comment.md
227+
228+
# Upload subway images
229+
ORIGINAL_SUBWAY_URL=$(upload_to_imgur "original-snapshots/TestMunichTransitSystems.test_munich_subway_system.png")
230+
UPDATED_SUBWAY_URL=$(upload_to_imgur "tests/map/__snapshots__/test_visual/TestMunichTransitSystems.test_munich_subway_system.png")
231+
echo "| ![Original]($ORIGINAL_SUBWAY_URL) | ![Updated]($UPDATED_SUBWAY_URL) |" >> visual-snapshots-comment.md
232+
echo "" >> visual-snapshots-comment.md
233+
234+
echo "### Tram System" >> visual-snapshots-comment.md
235+
echo "| Original | Updated |" >> visual-snapshots-comment.md
236+
echo "|----------|---------|" >> visual-snapshots-comment.md
237+
238+
# Upload tram images
239+
ORIGINAL_TRAM_URL=$(upload_to_imgur "original-snapshots/TestMunichTransitSystems.test_munich_tram_system.png")
240+
UPDATED_TRAM_URL=$(upload_to_imgur "tests/map/__snapshots__/test_visual/TestMunichTransitSystems.test_munich_tram_system.png")
241+
echo "| ![Original]($ORIGINAL_TRAM_URL) | ![Updated]($UPDATED_TRAM_URL) |" >> visual-snapshots-comment.md
242+
echo "" >> visual-snapshots-comment.md
243+
244+
echo "### S-Bahn (Commuter Rail) System" >> visual-snapshots-comment.md
245+
echo "| Original | Updated |" >> visual-snapshots-comment.md
246+
echo "|----------|---------|" >> visual-snapshots-comment.md
247+
248+
# Upload commuter rail images
249+
ORIGINAL_COMMUTER_URL=$(upload_to_imgur "original-snapshots/TestMunichTransitSystems.test_munich_commuter_rail_system.png")
250+
UPDATED_COMMUTER_URL=$(upload_to_imgur "tests/map/__snapshots__/test_visual/TestMunichTransitSystems.test_munich_commuter_rail_system.png")
251+
echo "| ![Original]($ORIGINAL_COMMUTER_URL) | ![Updated]($UPDATED_COMMUTER_URL) |" >> visual-snapshots-comment.md
252+
echo "" >> visual-snapshots-comment.md
253+
254+
echo "## Complete Transit System Overlays" >> visual-snapshots-comment.md
255+
echo "" >> visual-snapshots-comment.md
256+
257+
echo "### CartoDB Positron Basemap" >> visual-snapshots-comment.md
258+
echo "| Original | Updated |" >> visual-snapshots-comment.md
259+
echo "|----------|---------|" >> visual-snapshots-comment.md
260+
261+
# Upload complete system images
262+
ORIGINAL_COMPLETE_URL=$(upload_to_imgur "original-snapshots/TestMunichCompleteSystem.test_munich_complete_transit_system.png")
263+
UPDATED_COMPLETE_URL=$(upload_to_imgur "tests/map/__snapshots__/test_visual/TestMunichCompleteSystem.test_munich_complete_transit_system.png")
264+
echo "| ![Original]($ORIGINAL_COMPLETE_URL) | ![Updated]($UPDATED_COMPLETE_URL) |" >> visual-snapshots-comment.md
265+
echo "" >> visual-snapshots-comment.md
266+
267+
echo "### CartoDB Voyager Basemap" >> visual-snapshots-comment.md
268+
echo "| Original | Updated |" >> visual-snapshots-comment.md
269+
echo "|----------|---------|" >> visual-snapshots-comment.md
270+
271+
# Upload voyager images
272+
ORIGINAL_VOYAGER_URL=$(upload_to_imgur "original-snapshots/TestMunichCompleteSystem.test_munich_complete_transit_system_voyager.png")
273+
UPDATED_VOYAGER_URL=$(upload_to_imgur "tests/map/__snapshots__/test_visual/TestMunichCompleteSystem.test_munich_complete_transit_system_voyager.png")
274+
echo "| ![Original]($ORIGINAL_VOYAGER_URL) | ![Updated]($UPDATED_VOYAGER_URL) |" >> visual-snapshots-comment.md
275+
276+
- name: Create "No Diff" comment content (when tests succeed)
277+
if: ${{ github.event_name == 'pull_request' && !cancelled() && steps.slow-tests-original.outcome == 'success' }}
278+
run: |
279+
# Overwrite the comment file with "No Diff" content
280+
echo "# 📸 Visual Test Snapshots Comparison" > visual-snapshots-comment.md
281+
echo "" >> visual-snapshots-comment.md
282+
echo "**No visual changes detected** - all snapshot tests passed! ✅" >> visual-snapshots-comment.md
283+
echo "" >> visual-snapshots-comment.md
284+
echo "The visual snapshots match the expected references. No updates needed." >> visual-snapshots-comment.md
285+
286+
- name: Update visual snapshots comment
287+
uses: ./.github/actions/find-update-or-create-comment
288+
if: ${{ github.event_name == 'pull_request' && !cancelled() }}
289+
with:
290+
issue-number: ${{ github.event.pull_request.number }}
291+
body-includes: "Visual Test Snapshots Comparison"
292+
comment-author: "github-actions[bot]"
293+
body-path: visual-snapshots-comment.md
294+
edit-mode: replace
295+
167296
- name: Run tests with coverage
168297
if: ${{ !cancelled() }}
169298
run: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pip-log.txt
3838
pip-delete-this-directory.txt
3939

4040
# Unit test / coverage reports
41+
coverage.*
4142
htmlcov/
4243
.coverage
4344
.coverage.*

core/logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def configure_logging(
4141
if format_json:
4242
# JSON output for production
4343
final_processor = structlog.processors.JSONRenderer()
44-
shared_processors.extend([structlog.processors.dict_tracebacks])
44+
shared_processors.append(structlog.processors.dict_tracebacks) # pyright: ignore[reportArgumentType]
4545
else:
4646
# Console output for development - use Rich console renderer without Rich tracebacks
4747
# Rich tracebacks will be handled by pytest hooks to avoid duplication

0 commit comments

Comments
 (0)