From 453ee22d6c88ff529c36dbbdd7eebc09bf265738 Mon Sep 17 00:00:00 2001 From: Nicholas Christensen Date: Thu, 7 Jan 2021 22:22:20 -0600 Subject: [PATCH] change test to ribbon example --- test/test_pytools.py | 67 ++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/test/test_pytools.py b/test/test_pytools.py index 9a0db01..8952676 100644 --- a/test/test_pytools.py +++ b/test/test_pytools.py @@ -292,70 +292,83 @@ def test_tag(): def copy(self, **kwargs): return TaggableWithCopy(kwargs["tags"]) - class UniqueTagChild(UniqueTag): + class FairRibbon(Tag): pass - class UniqueTagChildChild(UniqueTagChild): + class BlueRibbon(FairRibbon): pass - class TagChild(Tag): + class RedRibbon(FairRibbon): pass - class UniqueTagChild2(UniqueTag): + class ShowRibbon(FairRibbon, UniqueTag): pass - unique_tag_child = UniqueTagChild() - unique_tag_child_child = UniqueTagChildChild() - tag = Tag() - tag_child = TagChild() - unique_tag_child2 = UniqueTagChild2() + class BestInShowRibbon(ShowRibbon): + pass + + class ReserveBestInShowRibbon(ShowRibbon): + pass + + class BestInClassRibbon(FairRibbon, UniqueTag): + pass + + best_in_show_ribbon = BestInShowRibbon() + reserve_best_in_show_ribbon = ReserveBestInShowRibbon() + blue_ribbon = BlueRibbon() + red_ribbon = RedRibbon() + best_in_class_ribbon = BestInClassRibbon() # Test that instantiation fails if tags is not a FrozenSet of Tags with pytest.raises(AssertionError): - TaggableWithCopy(tags=[unique_tag_child, unique_tag_child_child, tag, - tag_child]) + TaggableWithCopy(tags=[best_in_show_ribbon, reserve_best_in_show_ribbon, + blue_ribbon, red_ribbon]) # Test that instantiation fails if tags is not a FrozenSet of Tags with pytest.raises(AssertionError): - TaggableWithCopy(tags=frozenset((1, unique_tag_child_child, tag, - tag_child))) + TaggableWithCopy(tags=frozenset((1, reserve_best_in_show_ribbon, blue_ribbon, + red_ribbon))) # Test that instantiation fails if there are multiple instances # of the same UniqueTag subclass with pytest.raises(NonUniqueTagError): - TaggableWithCopy(tags=frozenset((unique_tag_child, - unique_tag_child_child, tag, tag_child))) + TaggableWithCopy(tags=frozenset((best_in_show_ribbon, + reserve_best_in_show_ribbon, blue_ribbon, red_ribbon))) # Test that instantiation succeeds if there are multiple instances # Tag subclasses. - t1 = TaggableWithCopy(frozenset([unique_tag_child_child, tag, - tag_child])) - assert t1.tags == frozenset((unique_tag_child_child, tag_child, tag)) + t1 = TaggableWithCopy(frozenset([reserve_best_in_show_ribbon, blue_ribbon, + red_ribbon])) + assert t1.tags == frozenset((reserve_best_in_show_ribbon, red_ribbon, + blue_ribbon)) # Test that instantiation succeeds if there are multiple instances # of UniqueTag of different subclasses. - t1 = TaggableWithCopy(frozenset([unique_tag_child_child, unique_tag_child2, tag, - tag])) - assert t1.tags == frozenset((unique_tag_child_child, unique_tag_child2, tag)) + t1 = TaggableWithCopy(frozenset([reserve_best_in_show_ribbon, + best_in_class_ribbon, blue_ribbon, + blue_ribbon])) + assert t1.tags == frozenset((reserve_best_in_show_ribbon, best_in_class_ribbon, + blue_ribbon)) # Test tagged() function - t2 = t1.tagged(tag_child) + t2 = t1.tagged(red_ribbon) print(t2.tags) - assert t2.tags == frozenset((unique_tag_child_child, unique_tag_child2, tag, - tag_child)) + assert t2.tags == frozenset((reserve_best_in_show_ribbon, best_in_class_ribbon, + blue_ribbon, + red_ribbon)) # Test that tagged() fails if a UniqueTag of the same subclass # is alredy present with pytest.raises(NonUniqueTagError): - t1.tagged(unique_tag_child) + t1.tagged(best_in_show_ribbon) # Test without_tags() function - t4 = t2.without_tags(tag_child) + t4 = t2.without_tags(red_ribbon) assert t4.tags == t1.tags # Test that without_tags() fails if the tag is not present. with pytest.raises(ValueError): - t4.without_tags(tag_child) + t4.without_tags(red_ribbon) if __name__ == "__main__": -- GitLab