def test_mismatch(): """Check if mismatch returns those element that are not described by characteristic.""" box = MatchBox('argument') element1 = 'element' element2 = 'element2' totally_other = 'other' box.index['other'].add(totally_other) box.mismatch_unknown.add(element1) box.index['test'].add(element2) assert box.mismatch('test') == {element1, element2}, "both elements should be returned."
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"
def test_match(): """Check if match cuts objects properly.""" box = MatchBox('argument') element1 = 'element' element2 = 'element2' totally_other = 'other' box.index['other'].add(totally_other) box.exclude_unknown.add(element1) box.index['test'].add(element2) assert box.match({element1, element2, totally_other}, 'test') == {totally_other}, "only one element should match"
def test_not_matching(): """Check if not_matching returns those element that are not described by characteristic.""" box = MatchBox("argument") element1 = "element" element2 = "element2" totally_other = "other" box.index["other"].add(totally_other) box.exclude_unknown.add(element1) box.index["test"].add(element2) assert box.not_matching("test") == {element1, element2}, "both elements should be returned."
def test_match(): """Check if match cuts objects properly.""" box = MatchBox("argument") element1 = "element" element2 = "element2" totally_other = "other" box.index["other"].add(totally_other) box.exclude_unknown.add(element1) box.index["test"].add(element2) assert box.match({element1, element2, totally_other}, "test") == {totally_other}, "only one element should match"
def test_matchbox_remove_completely(): """Check removing entities from matchbox.""" # Given set of entities, all with matching trait, and one mismatching within index entity1 = Entity('entity1') entity2 = Entity('entity2') entity3 = Entity('entity3') entity4 = Entity('entity4', False) matchbox = MatchBox('characteristic') matchbox.add(entity1) matchbox.add(entity2) matchbox.add(entity3) matchbox.add(entity4) assert matchbox assert matchbox.mismatch_unknown assert matchbox.index # When removing them from a box matchbox.remove(entity1) matchbox.remove(entity2) matchbox.remove(entity3) matchbox.remove(entity4) # Then box should be empty assert not matchbox assert not matchbox.mismatch_unknown assert not matchbox.index
def test_match(): """Check if match cuts entites properly.""" box = MatchBox('argument') element1 = 'element' element2 = 'element2' totally_other = 'other' box.index['other'].add(totally_other) box.mismatch_unknown.add(element1) box.index['test'].add(element2) all_elements = {element1, element2, totally_other} assert box.match(all_elements, 'test') == {totally_other}, "only one element should match"
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"
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."
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."
def test_multimatchbox_indexed_not_match(characteristic_values): """ Check simple adding object to index if it does not match a certain characteristic's value. In this case object gets recorded on index. """ ob = IndexedObject(characteristic_values, False) matchbox = MatchBox("characteristic") matchbox.add(ob) values = matchbox.extract_characteristic_value(ob).values # get the values as sorting algorithms sees them assert set(values) == set(matchbox.index.keys()), "characteristic value should result in an entry in index." assert matchbox.exclude_unknown == set(), "object should not be matching any unknown values." for characteristic in values: assert ob in matchbox.index[characteristic], "Object should be in set under it's characteristic's value key."
def test_indexed_match(characteristic_values): """ Check simple adding object to index if it does match characteristic's value. In this case, objects is recorded on exclude_unknown. """ ob = IndexedObject(characteristic_values) matchbox = MatchBox("characteristic") matchbox.add(ob) values = matchbox.extract_characteristic_value(ob).values # get the values as sorting algorithms sees them assert set(values) == set(matchbox.index.keys()), "characteristic value should result in an entry in index." for characteristic in values: assert matchbox.index[characteristic] == set(), "But the entry should be empty." assert ob in matchbox.exclude_unknown, "object should be not matching any future entries though."
def test_matchbox_remove_one(): """Check removing entity from matchbox.""" # Given set of entities, all with matching trait, and one mismatching within index entity1 = Entity('entity1') entity2 = Entity('entity2') entity3 = Entity('entity3') entity4 = Entity('entity4', False) matchbox = MatchBox('characteristic') matchbox.add(entity1) matchbox.add(entity2) matchbox.add(entity3) matchbox.add(entity4) assert matchbox assert matchbox.mismatch_unknown assert matchbox.index assert entity1 in matchbox.mismatch_unknown assert entity1 not in matchbox.index['entity1'] assert entity1 in matchbox.index['entity2'] assert entity1 in matchbox.index['entity2'] assert entity1 in matchbox.index['entity2'] # When removing one entity from a box matchbox.remove(entity1) # it's no longer present assert entity1 not in matchbox.mismatch_unknown assert entity1 not in matchbox.index['entity1'] assert entity1 not in matchbox.index['entity2'] assert entity1 not in matchbox.index['entity2'] assert entity1 not in matchbox.index['entity2'] # but the matchbox is filled assert matchbox assert matchbox.mismatch_unknown assert matchbox.index