Repository navigation
test(snapshot): cover the Engine.snapshot() contract - #203
Open
harsh-thakkar7 wants to merge 1 commit into
Open
harsh-thakkar7 wants to merge 1 commit into
harsh-thakkar7 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #57
Problem
Engine.snapshot()is the single interface between the engine and every front-end — the GUI polls it ~12 times a second,moon_bridge.pyserves it over the loopback API, andrender_gui.py/integration_http.pydepend on its shape. It had no unit tests: everything it produced was verified only by running a real download and looking at the window. #58 (a clock that never stopped) lived in this method and nothing caught it, because catching it needed nothing more than calling the method twice and comparing two numbers.Change
One new file,
tests/test_snapshot.py— 11 tests, no production code changed. The mid-run states are produced by setting the counterssnapshot()reads directly rather than by driving a download, so what is under test is the snapshot contract and not the downloader. The five behaviours from the issue, each pinned by tests named for it:test_fresh_engine_reports_idle_with_zeroed_counters:stage == "idle",elapsed_s == 0, all counters zero, empty log,cursor == 0, and it does not raise.test_stage_is_extracting_while_links_remain_unextracted,test_stage_is_downloading_once_every_link_is_extracted,test_stage_is_done_once_every_download_finished.test_log_cursor_returns_every_line_when_starting_from_zero,test_a_second_read_with_the_same_cursor_returns_nothing(the no-gaps contract),test_lines_logged_after_the_cursor_come_back_on_the_next_read.test_speed_and_eta_are_zero_before_any_run,test_eta_stays_zero_once_downloads_are_in_flight(files downloading, no byte samples yet: no division by zero, no clamped ceiling).test_start_clears_the_previous_runs_totals: a real run through thebrowser_callsfixture, started over the remains of a finished seven-link run; asserts the totals are the new run's and the oldok == 7did not leak in.The clock test
test_a_finished_run_keeps_stage_done_and_stops_the_clockis the test that would have caught #58: a finished run must reportstage == "done"and the sameelapsed_son every later snapshot. #58 is closed, so it asserts the shipped behaviour rather than failing on it.Verification
python -m pytest tests/ -q→ 181 passed (170 before this file), no browser and no network; the whole file runs in ~1.1 sruff check .→ clean (ruff 0.16.4; CI pins 0.16.1)snapshot()did not need restructuring to be testedNot covered automatically: nothing in the GUI itself. These tests pin the numbers
snapshot()returns; whether a given widget renders them correctly still needs the eye check onlyrender_gui.pycan give (per #179).