|
27 | 27 | check_session_start_time_future_date, |
28 | 28 | check_session_start_time_old_date, |
29 | 29 | check_subject_age, |
| 30 | + check_subject_age_reference, |
30 | 31 | check_subject_exists, |
31 | 32 | check_subject_id_exists, |
32 | 33 | check_subject_id_no_slashes, |
@@ -474,6 +475,45 @@ def test_check_subject_age_with_years_fail(): |
474 | 475 | ) |
475 | 476 |
|
476 | 477 |
|
| 478 | +def test_check_subject_age_reference_default_pass(): |
| 479 | + subject = Subject(subject_id="001", age="P1D") |
| 480 | + assert check_subject_age_reference(subject) is None |
| 481 | + |
| 482 | + |
| 483 | +def test_check_subject_age_reference_birth_pass(): |
| 484 | + subject = Subject(subject_id="001", age="P1D", age__reference="birth") |
| 485 | + assert check_subject_age_reference(subject) is None |
| 486 | + |
| 487 | + |
| 488 | +def test_check_subject_age_reference_gestational_pass(): |
| 489 | + subject = Subject(subject_id="001", age="P1D", age__reference="gestational") |
| 490 | + assert check_subject_age_reference(subject) is None |
| 491 | + |
| 492 | + |
| 493 | +def test_check_subject_age_reference_none_pass(): |
| 494 | + # Files written before age__reference existed (or by other tools) may have no reference set. |
| 495 | + subject = Subject(subject_id="001", age="P1D") |
| 496 | + subject.fields["age__reference"] = None |
| 497 | + assert check_subject_age_reference(subject) is None |
| 498 | + |
| 499 | + |
| 500 | +def test_check_subject_age_reference_fail(): |
| 501 | + # PyNWB rejects invalid references at construction time, so emulate a file written by another |
| 502 | + # tool with an unsupported value by overriding the field after construction. |
| 503 | + subject = Subject(subject_id="001", age="P1D") |
| 504 | + subject.fields["age__reference"] = "conception" |
| 505 | + assert check_subject_age_reference(subject) == InspectorMessage( |
| 506 | + message=( |
| 507 | + "Subject age reference, 'conception', is not one of the valid options (['birth', 'gestational'])." |
| 508 | + ), |
| 509 | + importance=Importance.BEST_PRACTICE_SUGGESTION, |
| 510 | + check_function_name="check_subject_age_reference", |
| 511 | + object_type="Subject", |
| 512 | + object_name="subject", |
| 513 | + location="/general/subject", |
| 514 | + ) |
| 515 | + |
| 516 | + |
477 | 517 | def test_pass_check_subject_species_exists(): |
478 | 518 | subject = Subject(subject_id="001", species="Homo sapiens") |
479 | 519 | assert check_subject_species_exists(subject) is None |
|
0 commit comments