|
7 | 7 | ``makeArtifacts`` suite and verifies that the Python NDI stack can: |
8 | 8 |
|
9 | 9 | 1. Open the copied session database. |
10 | | -2. Reconstruct probes that match ``probes.json``. |
11 | | -3. Load every document whose JSON was exported to ``jsonDocuments/``. |
| 10 | +2. Load every document whose JSON was exported to ``jsonDocuments/``. |
| 11 | +3. Reconstruct probes that match ``probes.json``. |
12 | 12 |
|
13 | 13 | The test is parameterized over ``source_type`` so that a single test class |
14 | 14 | covers both ``matlabArtifacts`` and ``pythonArtifacts``. |
@@ -37,57 +37,21 @@ def _artifact_dir(self, source_type: str): |
37 | 37 | SYMMETRY_BASE / source_type / "session" / "buildSession" / "testBuildSessionArtifacts" |
38 | 38 | ) |
39 | 39 |
|
40 | | - # -- tests --------------------------------------------------------------- |
41 | | - |
42 | | - def test_build_session_artifacts(self, source_type): |
43 | | - """Verify session artifacts from the given source.""" |
| 40 | + def _open_session(self, source_type): |
44 | 41 | artifact_dir = self._artifact_dir(source_type) |
45 | | - |
46 | 42 | if not artifact_dir.exists(): |
47 | 43 | pytest.skip( |
48 | 44 | f"Artifact directory from {source_type} does not exist. " |
49 | 45 | f"Run the corresponding makeArtifacts suite first." |
50 | 46 | ) |
| 47 | + return artifact_dir, DirSession("exp1", artifact_dir) |
51 | 48 |
|
52 | | - # 1. Open the NDI session ------------------------------------------- |
53 | | - session = DirSession("exp1", artifact_dir) |
| 49 | + # -- tests (documents first, then probes) -------------------------------- |
54 | 50 |
|
55 | | - # 2. Verify probes -------------------------------------------------- |
56 | | - probes_json_path = artifact_dir / "probes.json" |
57 | | - if not probes_json_path.exists(): |
58 | | - pytest.skip(f"probes.json not found in {source_type} artifact directory.") |
| 51 | + def test_build_session_documents(self, source_type): |
| 52 | + """Verify that every exported JSON document can be loaded from the session DB.""" |
| 53 | + artifact_dir, session = self._open_session(source_type) |
59 | 54 |
|
60 | | - expected_probes = json.loads(probes_json_path.read_text(encoding="utf-8")) |
61 | | - actual_probes = session.getprobes() |
62 | | - |
63 | | - assert len(actual_probes) == len(expected_probes), ( |
64 | | - f"Number of actual probes ({len(actual_probes)}) does not match " |
65 | | - f"{source_type} generated artifacts ({len(expected_probes)})." |
66 | | - ) |
67 | | - |
68 | | - # Match probes by (name, reference, type) |
69 | | - if len(actual_probes) == len(expected_probes): |
70 | | - for expected in expected_probes: |
71 | | - found = False |
72 | | - for actual in actual_probes: |
73 | | - if ( |
74 | | - actual.name == expected["name"] |
75 | | - and actual.reference == expected["reference"] |
76 | | - and actual.type == expected["type"] |
77 | | - ): |
78 | | - found = True |
79 | | - assert getattr(actual, "subject_id", "") == expected.get( |
80 | | - "subject_id", "" |
81 | | - ), ( |
82 | | - f"Subject ID mismatch for probe {expected['name']} " f"in {source_type}" |
83 | | - ) |
84 | | - break |
85 | | - assert found, ( |
86 | | - f"Probe from {source_type} artifact not found in session: " |
87 | | - f"{expected['name']}" |
88 | | - ) |
89 | | - |
90 | | - # 3. Verify documents ----------------------------------------------- |
91 | 55 | json_docs_dir = artifact_dir / "jsonDocuments" |
92 | 56 | if not json_docs_dir.exists(): |
93 | 57 | pytest.skip(f"jsonDocuments directory not found in {source_type}.") |
@@ -119,3 +83,39 @@ def test_build_session_artifacts(self, source_type): |
119 | 83 | assert found, ( |
120 | 84 | f"Document from {source_type} artifact not found in session: " f"{expected_id}" |
121 | 85 | ) |
| 86 | + |
| 87 | + def test_build_session_probes(self, source_type): |
| 88 | + """Verify that probes reconstructed from the session match probes.json.""" |
| 89 | + artifact_dir, session = self._open_session(source_type) |
| 90 | + |
| 91 | + probes_json_path = artifact_dir / "probes.json" |
| 92 | + if not probes_json_path.exists(): |
| 93 | + pytest.skip(f"probes.json not found in {source_type} artifact directory.") |
| 94 | + |
| 95 | + expected_probes = json.loads(probes_json_path.read_text(encoding="utf-8")) |
| 96 | + actual_probes = session.getprobes() |
| 97 | + |
| 98 | + assert len(actual_probes) == len(expected_probes), ( |
| 99 | + f"Number of actual probes ({len(actual_probes)}) does not match " |
| 100 | + f"{source_type} generated artifacts ({len(expected_probes)})." |
| 101 | + ) |
| 102 | + |
| 103 | + for expected in expected_probes: |
| 104 | + found = False |
| 105 | + for actual in actual_probes: |
| 106 | + if ( |
| 107 | + actual.name == expected["name"] |
| 108 | + and actual.reference == expected["reference"] |
| 109 | + and actual.type == expected["type"] |
| 110 | + ): |
| 111 | + found = True |
| 112 | + assert getattr(actual, "subject_id", "") == expected.get( |
| 113 | + "subject_id", "" |
| 114 | + ), ( |
| 115 | + f"Subject ID mismatch for probe {expected['name']} " f"in {source_type}" |
| 116 | + ) |
| 117 | + break |
| 118 | + assert found, ( |
| 119 | + f"Probe from {source_type} artifact not found in session: " |
| 120 | + f"{expected['name']}" |
| 121 | + ) |
0 commit comments