def test_characters_with_skip_are_excluded(): c1 = Character(type=['human']) c2 = Character(type=['human'], skip=True) charlist = list(_refine_characters([c1, c2])) assert c1 in charlist assert c2 not in charlist
def test_simple_tag(self): char1 = Character(name=["char1"], court=['winter']) char2 = Character(name=["char2"], ) char3 = Character(name=["char3"], court=['summer']) raw_res = npc.commands.find_characters(["court: *"], [char1, char2, char3]) res = list(map(lambda x: x.tags('name').first_value(), raw_res)) assert 'char1' in res assert 'char2' not in res assert 'char3' in res
def test_text_tag(self): char1 = Character(name=["char1"], description=["hello"]) char2 = Character(name=["char2"], description=["x"]) char3 = Character(name=["char3"]) raw_res = npc.commands.find_characters(["description: *"], [char1, char2, char3]) res = list(map(lambda x: x.tags('name').first_value(), raw_res)) assert 'char1' in res assert 'char2' in res assert 'char3' not 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 = Character(court=['winter']) char2 = Character() char3 = 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_rank_tag(self): char1 = Character(name=["char1"], group=['winter'], rank={'winter': ['hobnob']}) char2 = Character(name=["char2"]) char3 = Character(name=["char3"], group=['summer'], rank={'summer': ['hobnob']}) raw_res = npc.commands.find_characters(["rank: *"], [char1, char2, char3]) res = list(map(lambda x: x.tags('name').first_value(), raw_res)) assert 'char1' in res assert 'char2' not in res assert 'char3' in res
def test_tag_no_value(self, tmp_path): char = Character(type=['human']) tmp_path.joinpath('U of Bros').mkdir() result = util.create_path_from_character(char, base_path=tmp_path, hierarchy='{school}') assert result == tmp_path
def test_translated_presence_true(self, tmp_path): char = Character(type=['changeling'], motley=['Kickasso']) tmp_path.joinpath('Bros').mkdir() result = util.create_path_from_character(char, base_path=tmp_path, hierarchy='{type-unit?Bros}') assert result == tmp_path.joinpath('Bros')
def test_type_presence_true(self, tmp_path): char = Character(type=['human']) tmp_path.joinpath('Bros').mkdir() result = util.create_path_from_character(char, base_path=tmp_path, hierarchy='{type?Bros}') assert result == tmp_path.joinpath('Bros')
def test_tag_presence_false_leaves_out_path(self, tmp_path): char = Character(type=['human']) tmp_path.joinpath('Bros').mkdir() result = util.create_path_from_character(char, base_path=tmp_path, hierarchy='{school?Bros}') assert result == tmp_path
def test_tag_presence_true_appends_path(self, tmp_path): char = Character(type=['human'], school=['U of Bros']) tmp_path.joinpath('Bros').mkdir() result = util.create_path_from_character(char, base_path=tmp_path, hierarchy='{school?Bros}') assert result == tmp_path.joinpath('Bros')
def test_wanderer_note_if_wanderer(): char = Character() char.tags('type').extend(['human', 'changeling']) char.tags('foreign').touch() char.tags('wanderer').touch() output = template_output(char) assert 'human/changeling (foreign), Wanderer' in output
def test_configured_missing_value(self, tmp_path): char = Character(type=['changeling']) tmp_path.joinpath('Courtless').mkdir() result = util.create_path_from_character(char, base_path=tmp_path, hierarchy='{type-social}') assert result == tmp_path.joinpath('Courtless')
def test_full_sheet_formatting(): char = Character() char.tags('type').append('Human') char.tags('name').extend(['Bob Herbson', 'Bobbie']) char.tags('dead').append('Perished in a teleporter accident.') char.tags('title').append('The Human Guinea Pig') char.tags('location').append('Moontown') char.tags('wanderer').touch() char.tags('group').append('Testers') char.tags('group').subtag('Testers').append('Chief Marshall') char.tags('group').append('Croquet Team') char.tags('group').subtag('Croquet Team').append('Water Boy') char.tags.add_group('motley', 'Moon Morons') char.tags('motley').subtag('Moon Morons').append('Fixer') char.tags('appearance').append('Red shirt and a goofy grin.') char.tags('description').append( 'Outgoing fella with a shady hobby and no fear of death.') output = template_output(char) print(output) # Always print the real output for when things go wrong expected = """\ <h3>Bob Herbson (Deceased)</h3> <div><em>AKA Bobbie</em></div> <div>The Human Guinea Pig</div> <div>Human in Moontown, Wanderer, Testers (Chief Marshall)</div> <div>Moon Morons Motley (Fixer)</div> <div>Croquet Team (Water Boy)</div> <p><em>Appearance:</em> Red shirt and a goofy grin.</p> <p><em>Notes:</em> Outgoing fella with a shady hobby and no fear of death.</p> <p><em>Dead:</em> Perished in a teleporter accident.</p> """ assert output == expected
def test_locations_appended_to_types(): char = Character() char.tags('type').extend(['human', 'changeling']) char.tags('foreign').append('florida') char.tags('location').append('orlando') output = template_output(char) assert 'human/changeling in florida and orlando' in output
def test_literal_component(self, tmp_path): char = Character(type=['human']) tmp_path.joinpath('Dudes').mkdir() result = util.create_path_from_character(char, base_path=tmp_path, hierarchy='Dudes') assert result == tmp_path.joinpath('Dudes')
def test_type_tag_value_substitution(self, tmp_path): char = Character(type=['human']) tmp_path.joinpath('Humans').mkdir() result = util.create_path_from_character(char, base_path=tmp_path, hierarchy='{type}') assert result == tmp_path.joinpath('Humans')
def test_ranks_presence_true(self, tmp_path): char = Character(type=['human'], ranks={'some frat': ['handstand guy']}) tmp_path.joinpath('Bros').mkdir() result = util.create_path_from_character(char, base_path=tmp_path, hierarchy='{ranks?Bros}') assert result == tmp_path.joinpath('Bros')
def test_first_motley_inline_with_type(): char = Character() char.tags('type').append('human') char.tags.add_group('motley', 'weirdos') char.tags('motley').subtag('weirdos').append('token bro') output = template_output(char) assert re.search(r'human.*, weirdos Motley \(token bro\)$', output, re.MULTILINE) is not None
def test_translates_tag(prefs): sectioner = TagSectioner('type-unit', 1, prefs) character = Character(attributes={ 'type': ['changeling'], 'motley': ['fools'] }) assert sectioner.text_for(character) == 'fools'
def test_with_both_kwargs_wins(): char = Character({ "name": ["hello"], "profession": ["tailor"] }, name=["nope"]) assert char.tags("name") == ["nope"] assert char.tags("profession") == ["tailor"]
def test_first_motley_on_own_line(): char = Character() char.tags('type').append('human') char.tags.add_group('motley') char.tags('motley').append('weirdos') char.tags('motley').subtag('weirdos').append('token bro') output = template_output(char) assert '<div>weirdos Motley (token bro)</div>' in output
def test_first_group_tags_appended(self): char = Character() char.tags('type').append('human') char.tags('group').append('student council') char.tags('group').subtag('student council').append('president') char.tags('group').subtag('student council').append('member') output = template_output(char) assert re.search(r'human.*, student council \(president, member\)', output) is not None
def test_wanderer_presence_true(self, tmp_path): """The foreign? check should include wanderer tag contents""" char = Character(type=['human'], wanderer=['']) char.tags('wanderer').touch() tmp_path.joinpath('Bros').mkdir() result = util.create_path_from_character(char, base_path=tmp_path, hierarchy='{foreign?Bros}') assert result == tmp_path.joinpath('Bros')
def test_group_folders(self, tmp_path): char = Character(type=['human'], group=['First', 'Second']) first = tmp_path / 'First' first.mkdir() second = first / 'Second' second.mkdir() result = util.create_path_from_character(char, base_path=tmp_path, hierarchy='{groups}') assert result == tmp_path.joinpath('First').joinpath('Second')
def test_location_not_exist_and_foreign(self, tmp_path): # foreign is tried second char = Character(type=['human'], foreign=['way the heck over there'], location=['over here']) tmp_path.joinpath('way the heck over there').mkdir() result = util.create_path_from_character(char, base_path=tmp_path, hierarchy='{locations}') assert result == tmp_path.joinpath('way the heck over there')
def test_group_then_motley(): char = Character() char.tags('type').append('human') char.tags.add_group('motley', 'weirdos') char.tags('motley').subtag('weirdos').append('token bro') char.tags('group').append('student council') char.tags('group').subtag('student council').append('president') output = template_output(char) assert re.search( r'human.*student council \(president\), weirdos Motley \(token bro\)$', output, re.MULTILINE) is not None
def test_group_rank(self, tmp_path): char = Character(type=['human'], group=['First', 'Second']) char.tags('group').subtag('First').update(['A', 'B']) first = tmp_path / 'First' first.mkdir() first.joinpath('A').mkdir() first.joinpath('B').mkdir() result = util.create_path_from_character(char, base_path=tmp_path, hierarchy='{group}/{ranks}') assert result == tmp_path.joinpath('First').joinpath('A')
def test_remaining_groups_in_own_section(self): char = Character() char.tags('type').append('human') char.tags('group').append('student council') char.tags('group').subtag('student council').append('president') char.tags('group').subtag('student council').append('member') char.tags('group').append('volleyball') char.tags('group').subtag('volleyball').append('star') char.tags('group').append('chess club') char.tags('group').subtag('chess club').append('newbie') output = template_output(char) assert re.search(r'^volleyball \(star\), chess club \(newbie\)$', output, re.MULTILINE) is not None
def update_path(self): """Update the path label based on current values""" values = self.values.copy() tags = {} tags['type'] = values['ctype'] if values['groups']: tags['group'] = values.pop('groups') tags.update({k: v for (k, v) in values.items() if v}) temp_char = Character() temp_char.merge_all({**self.prefs.get('tag_defaults'), **tags}) template_path = self.prefs.get('types.{}.sheet_template'.format( temp_char.type_key)) char_name = values['name'] if char_name: filename = char_name + path.splitext(template_path)[1] else: filename = '' base_path = create_path_from_character(temp_char, prefs=self.prefs) final_path = path.join(base_path, filename) path_exists = path.exists(final_path) if path_exists: self.buttonBox.button( QtWidgets.QDialogButtonBox.Ok).setEnabled(False) else: self.buttonBox.button( QtWidgets.QDialogButtonBox.Ok).setEnabled(True) if path_exists and char_name: self.path_dislpay.setText("Character already exists") else: self.path_dislpay.setText(final_path)
def _minimal_character(ctype: str, groups, dead, foreign, location, prefs): """ Create a minimal character object Args: ctype (str): Character type groups (list): One or more names of groups the character belongs to. dead (bool|str): Whether to add the @dead tag. Pass False to exclude it (the default), an empty string to inlcude it with no details given, and a non-empty string to include the tag along with the contents of the argument. foreign (bool|str): Details of non-standard residence. Leave empty to exclude the @foreign tag. location (str): Details about where the character lives. Leave empty to exclude the @location tag. prefs (Settings): Settings object Returns: Character object """ temp_char = Character() tags = {} tags['description'] = prefs.get('character_header') tags['type'] = ctype.title() if groups: tags['group'] = groups if dead is not False: tags['dead'] = dead if foreign is not False: tags['foreign'] = foreign if location is not False: tags['location'] = location temp_char.merge_all({**prefs.get('tag_defaults'), **tags}) return temp_char