Skip to content

Commit 68afdc5

Browse files
committed
Skip library dataset tests without hed-tests
The Windows CI checks out without submodules, so the BidsDataset tests that open the library dataset found no testconflict schema and failed. Skip them, and split the library half of the summary test into its own skippable test. The on-demand download spec test used score 1.0.0, which is bundled, so the bundle satisfied the lookup and nothing was downloaded. Use score 1.2.0, guard that it stays unbundled, and check that it is the only non-bundled file afterward.
1 parent 233c8f5 commit 68afdc5

3 files changed

Lines changed: 41 additions & 19 deletions

File tree

‎spec_tests/test_hed_cache.py‎

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,18 @@ def test_get_hed_version_path_no_auto_refresh_for_custom_directory(self):
131131
def test_get_hed_version_path_auto_refresh_downloads_missing_version(self):
132132
"""get_hed_version_path downloads only the single requested version from GitHub.
133133
134-
Uses a score version, which is not bundled with hedtools (only the standard schemas are), so
135-
the download must come from GitHub rather than the local bundle. score lives in a normal
136-
``hedxml/`` folder, so this exercises the real on-demand download path (manifest fast path and
137-
REST API fallback alike). Only the listing for the relevant library and the one XML file are
138-
fetched - not the entire catalog.
134+
Uses score 1.2.0, a released library version that hedtools does not bundle in
135+
``hed/schema/schema_data/`` (the bundle has score 1.0.0, 1.1.0, 2.0.0 and 2.1.0), so seeding the
136+
fresh cache with the bundle cannot satisfy the lookup and the file must come from GitHub. score
137+
lives in a normal ``hedxml/`` folder, so this exercises the real on-demand download path (manifest
138+
fast path and REST API fallback alike). Only the listing for the relevant library and the one XML
139+
file are fetched - not the entire catalog.
139140
"""
141+
# Guard the premise: if this version is ever bundled, the test stops exercising the download.
142+
self.assertFalse(
143+
os.path.isfile(os.path.join(hed_cache.INSTALLED_CACHE_LOCATION, "HED_score_1.2.0.xml")),
144+
"score 1.2.0 is now bundled; pick an unbundled released version for this test",
145+
)
140146
# Use a fresh cache directory so the version is definitely not present
141147
fresh_cache = os.path.join(os.path.dirname(self.hed_cache_dir), "schema_cache_auto_refresh/")
142148
if os.path.exists(fresh_cache):
@@ -145,16 +151,22 @@ def test_get_hed_version_path_auto_refresh_downloads_missing_version(self):
145151
saved = hed_cache.HED_CACHE_DIRECTORY
146152
try:
147153
hed_cache.HED_CACHE_DIRECTORY = fresh_cache
148-
# score 1.0.0 is a released library version that is NOT bundled - it must come from GitHub.
149-
result = hed_cache.get_hed_version_path("1.0.0", library_name="score")
150-
self.assertIsNotNone(result, "get_hed_version_path should download score 1.0.0 from GitHub on demand")
154+
result = hed_cache.get_hed_version_path("1.2.0", library_name="score")
155+
self.assertIsNotNone(result, "get_hed_version_path should download score 1.2.0 from GitHub on demand")
151156
self.assertTrue(os.path.exists(result))
152-
# Only the one requested file should have been downloaded (plus any bundled schemas the
157+
# Only the one requested file should have been downloaded (plus the bundled schemas the
153158
# cache seeds); no full-catalog download.
154159
xml_files = [f for f in os.listdir(fresh_cache) if hed_cache.version_pattern.match(f)]
155-
self.assertTrue(
156-
any("score" in f and "1.0.0" in f for f in xml_files),
157-
f"HED_score_1.0.0.xml must be in the cache after on-demand download; found: {xml_files}",
160+
self.assertIn(
161+
"HED_score_1.2.0.xml",
162+
xml_files,
163+
f"HED_score_1.2.0.xml must be in the cache after on-demand download; found: {xml_files}",
164+
)
165+
bundled = set(os.listdir(hed_cache.INSTALLED_CACHE_LOCATION))
166+
self.assertEqual(
167+
[f for f in xml_files if f not in bundled],
168+
["HED_score_1.2.0.xml"],
169+
"only the requested file should be downloaded; no full-catalog download",
158170
)
159171
finally:
160172
hed_cache.HED_CACHE_DIRECTORY = saved

‎tests/schema/util_test_schemas.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
TEST_SCHEMAS_DIR = os.path.realpath(
1616
os.path.join(os.path.dirname(__file__), "../../spec_tests/hed-tests/json_test_data/test_schemas/hedxml")
1717
)
18+
SKIP_REASON = "spec_tests/hed-tests is not checked out: git submodule update --init --recursive"
1819

1920

2021
def test_schemas_available() -> bool:
@@ -36,5 +37,5 @@ def load_test_schema(versions):
3637
unittest.SkipTest: When the submodule is not checked out (``git submodule update --init --recursive``).
3738
"""
3839
if not test_schemas_available():
39-
raise unittest.SkipTest("spec_tests/hed-tests is not checked out: git submodule update --init --recursive")
40+
raise unittest.SkipTest(SKIP_REASON)
4041
return load_schema_version(versions, xml_folder=TEST_SCHEMAS_DIR)

‎tests/tools/bids/test_bids_dataset.py‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
from hed.tools.bids.bids_file_group import BidsFileGroup
1212
from hed.tools.bids.bids_sidecar_file import BidsSidecarFile
1313
from hed.tools.bids.bids_tabular_file import BidsTabularFile
14-
from tests.schema.util_test_schemas import TEST_SCHEMAS_DIR, load_test_schema, test_schemas_available
14+
from tests.schema.util_test_schemas import (
15+
SKIP_REASON,
16+
TEST_SCHEMAS_DIR,
17+
load_test_schema,
18+
test_schemas_available,
19+
)
1520

1621

1722
class Test(unittest.TestCase):
@@ -32,9 +37,10 @@ def setUpClass(cls):
3237
cls.inherit_path = os.path.join(
3338
os.path.dirname(os.path.realpath(__file__)), "../../data/bids_tests/eeg_ds003645s_hed_inheritance"
3439
)
35-
# The library dataset's HEDVersion names the hed-tests library testconflict 1.1.2, which BidsDataset
36-
# resolves through the schema cache only. Point the cache at a folder seeded with that file, the
37-
# bundled standard schemas, and the real cache's score 2.0.0 when it is there (else it downloads).
40+
# The library dataset's HEDVersion names score 2.0.0 and the hed-tests library testconflict 1.1.2,
41+
# which BidsDataset resolves through the schema cache only. Point the cache at a folder seeded with
42+
# the bundled schemas (score 2.0.0 is one of them) and, when hed-tests is checked out, the
43+
# testconflict file. Tests that open the library dataset skip without hed-tests.
3844
cls.saved_cache_dir = hed_cache.HED_CACHE_DIRECTORY
3945
cls.cache_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../schema_cache_test_bids/")
4046
shutil.rmtree(cls.cache_dir, ignore_errors=True)
@@ -43,7 +49,6 @@ def setUpClass(cls):
4349
os.path.join(hed_cache.INSTALLED_CACHE_LOCATION, name)
4450
for name in os.listdir(hed_cache.INSTALLED_CACHE_LOCATION)
4551
]
46-
sources.append(os.path.join(cls.saved_cache_dir, "HED_score_2.0.0.xml"))
4752
if test_schemas_available():
4853
sources.append(os.path.join(TEST_SCHEMAS_DIR, "HED_testconflict_1.1.2.xml"))
4954
for source in sources:
@@ -247,6 +252,7 @@ def test_inheritance_no_suffixes(self):
247252
"The original top-level sidecar should not be overwritten famous_face",
248253
)
249254

255+
@unittest.skipUnless(test_schemas_available(), SKIP_REASON)
250256
def test_libraries(self):
251257
bids = BidsDataset(self.library_path, suffixes=["participants", "events"])
252258
self.assertIsInstance(
@@ -306,6 +312,9 @@ def test_get_summary(self):
306312
self.assertEqual(
307313
len(summary1["hed_schema_versions"]), 1, "BidsDataset summary hed_schema_versions entry has one schema"
308314
)
315+
316+
@unittest.skipUnless(test_schemas_available(), SKIP_REASON)
317+
def test_get_summary_libraries(self):
309318
bids2 = BidsDataset(self.library_path)
310319
summary2 = bids2.get_summary()
311320
self.assertIsInstance(summary2, dict, "BidsDataset with libraries has a summary that is a dictionary")
@@ -318,7 +327,7 @@ def test_get_summary(self):
318327
self.assertEqual(
319328
len(summary2["hed_schema_versions"]),
320329
2,
321-
"BidsDataset with libraries summary hed_schema_versions list has 3 schema",
330+
"BidsDataset with libraries summary hed_schema_versions list has 2 schemas",
322331
)
323332
self.assertTrue("dataset" in summary2)
324333

0 commit comments

Comments
 (0)