def test_simple_tag(self): char1 = npc.Character(name=["char1"], court=['winter']) char2 = npc.Character(name=["char2"], ) char3 = npc.Character(name=["char3"], court=['summer']) raw_res = npc.commands.find_characters(["court: *"], [char1, char2, char3]) res = list(map(lambda x: x.get_first('name'), raw_res)) assert 'char1' in res assert 'char2' not in res assert 'char3' in res
def test_text_tag(self): char1 = npc.Character(name=["char1"], description="hello") char2 = npc.Character(name=["char2"], description="") char3 = npc.Character(name=["char3"]) raw_res = npc.commands.find_characters(["description: *"], [char1, char2, char3]) res = list(map(lambda x: x.get_first('name'), raw_res)) assert 'char1' in res assert 'char2' not in res assert 'char3' not in res
def test_rank_tag(self): char1 = npc.Character(name=["char1"], group=['winter'], rank={'winter': ['hobnob']}) char2 = npc.Character(name=["char2"]) char3 = npc.Character(name=["char3"], group=['summer'], rank={'summer': ['hobnob']}) raw_res = npc.commands.find_characters(["rank: *"], [char1, char2, char3]) res = list(map(lambda x: x.get_first('name'), raw_res)) assert 'char1' in res assert 'char2' not in res assert 'char3' in res
def test_negation(): """ Negation should exclude characters that contain the text in their tag values, returning characters that either have a different value or who do not have the tag at all. """ char1 = npc.Character(court=['winter']) char2 = npc.Character() char3 = npc.Character(court=['summer']) res = npc.commands.find_characters(["court~:winter"], [char1, char2, char3]) assert char1 not in res assert char2 in res assert char3 in res
def test_many_names(self): names = ['Hugh Mann', 'Mr. Big', 'Huggy Bug'] char = npc.Character(name=names) header = char.build_header() assert "@name {}".format(names[0]) not in header for name in names[1:]: assert "@name {}".format(name) in header
def test_data_flag(flag): char = npc.Character() char.append(flag, None) assert re.search(r'@{}$'.format(flag), char.build_header(), re.MULTILINE) char.append(flag, 'datas') assert re.search(r'@{} datas$'.format(flag), char.build_header(), re.MULTILINE)
def test_groups_and_ranks(self, tmpdir): char = npc.Character(type=['human'], group=['First', 'Second'], rank={'First': ['A', 'B']}) tmpdir.mkdir('First') tmpdir.mkdir('First/Second') tmpdir.mkdir('First/A') result = util.create_path_from_character(char, base_path=str(tmpdir), hierarchy='{groups+ranks}') assert result == str(tmpdir.join('First').join('A'))
def test_translates_tag(prefs): sectioner = TagSectioner('type-unit', 1, prefs) character = npc.Character(attributes={ 'type': ['changeling'], 'motley': ['fools'] }) assert sectioner.text_for(character) == 'fools'
def test_tag_for_all(tag): char = npc.Character() bits = ['some', 'words', 'and', 'stuff'] for bit in bits: char.append(tag, bit) header = char.build_header() for bit in bits: assert '@{} {}'.format(tag, bit) in header
def test_merge_all(): char = npc.Character() char.append('name', 'Mr. Titleson') char.append('title', 'The Wise') more_tags = {'title': 'The Stern', 'location': 'Nothingtown'} char.merge_all(more_tags) assert char['title'] == ['The Wise', 'The Stern']
def test_both(self): char = npc.Character({ "name": ["hello"], "profession": ["tailor"] }, name=["nope"]) assert char["name"] == ["nope"] assert char["profession"] == ["tailor"]
def test_tag_present_and_filled(self): char = npc.Character(head=['attached'], limbs=[' \n'], torso=[]) char.problems = [] char.validate_tag_present_and_filled('head') assert len(char.problems) == 0 char.validate_tag_present_and_filled('limbs') assert 'Empty limbs' in char.problems char.validate_tag_present_and_filled('torso') assert 'Missing torso' in char.problems
def test_rank(): char = npc.Character() char.append('group', 'Townies') ranks = ['Foozer', 'Roz', 'Bazanger'] for rank in ranks: char.append_rank('Townies', rank) header = char.build_header() for rank in ranks: assert '@rank {}'.format(rank) in header
def test_no_path(): prefs = npc.settings.Settings() character = npc.Character({ "type": ['changeling'], "kith": ['nope'], "seeming": ['nope'] }) problems = npc.linters.changeling.lint(character, sk_data=prefs.get('changeling')) assert problems
def test_required_tag_not_present(self, tag): char = npc.Character(**{tag: []}) char.validate() assert 'Missing {}'.format(tag) in char.problems
def test_no_kith(self): char = npc.Character(type=['Changeling'], seeming=['Beast']) header = char.build_header() assert "@type Changeling" in header assert "@seeming Beast" in header
def test_bare_flag(flag): char = npc.Character() char.append(flag, None) header = char.build_header() assert re.search(r'@{}$'.format(flag), header, re.MULTILINE)
def test_unknown_tags(self): """Unrecognized tags should be errors with strict validation""" char = npc.Character(head=['attached', 'bald']) char.validate(strict=True) assert 'Unrecognized tags: head' in char.problems
def test_no_seeming(self): char = npc.Character(type=['Changeling'], kith=['Swimmerskin']) header = char.build_header() assert "@type Changeling" in header assert "@kith Swimmerskin" in header
def test_single_tags(key, values): char = npc.Character(type=['werewolf'], **{key: values}) char.validate() assert 'Multiple {key}s: {vals}'.format( key=key, vals=", ".join(values)) in char.problems
def test_required_tag_whitespace(self, tag): char = npc.Character(**{tag: [' \t']}) char.validate() assert 'Empty {}'.format(tag) in char.problems
def test_initial_state(self): """Character should be invalid before first call to validate()""" char = npc.Character(type=['human'], description='hi there', name=['dude']) assert not char.valid char.validate() assert char.valid
def test_with_errors(self): char = npc.Character() char.validate() assert not char.valid
def test_tag_appears_once(self): char = npc.Character(head=['left', 'right', 'beeblebrox']) char.validate_tag_appears_once('head') assert 'Multiple heads: left, right, beeblebrox' in char.problems
def test_single_type(self): char = npc.Character(type=['dog']) char.validate(strict=True) assert "Multiple types" not in char.problems
def test_filled_description(self): char = npc.Character(description='Hi there!') char.validate() assert 'Missing description' not in char.problems
def test_not_in_path(self): char = npc.Character(name=['Hugh Mann'], path='local/storage/fake.nwod') header = char.build_header() assert "@realname Hugh Mann" in header
def test_seeming_and_kith(self): char = npc.Character(type=['Changeling'], seeming=['Beast'], kith=['Swimmerskin']) header = char.build_header() assert "@changeling Beast Swimmerskin" in header
def test_description(): desc = 'Fee fie fo fum! I smell the blood of an Englishman!' char = npc.Character(description=desc) assert desc in char.build_header()
def test_multiple_types(self): char = npc.Character(type=['dog', 'cat']) char.validate(strict=True) assert "Multiple types: dog, cat" in char.problems