diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-0.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-0.svg new file mode 100644 index 00000000..72ebf366 --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-0.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2func_for_loop"/tmp/test_results/func_for_loop"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_for_loop"id7strid7id6tupleoutput_filepathid1memory_viz_argsid3includeid6id2SnapshotManager diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-1.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-1.svg new file mode 100644 index 00000000..aa10a5ff --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-1.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2numsid9func_for_loop"/tmp/test_results/func_for_loop"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_for_loop"id7strid7id6tuple1id8intoutput_filepathid1memory_viz_argsid3includeid6snapshot_countsid8id2SnapshotManager2id10int3id11intid8id10id11id9list diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-2.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-2.svg new file mode 100644 index 00000000..5fc9ab24 --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-2.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2numsid9iid12func_for_loop"/tmp/test_results/func_for_loop"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_for_loop"id7strid7id6tuple2id8intoutput_filepathid1memory_viz_argsid3includeid6snapshot_countsid8id2SnapshotManager1id10int3id11intid10id8id11id9list0id12int diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-3.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-3.svg new file mode 100644 index 00000000..76f0129e --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-3.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2numsid9iid11func_for_loop"/tmp/test_results/func_for_loop"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_for_loop"id7strid7id6tuple3id8intoutput_filepathid1memory_viz_argsid3includeid6snapshot_countsid8id2SnapshotManager2id10intid10id10id8id9list0id11int diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-4.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-4.svg new file mode 100644 index 00000000..2882a50e --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-4.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2numsid9iid12func_for_loop"/tmp/test_results/func_for_loop"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_for_loop"id7strid7id6tuple4id8intoutput_filepathid1memory_viz_argsid3includeid6snapshot_countsid8id2SnapshotManager2id10int3id11intid10id10id11id9list1id12int diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-5.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-5.svg new file mode 100644 index 00000000..d390f299 --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-5.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2numsid9iid12func_for_loop"/tmp/test_results/func_for_loop"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_for_loop"id7strid7id6tuple5id8intoutput_filepathid1memory_viz_argsid3includeid6snapshot_countsid8id2SnapshotManager2id10int3id11intid10id11id11id9list1id12int diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-6.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-6.svg new file mode 100644 index 00000000..6043a87a --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-6.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2numsid9iid10func_for_loop"/tmp/test_results/func_for_loop"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_for_loop"id7strid7id6tuple6id8intoutput_filepathid1memory_viz_argsid3includeid6snapshot_countsid8id2SnapshotManager2id10int3id11intid10id11id11id9list diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-7.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-7.svg new file mode 100644 index 00000000..04e5920f --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-7.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2numsid9iid10func_for_loop"/tmp/test_results/func_for_loop"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_for_loop"id7strid7id6tuple7id8intoutput_filepathid1memory_viz_argsid3includeid6snapshot_countsid8id2SnapshotManager2id10int3id11int4id12intid10id11id12id9list diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-8.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-8.svg new file mode 100644 index 00000000..b5105950 --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_for_loop/snapshot-8.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2numsid9iid10func_for_loop"/tmp/test_results/func_for_loop"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_for_loop"id7strid7id6tuple8id8intoutput_filepathid1memory_viz_argsid3includeid6snapshot_countsid8id2SnapshotManager2id10int3id11int4id12intid10id11id12id9list diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_multi_line/snapshot-0.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_multi_line/snapshot-0.svg new file mode 100644 index 00000000..b0573526 --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_multi_line/snapshot-0.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2func_multi_line"/tmp/test_results/func_multi_line"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_multi_line"id7strid7id6tupleoutput_filepathid1memory_viz_argsid3includeid6id2SnapshotManager diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_multi_line/snapshot-1.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_multi_line/snapshot-1.svg new file mode 100644 index 00000000..5c434546 --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_multi_line/snapshot-1.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2numid9func_multi_line"/tmp/test_results/func_multi_line"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_multi_line"id7strid7id6tuple1id8intoutput_filepathid1memory_viz_argsid3includeid6snapshot_countsid8id2SnapshotManager123id9int diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_multi_line/snapshot-2.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_multi_line/snapshot-2.svg new file mode 100644 index 00000000..790deaf9 --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_multi_line/snapshot-2.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2numid9some_stringid10func_multi_line"/tmp/test_results/func_multi_line"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_multi_line"id7strid7id6tuple2id8intoutput_filepathid1memory_viz_argsid3includeid6snapshot_countsid8id2SnapshotManager123id9int"Hello, world"id10str diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_multi_line/snapshot-3.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_multi_line/snapshot-3.svg new file mode 100644 index 00000000..09b73eb2 --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_multi_line/snapshot-3.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2numid9some_stringid10num2id11func_multi_line"/tmp/test_results/func_multi_line"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_multi_line"id7strid7id6tuple3id8intoutput_filepathid1memory_viz_argsid3includeid6snapshot_countsid8id2SnapshotManager123id9int"Hello, world"id10str321id11int diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_multi_line/snapshot-4.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_multi_line/snapshot-4.svg new file mode 100644 index 00000000..844c2042 --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_multi_line/snapshot-4.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2numid9some_stringid10num2id11arrid12func_multi_line"/tmp/test_results/func_multi_line"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_multi_line"id7strid7id6tuple4id8intoutput_filepathid1memory_viz_argsid3includeid6snapshot_countsid8id2SnapshotManager123id9int"Hello, world"id10str321id11int"string 123321"id13strid10id13id12list diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_mutation/snapshot-0.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_mutation/snapshot-0.svg new file mode 100644 index 00000000..74686a88 --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_mutation/snapshot-0.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2func_mutation"/tmp/test_results/func_mutation"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_mutation"id7strid7id6tupleoutput_filepathid1memory_viz_argsid3includeid6id2SnapshotManager diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_mutation/snapshot-1.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_mutation/snapshot-1.svg new file mode 100644 index 00000000..899f18a1 --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_mutation/snapshot-1.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2numid9func_mutation"/tmp/test_results/func_mutation"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_mutation"id7strid7id6tuple1id8intoutput_filepathid1memory_viz_argsid3includeid6snapshot_countsid8id2SnapshotManager123id9int diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_mutation/snapshot-2.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_mutation/snapshot-2.svg new file mode 100644 index 00000000..b86d9ff0 --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_mutation/snapshot-2.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2numid9func_mutation"/tmp/test_results/func_mutation"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_mutation"id7strid7id6tuple2id8intoutput_filepathid1memory_viz_argsid3includeid6snapshot_countsid8id2SnapshotManager321id9int diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_one_line/snapshot-0.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_one_line/snapshot-0.svg new file mode 100644 index 00000000..af4f1f13 --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_one_line/snapshot-0.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2func_one_line"/tmp/test_results/func_one_line"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_one_line"id7strid7id6tupleoutput_filepathid1memory_viz_argsid3includeid6id2SnapshotManager diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_one_line/snapshot-1.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_one_line/snapshot-1.svg new file mode 100644 index 00000000..6e976d93 --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_one_line/snapshot-1.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2numid9func_one_line"/tmp/test_results/func_one_line"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_one_line"id7strid7id6tuple1id8intoutput_filepathid1memory_viz_argsid3includeid6snapshot_countsid8id2SnapshotManager123id9int diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-0.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-0.svg new file mode 100644 index 00000000..d361ecff --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-0.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2func_while"/tmp/test_results/func_while"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_while"id7strid7id6tupleoutput_filepathid1memory_viz_argsid3includeid6id2SnapshotManager diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-1.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-1.svg new file mode 100644 index 00000000..f20565a5 --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-1.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2numid9func_while"/tmp/test_results/func_while"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_while"id7strid7id6tuple1id8intoutput_filepathid1memory_viz_argsid3includeid6snapshot_countsid8id2SnapshotManager0id9int diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-2.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-2.svg new file mode 100644 index 00000000..a888424d --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-2.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2numid9func_while"/tmp/test_results/func_while"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_while"id7strid7id6tuple2id8intoutput_filepathid1memory_viz_argsid3includeid6snapshot_countsid8id2SnapshotManager0id9int diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-3.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-3.svg new file mode 100644 index 00000000..bfd556ae --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-3.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2numid9func_while"/tmp/test_results/func_while"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_while"id7strid7id6tuple3id8intoutput_filepathid1memory_viz_argsid3includeid6snapshot_countsid8id2SnapshotManager1id9int diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-4.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-4.svg new file mode 100644 index 00000000..98f6d556 --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-4.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2numid9func_while"/tmp/test_results/func_while"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_while"id7strid7id6tuple4id8intoutput_filepathid1memory_viz_argsid3includeid6snapshot_countsid8id2SnapshotManager1id9int diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-5.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-5.svg new file mode 100644 index 00000000..4bc3be8b --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-5.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2numid9func_while"/tmp/test_results/func_while"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_while"id7strid7id6tuple5id8intoutput_filepathid1memory_viz_argsid3includeid6snapshot_countsid8id2SnapshotManager2id9int diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-6.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-6.svg new file mode 100644 index 00000000..ad1fbe12 --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-6.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2numid9func_while"/tmp/test_results/func_while"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_while"id7strid7id6tuple6id8intoutput_filepathid1memory_viz_argsid3includeid6snapshot_countsid8id2SnapshotManager2id9int diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-7.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-7.svg new file mode 100644 index 00000000..0a6d8116 --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-7.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2numid9func_while"/tmp/test_results/func_while"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_while"id7strid7id6tuple7id8intoutput_filepathid1memory_viz_argsid3includeid6snapshot_countsid8id2SnapshotManager3id9int diff --git a/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-8.svg b/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-8.svg new file mode 100644 index 00000000..d3eda534 --- /dev/null +++ b/tests/test_debug/snapshot_manager_testing_snapshots/func_while/snapshot-8.svg @@ -0,0 +1,33 @@ +output_pathid1managerid2numid9func_while"/tmp/test_results/func_while"id1str"--roughjs-config"id4str"seed=12345"id5strid4id5id3list"func_while"id7strid7id6tuple8id8intoutput_filepathid1memory_viz_argsid3includeid6snapshot_countsid8id2SnapshotManager3id9int diff --git a/tests/test_debug/test_snapshot_manager.py b/tests/test_debug/test_snapshot_manager.py index 37098b98..f8e5431a 100644 --- a/tests/test_debug/test_snapshot_manager.py +++ b/tests/test_debug/test_snapshot_manager.py @@ -1,13 +1,15 @@ from __future__ import annotations import os.path -import shutil import pytest +from pytest_snapshot.plugin import Snapshot from python_ta.debug import SnapshotManager -SNAPSHOT_DIR = "snapshot_manager_testing_snapshots" +SNAPSHOT_DIR = os.path.join( + os.path.dirname(os.path.realpath(__file__)), "snapshot_manager_testing_snapshots" +) TEST_RESULTS_DIR = "/tmp/test_results" @@ -61,35 +63,27 @@ def func_while(output_path=None) -> SnapshotManager: return manager -def assert_output_files_match(snapshot_count: int, output_path: str, expected_path: str): +def assert_output_files_match( + snapshot_count: int, output_path: str, snapshot: Snapshot, function_name: str +): + actual_svgs = {} for i in range(snapshot_count): - actual_file = os.path.join(output_path, f"snapshot-{i}.svg") - expected_file = os.path.join(expected_path, f"snapshot-{i}.svg") - with open(actual_file) as actual_file, open(expected_file) as expected_file: + file_name = f"snapshot-{i}.svg" + actual_file = os.path.join(output_path, file_name) + with open(actual_file) as actual_file: actual_svg = actual_file.read() - expected_svg = expected_file.read() - assert actual_svg == expected_svg + actual_svgs[file_name] = actual_svg + snapshot.assert_match_dir(actual_svgs, function_name) @pytest.mark.parametrize( "test_func", [func_one_line, func_multi_line, func_mutation, func_for_loop, func_while] ) -# TODO: find a good way to take snapshots -def test_snapshot_manger(test_func): - # set up to ensure the output dir exists - save_snapshots = False - +def test_snapshot_manger(test_func, snapshot): + snapshot.snapshot_dir = SNAPSHOT_DIR actual_dir = os.path.join(TEST_RESULTS_DIR, test_func.__name__) os.makedirs(actual_dir, exist_ok=True) - manager = test_func(actual_dir) - - expected_dir = os.path.join(SNAPSHOT_DIR, test_func.__name__) - if save_snapshots: - shutil.rmtree(expected_dir, ignore_errors=True) - shutil.copytree(actual_dir, expected_dir, dirs_exist_ok=True) - else: - assert_output_files_match(manager.get_snapshot_count(), actual_dir, expected_dir) - - # clean up the test dir - shutil.rmtree(actual_dir) + assert_output_files_match( + manager.get_snapshot_count(), actual_dir, snapshot, test_func.__name__ + )