File: character_strings_test.py

package info (click to toggle)
freeorion 0.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 194,940 kB
  • sloc: cpp: 186,508; python: 40,969; ansic: 1,164; xml: 719; makefile: 32; sh: 7
file content (43 lines) | stat: -rw-r--r-- 1,489 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from character.character_module import Aggression, Character, Trait
from character.character_strings_module import (
    _make_aggression_based_function,
    get_trait_name_aggression,
)


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"


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"


class UnknownTrait(Trait):
    pass


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"