Skip to content

Commit 17c1cc1

Browse files
committed
Centralize expected age references in metadata tests
1 parent 1e809fa commit 17c1cc1

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

‎dandi/tests/test_metadata.py‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@
6363

6464
METADATA_DIR = Path(__file__).with_name("data") / "metadata"
6565

66+
AGE_REFERENCE_TYPES = {
67+
"birth": AgeReferenceType.BirthReference,
68+
"gestational": AgeReferenceType.GestationalReference,
69+
None: AgeReferenceType.BirthReference,
70+
}
71+
6672
mark_xfail_ontobee = pytest.mark.xfail(
6773
condition="not config.getoption('--scheduled')",
6874
reason="Flaky ontobee site",
@@ -477,7 +483,9 @@ def test_time_extract() -> None:
477483

478484

479485
@pytest.mark.ai_generated
480-
@pytest.mark.parametrize("reference", ["birth", "gestational"])
486+
@pytest.mark.parametrize(
487+
"reference", [ref for ref in AGE_REFERENCE_TYPES.keys() if ref is not None]
488+
)
481489
def test_age_reference_roundtrip(tmp_path: Path, reference: str) -> None:
482490
path = tmp_path / "age.nwb"
483491
nwb = NWBFile("age reference", "age", datetime(2020, 1, 1, tzinfo=tzutc()))
@@ -489,16 +497,11 @@ def test_age_reference_roundtrip(tmp_path: Path, reference: str) -> None:
489497
age = extract_age(metadata)
490498
assert age is not None
491499
assert age.value == "P3W"
492-
expected = (
493-
AgeReferenceType.GestationalReference
494-
if reference == "gestational"
495-
else AgeReferenceType.BirthReference
496-
)
497-
assert age.valueReference == PropertyValue(value=expected)
500+
assert age.valueReference == PropertyValue(value=AGE_REFERENCE_TYPES[reference])
498501

499502

500503
@pytest.mark.ai_generated
501-
@pytest.mark.parametrize("reference", ["birth", None])
504+
@pytest.mark.parametrize("reference", AGE_REFERENCE_TYPES.keys())
502505
@pytest.mark.parametrize("legacy", [False, True])
503506
def test_age_reference_legacy(reference: str | None, legacy: bool) -> None:
504507
age = extract_age(
@@ -507,14 +510,12 @@ def test_age_reference_legacy(reference: str | None, legacy: bool) -> None:
507510
assert age is not None
508511
assert age.value == "P3W"
509512
assert age.valueReference == PropertyValue(
510-
value=AgeReferenceType.GestationalReference
511-
if legacy
512-
else AgeReferenceType.BirthReference
513+
value=AGE_REFERENCE_TYPES["gestational" if legacy else reference]
513514
)
514515

515516

516517
@pytest.mark.ai_generated
517-
@pytest.mark.parametrize("reference", ["birth", "gestational", None])
518+
@pytest.mark.parametrize("reference", AGE_REFERENCE_TYPES.keys())
518519
def test_age_reference_preserves_birth_dates(reference: str | None) -> None:
519520
age = extract_age(
520521
{
@@ -526,7 +527,7 @@ def test_age_reference_preserves_birth_dates(reference: str | None) -> None:
526527
)
527528
assert age is not None
528529
assert age.value == "P2D"
529-
assert age.valueReference == PropertyValue(value=AgeReferenceType.BirthReference)
530+
assert age.valueReference == PropertyValue(value=AGE_REFERENCE_TYPES["birth"])
530531

531532

532533
def test_time_extract_gest() -> None:

0 commit comments

Comments
 (0)