From fde01ea57d79ef75aee407e7568f5cdcf980974b Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Fri, 10 Oct 2025 09:50:42 -0400 Subject: [PATCH 1/3] build temp dir structure --- tests/conftest.py | 78 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 3eaae7d..ebcfad9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -22,6 +22,84 @@ def tmp_examples(tmp_path_factory): yield tmp_examples +@pytest.fixture(scope="session") +def example_cases(tmp_path_factory): + """Copy the entire examples tree into a temp directory once per test + session. + + Returns the path to that copy. + """ + root_temp_dir = tmp_path_factory.mktemp("temp") + + # case 1: pack with no examples + case1ex_dir = root_temp_dir / "case1" / "docs" / "examples" + case1 = case1ex_dir / "empty_pack" # empty_pack + case1.mkdir(parents=True, exist_ok=True) + case1req_dir = root_temp_dir / "case1" / "requirements" / "packs" + case1req_dir.mkdir(parents=True, exist_ok=True) + + # Case 2: pack with multiple examples + case2ex_dir = root_temp_dir / "case2" / "docs" / "examples" + case2a = ( + case2ex_dir / "full_pack" / "ex1" / "solution" / "diffpy-cmi" + ) # full_pack, ex1 + case2a.mkdir(parents=True, exist_ok=True) + (case2a / "script1.py").touch() + case2b = ( + case2ex_dir / "full_pack" / "ex2" / "random" / "path" + ) # full_pack, ex2 + case2b.mkdir(parents=True, exist_ok=True) + (case2b / "script1.py").touch() + (case2b / "script2.py").touch() + case2req_dir = root_temp_dir / "case2" / "requirements" / "packs" + case2req_dir.mkdir(parents=True, exist_ok=True) + + # Case 3: multiple packs with multiple examples + case3ex_dir = root_temp_dir / "case3" / "docs" / "examples" + case3a = case3ex_dir / "packA" / "ex1" # packA, ex1 + case3a.mkdir(parents=True, exist_ok=True) + (case3a / "script1.py").touch() + case3b = case3ex_dir / "packA" / "ex2" / "solutions" # packA, ex2 + case3b.mkdir(parents=True, exist_ok=True) + (case3b / "script2.py").touch() + case3c = ( + case3ex_dir / "packB" / "ex3" / "more" / "random" / "path" + ) # packB, ex3 + case3c.mkdir(parents=True, exist_ok=True) + (case3c / "script3.py").touch() + (case3c / "script4.py").touch() + case3req_dir = root_temp_dir / "case3" / "requirements" / "packs" + case3req_dir.mkdir(parents=True, exist_ok=True) + + # Case 4: no pack found (empty directory) + case4ex_dir = root_temp_dir / "case4" / "docs" / "examples" + case4 = case4ex_dir + case4.mkdir(parents=True, exist_ok=True) + case4req_dir = root_temp_dir / "case4" / "requirements" / "packs" + case4req_dir.mkdir(parents=True, exist_ok=True) + + # Case 5: multiple packs with the same example names + case5ex_dir = root_temp_dir / "case5" / "docs" / "examples" + case5a = case5ex_dir / "packA" / "ex1" / "path1" # packA, ex1 + case5a.mkdir(parents=True, exist_ok=True) + (case5a / "script1.py").touch() + case5b = case5ex_dir / "packB" / "ex1" / "path2" # packB, ex1 + case5b.mkdir(parents=True, exist_ok=True) + (case5b / "script2.py").touch() + case5req_dir = root_temp_dir / "case5" / "requirements" / "packs" + case5req_dir.mkdir(parents=True, exist_ok=True) + + yield root_temp_dir + + +@pytest.fixture(scope="session") +def target_dir(tmp_path_factory): + """Create a temporary directory to serve as the target for copying + examples.""" + target_directory = tmp_path_factory.mktemp("copy_target") + yield target_directory + + @pytest.fixture(scope="session", autouse=True) def use_headless_matplotlib(): """Force matplotlib to use a headless backend during tests.""" From c60547148f205f98cc34c64b4d12d3e9471586e9 Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Fri, 10 Oct 2025 09:51:29 -0400 Subject: [PATCH 2/3] news --- news/tmpdir-build.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 news/tmpdir-build.rst diff --git a/news/tmpdir-build.rst b/news/tmpdir-build.rst new file mode 100644 index 0000000..0042860 --- /dev/null +++ b/news/tmpdir-build.rst @@ -0,0 +1,23 @@ +**Added:** + +* Add temp dir fixture for testing. + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* From 5ac0487a56a3d8b41ffb94198de9630f22c41f1c Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Fri, 10 Oct 2025 09:54:00 -0400 Subject: [PATCH 3/3] rm unrelated function --- tests/conftest.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index ebcfad9..5a4edca 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -92,14 +92,6 @@ def example_cases(tmp_path_factory): yield root_temp_dir -@pytest.fixture(scope="session") -def target_dir(tmp_path_factory): - """Create a temporary directory to serve as the target for copying - examples.""" - target_directory = tmp_path_factory.mktemp("copy_target") - yield target_directory - - @pytest.fixture(scope="session", autouse=True) def use_headless_matplotlib(): """Force matplotlib to use a headless backend during tests."""