|
| 1 | +import pytest |
| 2 | + |
| 3 | +from cdisc_rules_engine.models.library_metadata_container import ( |
| 4 | + LibraryMetadataContainer, |
| 5 | +) |
| 6 | +from cdisc_rules_engine.operations.related_domain_is_custom import ( |
| 7 | + RelatedDomainIsCustom, |
| 8 | +) |
| 9 | + |
| 10 | + |
| 11 | +class DummyDataset: |
| 12 | + def __init__(self, name: str, is_supp: bool, rdomain: str): |
| 13 | + self.name = name |
| 14 | + self.is_supp = is_supp |
| 15 | + self.rdomain = rdomain |
| 16 | + |
| 17 | + |
| 18 | +class DummyParams: |
| 19 | + def __init__(self, datasets, domain: str): |
| 20 | + self.datasets = datasets |
| 21 | + self.domain = domain |
| 22 | + |
| 23 | + |
| 24 | +@pytest.mark.parametrize( |
| 25 | + "description, standard_domains, study_datasets, domain, expected", |
| 26 | + [ |
| 27 | + ( |
| 28 | + # Related SUPP domain is not custom when its referenced domain |
| 29 | + # exists in standard domains. |
| 30 | + "supp_related_domain_not_custom_when_rdomain_in_standard", |
| 31 | + {"AE"}, |
| 32 | + [ |
| 33 | + DummyDataset(name="SUPPAE", is_supp=True, rdomain="AE"), |
| 34 | + ], |
| 35 | + "SUPPAE", |
| 36 | + False, |
| 37 | + ), |
| 38 | + ( |
| 39 | + # Related SUPP domain is custom when its referenced domain is not |
| 40 | + # present in standard domains. |
| 41 | + "supp_related_domain_custom_when_rdomain_not_in_standard", |
| 42 | + {"AE"}, |
| 43 | + [ |
| 44 | + DummyDataset(name="SUPPXX", is_supp=True, rdomain="XX"), |
| 45 | + ], |
| 46 | + "SUPPXX", |
| 47 | + True, |
| 48 | + ), |
| 49 | + ( |
| 50 | + # If there is no matching supplementary dataset for the domain, |
| 51 | + # operation should treat it as non-custom (fallback to False). |
| 52 | + "no_matching_supp_dataset_returns_false", |
| 53 | + {"AE"}, |
| 54 | + [ |
| 55 | + DummyDataset(name="SUPPAE", is_supp=True, rdomain="AE"), |
| 56 | + ], |
| 57 | + "DM", |
| 58 | + False, |
| 59 | + ), |
| 60 | + ], |
| 61 | +) |
| 62 | +def test_related_domain_is_custom( |
| 63 | + description, standard_domains, study_datasets, domain, expected |
| 64 | +): |
| 65 | + """Verify RelatedDomainIsCustom behaviour for several scenarios. |
| 66 | +
|
| 67 | + Scenarios covered: |
| 68 | + - supplementary domain whose referenced domain is standard (not custom); |
| 69 | + - supplementary domain whose referenced domain is not standard (custom); |
| 70 | + - domain without matching supplementary dataset (falls back to False). |
| 71 | + """ |
| 72 | + |
| 73 | + library_metadata = LibraryMetadataContainer( |
| 74 | + standard_metadata={"domains": standard_domains} |
| 75 | + ) |
| 76 | + params = DummyParams(datasets=study_datasets, domain=domain) |
| 77 | + |
| 78 | + op = RelatedDomainIsCustom( |
| 79 | + params=params, |
| 80 | + library_metadata=library_metadata, |
| 81 | + original_dataset=None, |
| 82 | + cache_service=None, |
| 83 | + data_service=None, |
| 84 | + ) |
| 85 | + |
| 86 | + assert op._execute_operation() is expected |
0 commit comments