Ejemplo n.º 1
0
def test_integration():
    key = "Fully specified name:en"
    concepts = [
        OrderedDict([(key, "a"), ("Answers", ""), ("Members", "b")]),
        OrderedDict([(key, "b"), ("Answers", "c"), ("Members", "")]),
        OrderedDict([(key, "c"), ("Answers", ""), ("Members", "")]),
        OrderedDict([(key, "d"), ("Answers", ""), ("Members", "")]),
    ]
    concepts = get_all_concepts_in_tree(concepts, "a")
    detect_cycles(concepts)
    concepts = move_referring_concepts_down(concepts, "Fully specified name:en")
    excludes = ["b"]
    concepts = exclude(concepts, excludes)
    assert [c[key] for c in concepts] == ["c", "a"]
def test_detect_cycles():
    key = "Fully specified name:en"
    concepts = [
        OrderedDict([(key, "a"), ("Answers", ""), ("Members", "b;c")]),
        OrderedDict([(key, "b"), ("Answers", ""), ("Members", "")]),
        OrderedDict([(key, "c"), ("Answers", "d;e"), ("Members", "")]),
        OrderedDict([(key, "d"), ("Answers", "e;f"), ("Members", "")]),
        OrderedDict([(key, "e"), ("Answers", ""), ("Members", "")]),
        OrderedDict([(key, "f"), ("Answers", "c;e"), ("Members", "")]),
    ]
    try:
        detect_cycles(concepts)
        assert False, "detect_cycles should have detected the cycle c-d-f-c"
    except Exception as e:
        assert "c --> d --> f --> c" in str(e)
        assert str(e).count("\n\t") == 1  # only should print one cycle