generated from tophat/new-project-kit
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: check current session's pending-write queue when recalling snaps…
…hots (e.g. diffing) (#927) * fix: check current session's pending-write queue when recalling snapshots (e.g. diffing) * Make PyTestLocation hashable * Explicitly set methodname to None for doctests ----------------------------------------------------------------------------------- benchmark: 3 tests ----------------------------------------------------------------------------------- Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ test_1000x_reads 666.9710 (1.0) 748.6652 (1.0) 705.2418 (1.0) 37.2862 (1.0) 703.0552 (1.0) 70.1912 (1.07) 2;0 1.4180 (1.0) 5 1 test_standard 669.7840 (1.00) 843.3747 (1.13) 733.8905 (1.04) 68.2257 (1.83) 705.8282 (1.00) 85.6269 (1.30) 1;0 1.3626 (0.96) 5 1 test_1000x_writes 793.8229 (1.19) 937.1953 (1.25) 850.9716 (1.21) 54.4067 (1.46) 847.3260 (1.21) 65.9041 (1.0) 2;0 1.1751 (0.83) 5 1 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ * Queue writes with a dict for O(1) look-ups Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- test_1000x_reads 625.5781 (1.0) 887.4346 (1.0) 694.6221 (1.0) 109.0048 (1.0) 658.3128 (1.0) 87.7517 (1.0) 1;1 1.4396 (1.0) 5 1 test_1000x_writes 637.3099 (1.02) 1,021.0924 (1.15) 812.9789 (1.17) 150.2342 (1.38) 757.7635 (1.15) 215.9572 (2.46) 2;0 1.2300 (0.85) 5 1 test_standard 694.1814 (1.11) 1,037.9224 (1.17) 845.1463 (1.22) 136.2068 (1.25) 785.6973 (1.19) 194.9636 (2.22) 2;0 1.1832 (0.82) 5 1 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- * Use type aliases * return both keys from _snapshot_write_queue_key * Use a defaultdict * Update comments
- Loading branch information
Showing
4 changed files
with
137 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import pytest | ||
|
||
_TEST = """ | ||
def test_foo(snapshot): | ||
assert {**base} == snapshot(name="a") | ||
assert {**base, **extra} == snapshot(name="b", diff="a") | ||
""" | ||
|
||
|
||
def _make_file(testdir, base, extra): | ||
testdir.makepyfile( | ||
test_file="\n\n".join([f"base = {base!r}", f"extra = {extra!r}", _TEST]) | ||
) | ||
|
||
|
||
def _run_test(testdir, base, extra, expected_update_lines): | ||
_make_file(testdir, base=base, extra=extra) | ||
|
||
# Run with --snapshot-update, to generate/update snapshots: | ||
result = testdir.runpytest( | ||
"-v", | ||
"--snapshot-update", | ||
) | ||
result.stdout.re_match_lines((expected_update_lines,)) | ||
assert result.ret == 0 | ||
|
||
# Run without --snapshot-update, to validate the snapshots are actually up-to-date | ||
result = testdir.runpytest("-v") | ||
result.stdout.re_match_lines((r"2 snapshots passed\.",)) | ||
assert result.ret == 0 | ||
|
||
|
||
def test_diff_lifecycle(testdir) -> pytest.Testdir: | ||
# first: create both snapshots completely from scratch | ||
_run_test( | ||
testdir, | ||
base={"A": 1}, | ||
extra={"X": 10}, | ||
expected_update_lines=r"2 snapshots generated\.", | ||
) | ||
|
||
# second: edit the base data, to change the data for both snapshots (only changes the serialized output for the base snapshot `a`). | ||
_run_test( | ||
testdir, | ||
base={"A": 1, "B": 2}, | ||
extra={"X": 10}, | ||
expected_update_lines=r"1 snapshot passed. 1 snapshot updated\.", | ||
) | ||
|
||
# third: edit just the extra data (only changes the serialized output for the diff snapshot `b`) | ||
_run_test( | ||
testdir, | ||
base={"A": 1, "B": 2}, | ||
extra={"X": 10, "Y": 20}, | ||
expected_update_lines=r"1 snapshot passed. 1 snapshot updated\.", | ||
) |