예제 #1
0
def test_matchbox_falsy_used_trait(falsy_trait):
    """Check simple adding object to index if it does match characteristic's traits."""
    obj = Entity(falsy_trait)

    box = MatchBox('characteristic')
    assert box.extract_traits(obj).traits, "traits are not falsy"
    assert not box.extract_traits(obj).traits[0], "though single trait element is"
    box.add(obj)
    assert falsy_trait in box.index, "index should not be empty, with key for the falsy_trait instead."
    assert obj in box.mismatch_unknown, "due to characteristic_match, this should be filed."
    assert box, "box should not be empty"
예제 #2
0
def test_matchbox_empty_trait(empty_trait):
    """Check extracting object's traits if it is recognised as not used."""
    obj = Entity(empty_trait)

    box = MatchBox('characteristic')
    assert not box.extract_traits(obj).traits, "falsy trait"
    box.add(obj)
    assert not box.index, "index should be empty."
    assert not box.mismatch_unknown, "collection for not matching unknown should also be empty."
    assert not box, "box should be empty"
예제 #3
0
def test_multimatchbox_indexed_not_match(traits):
    """
    Check simple adding entity to index if it does not match a certain characteristic's trait.

    In this case entity gets recorded on index.
    """
    obj = Entity(traits, False)

    matchbox = MatchBox('characteristic')
    matchbox.add(obj)
    traits = matchbox.extract_traits(obj).traits  # get traits as sorting algorithms sees them
    assert set(traits) == set(matchbox.index.keys()), "characteristic trait should result in an entry in index."
    assert matchbox.mismatch_unknown == set(), "Entity should not be matching any unknown traits."

    for trait in traits:
        assert obj in matchbox.index[trait], "Entity should be in set under it's characteristic's trait key."
예제 #4
0
def test_indexed_match(traits):
    """
    Check simple adding entity to index if it does match characteristic's trait.

    In this case, entities is recorded on mismatch_unknown.
    """
    obj = Entity(traits)

    matchbox = MatchBox('characteristic')
    matchbox.add(obj)
    traits = matchbox.extract_traits(obj).traits  # get traits as sorting algorithms sees them
    assert set(traits) == set(matchbox.index.keys()), "characteristic trait should result in an entry in index."
    for trait in traits:
        assert matchbox.index[trait] == set(), "But the entry should be empty."

    assert obj in matchbox.mismatch_unknown, "entity should be not matching any future entries though."