Skip to content

Commit d6d6405

Browse files
authored
Merge pull request #1450 from VisLab/remove_testlib
Drop the test dependencies on testlib
2 parents b6bf984 + 68afdc5 commit d6d6405

55 files changed

Lines changed: 489 additions & 390 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.rules/testing.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ tests/
3636
- `spec_tests/hed-examples/` - Example BIDS datasets
3737
- `spec_tests/hed-schemas/` - Official schema repository
3838
- Initialize: `git submodule update --init --recursive`
39+
- Unit tests that need a library schema use the hed-tests test schemas (testconflict, testclash, testminimal, testaux) from `spec_tests/hed-tests/json_test_data/test_schemas/hedxml/` through `tests/schema/util_test_schemas.py` (`load_test_schema`), never the deprecated testlib library; those tests skip when the submodule is not checked out. A test that needs a released library with a version history uses score.
3940

4041
## Running Tests
4142

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Purpose: core Python library for HED (Hierarchical Event Descriptors) validation
77
Test framework: unittest. Never convert the suite to pytest style as a side effect of other work, and never mix the two.
88

99
- Install dev env: `pip install -e ".[dev,test,docs,examples]"` (uv works: `uv venv .venv` then `uv pip install ...`)
10-
- Fetch test data: `git submodule update --init --recursive`
10+
- Fetch test data: `git submodule update --init --recursive` (the spec tests need it; the unit tests that load a library schema read the hed-tests test schemas from it and skip without it)
1111
- Run tests: `python -m unittest discover tests -v`
1212
- Spec tests (need submodules): `python -m unittest discover spec_tests -v`
1313
- Single test: `python -m unittest tests.models.test_hed_string.TestHedString.test_constructor`

