Exemple #1
0
def testAddingTaxaExceptionsExisting(patch_write, patch_retr):
    def retrDynamicReturn(a, b):
        if b == REALNAMES:
            return {"felis catus": 1, "panthera tigris": 2}
        elif b == EXCEPTIONS:
            return {
                "panthera tigris": {
                    "consumer": "family",
                    "resource": "genus"
                }
            }
        return {}

    patch_retr.side_effect = retrDynamicReturn
    species = "felis catus"
    consumer = "family"
    resource = "genus"
    instance = Web(path="dir")
    instance.add_taxonomic_exception(species, consumer, resource, True)
    patch_write.assert_called_with(
        "dir",
        "reorderedTaxaInteractions",
        {
            "panthera tigris": {
                "consumer": "family",
                "resource": "genus"
            },
            "felis catus": {
                "consumer": "family",
                "resource": "genus"
            },
        },
    )
Exemple #2
0
def testReplicatingWebBlank(patch_retr):
    def retrDynamicReturn(a, b):
        if b == REALNAMES:
            return {}
        elif b == EXCEPTIONS:
            return {}
        elif b == WEB:
            return {IDTRACKER: 0}
        elif b == TAXA:
            return {}
        elif b == LINKS:
            return {}
        elif b == DATASETS:
            return {}
        return {}

    patch_retr.side_effect = retrDynamicReturn
    instance = Web(path="dir")
    newWeb = instance.replicateWeb()

    assert newWeb.datasetMetas == retrDynamicReturn(1, DATASETS)
    assert newWeb.linkMetas == retrDynamicReturn(1, LINKS)
    assert newWeb.interactions == retrDynamicReturn(1, WEB)
    assert newWeb.stringNames == retrDynamicReturn(1, REALNAMES)
    assert newWeb.taxa == retrDynamicReturn(1, TAXA)
Exemple #3
0
def testReplicatingWebExpected(patch_retr):
    def retrDynamicReturn(a, b):
        if b == REALNAMES:
            return {"felis catus": 1, "panthera tigris": 2, "vulpes vulpes": 3}
        elif b == EXCEPTIONS:
            return {}
        elif b == WEB:
            return {IDTRACKER: 5, 2: {1: [1, 3], 3: [2]}, 3: {1: [4]}}
        elif b == TAXA:
            return {
                1: {
                    "family": "felidae"
                },
                2: {
                    "family": "felidae"
                },
                3: {
                    "family": "canidea"
                },
            }
        elif b == LINKS:
            return {1: {"dId": 2}, 2: {"dId": 1}, 3: {"dId": 1}, 4: {"dId": 2}}
        elif b == DATASETS:
            return {1: {}, 2: {}}
        return {}

    patch_retr.side_effect = retrDynamicReturn
    instance = Web(path="dir")
    newWeb = instance.replicateWeb()

    assert newWeb.datasetMetas == retrDynamicReturn(1, DATASETS)
    assert newWeb.linkMetas == retrDynamicReturn(1, LINKS)
    assert newWeb.interactions == retrDynamicReturn(1, WEB)
    assert newWeb.stringNames == retrDynamicReturn(1, REALNAMES)
    assert newWeb.taxa == retrDynamicReturn(1, TAXA)
Exemple #4
0
def testFilteringByDatasetIdsEmpty(patch_retr):
    def retrDynamicReturn(a, b):
        if b == REALNAMES:
            return {"felis catus": 1, "panthera tigris": 2, "vulpes vulpes": 3}
        elif b == EXCEPTIONS:
            return {}
        elif b == WEB:
            return {IDTRACKER: 5, 2: {1: [1, 3], 3: [2]}, 3: {1: [4]}}
        elif b == TAXA:
            return {
                1: {
                    "family": "felidae"
                },
                2: {
                    "family": "felidae"
                },
                3: {
                    "family": "canidea"
                },
            }
        elif b == LINKS:
            return {1: {"dId": 2}, 2: {"dId": 1}, 3: {"dId": 1}, 4: {"dId": 2}}
        elif b == DATASETS:
            return {1: {}, 2: {}}
        return {}

    patch_retr.side_effect = retrDynamicReturn
    instance = Web(path="dir")
    newWeb = instance.filter_by_dataset_id([])

    assert newWeb.datasetMetas == {}
    assert newWeb.linkMetas == {}
    assert newWeb.interactions == {IDTRACKER: 5}
    assert newWeb.stringNames == {}
    assert newWeb.taxa == {}
Exemple #5
0
def testFilteringOnTaxa(patch_retr):
    def retrDynamicReturn(a, b):
        if b == REALNAMES:
            return {"felis catus": 1, "panthera tigris": 2, "vulpes vulpes": 3}
        elif b == EXCEPTIONS:
            return {}
        elif b == WEB:
            return {IDTRACKER: 5, 2: {1: [1, 3], 3: [2]}, 3: {1: [4]}}
        elif b == TAXA:
            return {
                1: {
                    "family": "felidae"
                },
                2: {
                    "family": "felidae"
                },
                3: {
                    "family": "canidea"
                },
            }
        elif b == LINKS:
            return {
                1: {
                    "dId": 2,
                    "evidencedBy": "observation"
                },
                2: {
                    "dId": 1,
                    "evidencedBy": "observation"
                },
                3: {
                    "dId": 1
                },
                4: {
                    "dId": 2,
                    "evidencedBy": "inferred"
                },
            }
        elif b == DATASETS:
            return {1: {}, 2: {}}
        return {}

    patch_retr.side_effect = retrDynamicReturn
    instance = Web(path="dir")
    newWeb = instance.filterByTaxa([("felidae", "family")])
    assert newWeb.datasetMetas == {1: {}, 2: {}}
    assert newWeb.linkMetas == {
        1: {
            "dId": 2,
            "evidencedBy": "observation"
        },
        3: {
            "dId": 1
        },
    }
    assert newWeb.interactions == {2: {1: [1, 3]}}
    assert newWeb.stringNames == {"felis catus": 1, "panthera tigris": 2}
    assert newWeb.taxa == {1: {"family": "felidae"}, 2: {"family": "felidae"}}
Exemple #6
0
def testAddingTaxaExceptionsInvalid(patch_write, patch_retr):
    def retrDynamicReturn(a, b):
        if b == REALNAMES:
            return {"felis catus": 1, "panthera tigris": 2}
        elif b == EXCEPTIONS:
            return {}
        return {}

    patch_retr.side_effect = retrDynamicReturn
    species = "felis"
    consumer = "family"
    resource = "genus"
    instance = Web(path="dir")
    with pytest.raises(ValueError):
        instance.add_taxonomic_exception(species, consumer, resource, True)