Example #1
0
    def test_match_single_handle(self):
        """
        Test that single handle can be matched
        """
        collection = EffectsCollection()
        handle = EffectHandle(trigger="on drink", effect=None, parameters=None, charges=1)

        collection.add_effect_handle(handle)

        matcher = ContainsEffectHandle(handle)

        assert_that(matcher._matches(collection), is_(equal_to(True)))
Example #2
0
    def test_match_any(self):
        """
        Test that matcher can match to any handle
        """
        collection = EffectsCollection()
        handle1 = EffectHandle(trigger="on drink", effect=None, parameters=None, charges=1)

        collection.add_effect_handle(handle1)

        matcher = ContainsEffectHandle(None)

        assert_that(matcher._matches(collection), is_(equal_to(True)))
Example #3
0
    def test_detect_sinle_mismatch(self):
        """
        Test that missing a single handle is detected correctly
        """
        collection = EffectsCollection()
        handle1 = EffectHandle(trigger="on drink", effect=None, parameters=None, charges=1)

        collection.add_effect_handle(handle1)

        handle2 = EffectHandle(trigger="on kick", effect=None, parameters=None, charges=1)

        matcher = ContainsEffectHandle(handle2)

        assert_that(matcher._matches(collection), is_(equal_to(False)))
Example #4
0
    def test_match_multiple_handles(self):
        """
        Test that matcher can match multiple handlers
        """
        collection = EffectsCollection()
        handle1 = EffectHandle(trigger="on drink", effect=None, parameters=None, charges=1)

        handle2 = EffectHandle(trigger="on kick", effect=None, parameters=None, charges=1)

        collection.add_effect_handle(handle1)
        collection.add_effect_handle(handle2)

        matcher = ContainsEffectHandle([handle1, handle2])

        assert_that(matcher._matches(collection), is_(equal_to(True)))
Example #5
0
    def test_detect_mismatch_in_collection(self):
        """
        Test that matcher can detect a mismatch in collection
        """
        collection = EffectsCollection()
        handle1 = EffectHandle(trigger="on drink", effect=None, parameters=None, charges=1)

        handle2 = EffectHandle(trigger="on kick", effect=None, parameters=None, charges=1)

        handle3 = EffectHandle(trigger="on burn", effect=None, parameters=None, charges=1)

        collection.add_effect_handle(handle1)
        collection.add_effect_handle(handle2)

        matcher = ContainsEffectHandle([handle1, handle2, handle3])

        assert_that(matcher._matches(collection), is_(equal_to(False)))
 def setup(self):
     """
     Setup test case
     """
     self.collection = EffectsCollection()
class TestEffectsCollection(object):
    """
    Class to test effects collection
    """
    def __init__(self):
        """
        Default constructor
        """
        super(TestEffectsCollection, self).__init__()
        self.collection = None

    def setup(self):
        """
        Setup test case
        """
        self.collection = EffectsCollection()

    def test_adding_effect_handle(self):
        """
        Test that effect handle can be added and retrieved
        """
        handle = EffectHandleBuilder().build()

        self.collection.add_effect_handle(handle)

        assert_that(self.collection, has_effect_handle(handle))

    def test_adding_multiple_handles(self):
        """
        Test that adding two handles don't create key collisions
        """
        handle1 = (EffectHandleBuilder()
                        .with_effect('heal')
                        .build())
        handle2 = (EffectHandleBuilder()
                        .with_effect('bless')
                        .build())

        self.collection.add_effect_handle(handle1)
        self.collection.add_effect_handle(handle2)

        assert_that(self.collection, has_effect_handles([handle1, handle2]))

    def test_returning_only_specific_handles(self):
        """
        Test that handles can be retrieved by their trigger
        """
        handle1 = (EffectHandleBuilder()
                        .with_trigger('on drink')
                        .build())
        handle2 = (EffectHandleBuilder()
                        .with_trigger('on bash')
                        .build())
        self.collection.add_effect_handle(handle1)
        self.collection.add_effect_handle(handle2)

        handles = self.collection.get_effect_handles('on bash')

        assert_that(handle2, is_in(handles))

    def test_no_matching_trigger(self):
        """
        Test that collection returns an empty list when trigger does not match
        """
        handle1 = (EffectHandleBuilder()
                        .with_trigger('on sleep')
                        .build())
        self.collection.add_effect_handle(handle1)

        handles = self.collection.get_effect_handles('on kick')

        assert_that(handles, is_(equal_to([])))

    def test_removing_handle(self):
        """
        Test that a handle can be removed
        """
        handle = EffectHandleBuilder().build()

        self.collection.add_effect_handle(handle)
        self.collection.remove_effect_handle(handle)

        assert_that(self.collection, is_not(has_effect_handle(handle)))

    def test_adding_effects(self):
        """
        Test that an effect can be added
        """
        effect = EffectBuilder().build()

        self.collection.add_effect(effect)

        assert_that(self.collection, has_effect(effect))

    def test_removing_expired_effects(self):
        """
        Test that expired effects are removed
        """
        effect = (EffectBuilder()
                    .with_duration(0)
                    .build())

        self.collection.add_effect(effect)
        self.collection.remove_expired_effects()

        assert_that(self.collection, is_not(has_effect(effect)))