‎hed/schema/hed_schema_io.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ def get_hed_xml_version(xml_file_path) -> str:
322322
def parse_version_list(xml_version_list) -> dict:
323323
"""Takes a list of xml versions and returns a dictionary split by prefix
324324
325-
e.g. ["score", "testlib"] will return {"": "score, testlib"}
326-
e.g. ["score", "testlib", "ol:otherlib"] will return {"": "score, testlib", "ol:": "otherlib"}
325+
e.g. ["score", "lang"] will return {"": "score, lang"}
326+
e.g. ["score", "lang", "ol:otherlib"] will return {"": "score, lang", "ol:": "otherlib"}
327327
328328
Parameters:
329329
xml_version_list (list): List of str specifying which HED schemas to use

‎hed/schema/schema_io/wiki2schema.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def parse_star_string(s):
164164
s = s.lstrip("* ").strip() # remove leading '* ' and any surrounding whitespace
165165
result = {}
166166

167-
# Check for a leading schema-attribute block in {}, e.g. {inLibrary=testlib}
167+
# Check for a leading schema-attribute block in {}, e.g. {inLibrary=score}
168168
if s.startswith("{"):
169169
end_brace = s.find("}")
170170
if end_brace >= 0:

‎hed/schema/schema_validation/attribute_validators.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def unit_class_requires_numeric_check(hed_schema, tag_entry, attribute_name) ->
156156
that carries a unit class MUST have `valueClass=numericClass`. Standard schemas before 8.5.0 (and
157157
libraries partnered with them) are not checked: 8.3.0 and earlier have `Sampling-rate/#` with a unit
158158
class and no value class. An unpartnered library has no standard version and is not checked either
159-
(testlib 1.0.2 and the testunpart fixture carry the same historical omission).
159+
(the testunpart fixture carries the same historical omission).
160160
161161
Parameters:
162162
hed_schema (HedSchema): The schema to use for validation.

‎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 testlib version, which is not bundled with hedtools, so the download must come from
135-
GitHub rather than the local bundle. testlib lives in a normal ``hedxml/`` folder, so this
136-
exercises the real on-demand download path (manifest fast path and REST API fallback alike)
137-
without relying on deprecated versions. Only the listing for the relevant library and the
138-
one XML file are 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-
# testlib 2.0.0 is a released library version that is NOT bundled - it must come from GitHub.
149-
result = hed_cache.get_hed_version_path("2.0.0", library_name="testlib")
150-
self.assertIsNotNone(result, "get_hed_version_path should download testlib 2.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("testlib" in f and "2.0.0" in f for f in xml_files),
157-
f"HED_testlib_2.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/data/bids_tests/eeg_ds003645s_hed_library/dataset_description.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Name": "Face processing MEEG dataset with HED annotation",
33
"BIDSVersion": "1.10.0",
4-
"HEDVersion": ["score_2.0.0", "test:testlib_1.0.2"],
4+
"HEDVersion": ["score_2.0.0", "test:testconflict_1.1.2"],
55
"License": "CC0",
66
"Authors": [
77
"Daniel G. Wakeman",

‎tests/data/bids_tests/eeg_ds003645s_hed_library/task-FacePerception_events.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"double_press": "Experiment participant presses both keys ."
2323
},
2424
"HED": {
25-
"show_face": "Sensory-event, test:Experimental-stimulus, (Def/Face-image, Onset), (Def/Blink-inhibition-task,Onset),(Def/Cross-only, Offset)",
25+
"show_face": "Sensory-event, test:Object-one, (Def/Face-image, Onset), (Def/Blink-inhibition-task,Onset),(Def/Cross-only, Offset)",
2626
"show_face_initial": "Sensory-event, Experimental-stimulus, (Def/Face-image, Onset), (Def/Blink-inhibition-task,Onset), (Def/Fixation-task, Onset)",
2727
"show_circle": "Sensory-event, (Intended-effect, Cue), (Def/Circle-only, Onset), (Def/Face-image, Offset), (Def/Blink-inhibition-task, Offset), (Def/Fixation-task, Offset)",
2828
"show_cross": "Sensory-event, (Intended-effect, Cue), (Def/Cross-only, Onset), (Def/Fixation-task, Onset), (Def/Circle-only, Offset), Hyperventilation-refused-procedure/Could not comply",
@@ -68,12 +68,12 @@
6868
},
6969
"stim_file": {
7070
"Description": "Path of the stimulus file in the stimuli directory.",
71-
"HED": "(Image, Pathname/#), test:Image"
71+
"HED": "(Image, Pathname/#), test:Object-two"
7272
},
7373
"hed_def_sensory": {
7474
"Description": "Metadata dictionary for gathering sensory definitions",
7575
"HED": {
76-
"cross_only_def": "(Definition/Cross-only, (Visual-presentation, (Foreground-view, (White, Cross), (Center-of, Computer-screen)), Sleep-architecture, (Background-view, Black), test:Cue, Description/A white fixation cross on a black background in the center of the screen.))",
76+
"cross_only_def": "(Definition/Cross-only, (Visual-presentation, (Foreground-view, (White, Cross), (Center-of, Computer-screen)), Sleep-architecture, (Background-view, Black), test:Object-three, Description/A white fixation cross on a black background in the center of the screen.))",
7777
"face_image_def": "(Definition/Face-image, (Visual-presentation, (Foreground-view, ((Image, Face, Hair), Color/Grayscale), ((White, Cross), (Center-of, Computer-screen))), (Background-view, Black), Description/A happy or neutral face in frontal or three-quarters frontal pose with long hair cropped presented as an achromatic foreground image on a black background with a white fixation cross superposed.))",
7878
"circle_only_def": "(Definition/Circle-only, (Visual-presentation, (Foreground-view, ((White, Circle), (Center-of, Computer-screen))), (Background-view, Black), Description/A white circle on a black background in the center of the screen.))"
7979
}

tests/data/schema_tests/HED_testlib_2.1.0.xml renamed to tests/data/schema_tests/HED_testlocal_2.1.0.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" ?>
2-
<HED version="2.1.0" library="testlib" withStandard="8.4.0" unmerged="True">
3-
<prologue>Conflicts: testlib_2.0.0 Violin-subsound1 and Violin-subsound2 and Violin-subsound3 have different parents. testlib_2.0.0 piano-subsound2 does not take value; testlib_2.2.0 Piano-subsound2 takes a value with a unit class.</prologue>
2+
<HED version="2.1.0" library="testlocal" withStandard="8.4.0" unmerged="True">
3+
<prologue>Conflicts: testlocal_2.0.0 Violin-subsound1 and Violin-subsound2 and Violin-subsound3 have different parents. testlocal_2.0.0 piano-subsound2 does not take value; testlocal_2.2.0 Piano-subsound2 takes a value with a unit class.</prologue>
44
<schema>
55
<node>
66
<name>BA-nonextension</name>

‎tests/data/schema_tests/merge_group_tests/HED_testconflict_2.0.0.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" ?>
22
<HED version="2.0.0" library="testconflict" withStandard="8.5.0" unmerged="True">
3-
<prologue>testconflict 2.0.0 partners with standard schema 8.5.0. Changes from 1.1.2: deletes Legacy-tag (major bump: tag deleted) and adds the Rooted-tag subtree rooted under the standard Event tag. Partnering an unpartnered library is itself a major change (testlib precedent).</prologue>
3+
<prologue>testconflict 2.0.0 partners with standard schema 8.5.0. Changes from 1.1.2: deletes Legacy-tag (major bump: tag deleted) and adds the Rooted-tag subtree rooted under the standard Event tag. Partnering an unpartnered library is itself a major change (precedent of an earlier library).</prologue>
44
<schema>
55
<node>
66
<name>Object-tag</name>

0 commit comments

Comments
 (0)