示例#1
0
def test_get_trait_name_aggression():
    """Check that asking for an unknown trait returns None"""

    character = Character([Aggression(1)])
    assert get_trait_name_aggression(character) == "UserString GSETUP_TURTLE"

    nonaggressive_character = Character([UnknownTrait()])
    assert get_trait_name_aggression(nonaggressive_character) == "UserString UNKNOWN_VALUE_SYMBOL"
示例#2
0
def test_make_aggression_based_function():
    """Check that the table adds the correct prefixes, suffixes, runs the postfix function,
    has the UNKNOWN value entry and is the correct length.
    """
    table = _make_aggression_based_function("prefix", lambda x: "post_proc_%s" % x)

    character = Character([Aggression(0)])
    assert table(character) == "post_proc_prefix_BEGINNER"

    character = Character([Aggression(5)])
    assert table(character) == "post_proc_prefix_MANIACAL"

    character = Character([Trait()])
    assert table(character) == "post_proc_UNKNOWN_VALUE_SYMBOL"
示例#3
0
def test_make_aggression_based_function_no_post_func():
    """Check that the table doesn't run the post function if it doesn't exist"""
    table = _make_aggression_based_function("prefix")

    character = Character([Aggression(0)])
    assert table(character) == "prefix_BEGINNER"
示例#4
0
 def test_character_must_be_composed_of_traits(self):
     with pytest.raises(TypeError,
                        match="All traits must be sub-classes of Trait"):
         not_a_trait = int(1)
         Character([LeftTrait, not_a_trait])
示例#5
0
        return 100

    def military_safety_factor(self):  # pylint: disable=no-self-use,unused-argument
        """Use for max combiner"""
        return 10


class OtherTrait(Trait):
    """A test trait"""


left_trait = LeftTrait()
right_trait = RightTrait()
other_trait = OtherTrait()

rejection_character = Character([left_trait, right_trait])
permissive_character = Character([left_trait, other_trait])


class TestCharacter:
    """Test the Character class which combines traits
    Each combiner test checks that the combiner generates the expected output.
    """
    def test_get_trait(self):
        assert rejection_character.get_trait(LeftTrait) == left_trait
        assert rejection_character.get_trait(RightTrait) == right_trait
        assert rejection_character.get_trait(OtherTrait) != left_trait
        assert rejection_character.get_trait(OtherTrait) != right_trait
        assert rejection_character.get_trait(OtherTrait) is None

    def test_all_combiner(self):
 def test_character_must_be_composed_of_traits(self):
     with pytest.raises(TypeError):
         not_a_trait = int(1)
         Character([LeftTrait, not_a_trait])