|
| 1 | +"""Tests for the ``mints`` declaration on ``ResourceConfig``. |
| 2 | +
|
| 3 | +A resource description states which identifier namespaces it is the minting |
| 4 | +authority for. The authority relation (``identifier_authority`` in |
| 5 | +omnipath-build) is populated from this declaration, not inferred from what a |
| 6 | +resource's schema happens to tag data as — a resource can carry cross- |
| 7 | +references to a namespace without minting it. |
| 8 | +""" |
| 9 | + |
| 10 | +from __future__ import annotations |
| 11 | + |
| 12 | +from pypath.inputs_v2.base import ResourceConfig |
| 13 | +from pypath.internals.cv_terms import ( |
| 14 | + IdentifierNamespaceCv, |
| 15 | + LicenseCV, |
| 16 | + ResourceCv, |
| 17 | + UpdateCategoryCV, |
| 18 | +) |
| 19 | + |
| 20 | + |
| 21 | +def _config(**overrides) -> ResourceConfig: |
| 22 | + defaults = dict( |
| 23 | + id=ResourceCv.CHEBI, |
| 24 | + name='Test Resource', |
| 25 | + url='https://example.org', |
| 26 | + license=LicenseCV.CC_BY_4_0, |
| 27 | + update_category=UpdateCategoryCV.REGULAR, |
| 28 | + description='A resource used only to exercise the mints field.', |
| 29 | + ) |
| 30 | + defaults.update(overrides) |
| 31 | + return ResourceConfig(**defaults) |
| 32 | + |
| 33 | + |
| 34 | +def test_mints_defaults_to_empty(): |
| 35 | + """A resource that declares nothing mints nothing — a pure consumer.""" |
| 36 | + config = _config() |
| 37 | + assert config.mints == () |
| 38 | + |
| 39 | + |
| 40 | +def test_mints_declares_the_namespaces_a_resource_is_authoritative_for(): |
| 41 | + config = _config(mints=(IdentifierNamespaceCv.CHEBI,)) |
| 42 | + assert config.mints == (IdentifierNamespaceCv.CHEBI,) |
| 43 | + |
| 44 | + |
| 45 | +def test_mints_holds_more_than_one_namespace(): |
| 46 | + config = _config( |
| 47 | + mints=( |
| 48 | + IdentifierNamespaceCv.KEGG_COMPOUND, |
| 49 | + IdentifierNamespaceCv.KEGG_REACTION, |
| 50 | + ), |
| 51 | + ) |
| 52 | + assert IdentifierNamespaceCv.KEGG_COMPOUND in config.mints |
| 53 | + assert IdentifierNamespaceCv.KEGG_REACTION in config.mints |
| 54 | + |
| 55 | + |
| 56 | +def test_mints_does_not_claim_a_namespace_a_resource_only_cites(): |
| 57 | + """The regression this field exists to catch: KEGG cites PubChem |
| 58 | +
|
| 59 | + identifiers it does not mint. Declaring ``mints`` explicitly is what lets |
| 60 | + the build tell "this resource is the authority" apart from "this resource |
| 61 | + also carries a cross-reference". |
| 62 | + """ |
| 63 | + kegg = _config( |
| 64 | + id=ResourceCv.KEGG_METABOLIC, |
| 65 | + mints=(IdentifierNamespaceCv.KEGG_COMPOUND,), |
| 66 | + ) |
| 67 | + assert IdentifierNamespaceCv.PUBCHEM_COMPOUND not in kegg.mints |
0 commit comments