Esempio n. 1
0
 def test_conflict_dir(self):
     """Ignore a directory when it is in both the search and ignore lists"""
     parseables = fixture_dir('parsing', 'characters')
     ignore_me = fixture_dir('parsing', 'characters')
     characters = npc.parser.get_characters(search_paths=[parseables],
                                            ignore_paths=[ignore_me])
     assert not len(list(characters))
Esempio n. 2
0
 def test_ignore_dir(self):
     parseables = fixture_dir('parsing', 'characters')
     ignore_me = fixture_dir('parsing', 'characters', 'Fetches')
     characters = npc.parser.get_characters(search_paths=[parseables],
                                            ignore_paths=[ignore_me])
     for c in characters:
         assert c.tags('type')[0] != 'Fetch'
Esempio n. 3
0
 def test_ignore_file(self):
     parseables = fixture_dir('parsing', 'characters')
     ignore_me = fixture_dir('parsing', 'characters', 'Changelings',
                             'Kabana Matansa.nwod')
     characters = npc.parser.get_characters(search_paths=[parseables],
                                            ignore_paths=[ignore_me])
     for c in characters:
         assert 'Kabana Matansa' not in c.tags['name']
Esempio n. 4
0
 def test_conflict_file(self, ):
     """Always parse a file when it is in the search and ignore lists"""
     parseables = fixture_dir('parsing', 'characters', 'Changelings',
                              'Kabana Matansa.nwod')
     ignore_me = fixture_dir('parsing', 'characters', 'Changelings',
                             'Kabana Matansa.nwod')
     characters = npc.parser.get_characters(search_paths=[parseables],
                                            ignore_paths=[ignore_me])
     assert len(list(characters)) == 1
Esempio n. 5
0
    def test_extra_md_metadata(self, prefs, metaformat, tmpdir):
        """All metadata formats for the markdown type should show the extra
        metadata for the markdown type from the imported settings."""

        outfile = tmpdir.join("output.md")
        prefs.load_more(fixture_dir(['listing', 'settings-metadata.json']))
        search = fixture_dir(['listing', 'valid-json'])
        npc.commands.listing(search, fmt='markdown', metadata=metaformat, outfile=str(outfile), prefs=prefs)
        assert 'test-type: markdown' in outfile.read().lower()
Esempio n. 6
0
def test_extra_md_metadata(prefs, metaformat, tmp_path):
    """All metadata formats for the markdown type should show the extra
    metadata for the markdown type from the imported settings."""

    outfile = tmp_path / 'output.md'
    prefs.load_more(fixture_dir('listing', 'settings-metadata.json'))
    search = fixture_dir('listing', 'valid-json')
    result = npc.commands.listing.make_list(search, fmt='markdown', metadata=metaformat, outfile=str(outfile), prefs=prefs)
    assert result.errmsg == ''
    assert result.success == True
    assert 'test-type: markdown' in outfile.read_text().lower()
Esempio n. 7
0
 def test_valid_formats(self, format_name):
     listing = Listing(metadata_format=format_name, metadata=self.metadata)
     assert listing.result
     with open(
             fixture_dir('listing', 'html', 'metadata',
                         "metadata-{}.txt".format(format_name)), 'r') as f:
         assert f.read() in listing.output
Esempio n. 8
0
def test_md_mmd_metadata(tmp_path, metaformat):
    """The 'mmd' and 'multimarkdown' metadata args should prepend multi-markdown
    metadata tags to the markdown output."""

    outfile = tmp_path / 'output.md'
    search = fixture_dir('listing', 'valid-json')
    npc.commands.listing.make_list(search, fmt='markdown', metadata=metaformat, outfile=str(outfile))
    assert 'Title: NPC Listing' in outfile.read_text()
Esempio n. 9
0
 def make_list(*search_parts, outformat='json', metadata=None, prefs=prefs, title=None):
     tmpdir = tmp_path / 'list'
     tmpdir.mkdir()
     outfile = tmpdir / 'output.json'
     outfile.touch()
     search = fixture_dir('listing', *search_parts)
     npc.commands.listing.make_list(search, fmt=outformat, metadata=metadata, outfile=str(outfile), prefs=prefs, title=title)
     return load_json(outfile)
Esempio n. 10
0
def test_default_table_format():
    data_out = io.StringIO()
    tables = {'type': Counter(['human', 'human', 'elf'])}
    assert npc.formatters.markdown.report(tables, data_out)

    with open(fixture_dir('formatters', 'markdown',
                          'report.txt')) as table_fixture:
        assert data_out.getvalue() == table_fixture.read()
Esempio n. 11
0
    def test_md_mmd_metadata(self, tmpdir):
        """The 'mmd' metadata arg should prepend multi-markdown metadata tags to
        the markdown output."""

        outfile = tmpdir.join("output.md")
        search = fixture_dir(['listing', 'valid-json'])
        npc.commands.listing(search, fmt='markdown', metadata='mmd', outfile=str(outfile))
        assert 'Title: NPC Listing' in outfile.read()
Esempio n. 12
0
 def test_extra_json_metadata(self, list_json_output, prefs):
     """The extra json metdata should be included for the json output type."""
     prefs.load_more(fixture_dir(['listing', 'settings-metadata.json']))
     listing = list_json_output(['valid-json'], metadata='json', prefs=prefs)
     for c in listing:
         if 'meta' in c:
             assert c['test'] == 'yes'
             assert c['test-type'] == 'json'
Esempio n. 13
0
def test_progress_callback(tmpdir, capsys):
    """The progress callback should be called for every character"""

    outfile = tmpdir.join("output.md")
    search = fixture_dir('listing', 'valid-json')
    npc.commands.listing.make_list(search, fmt='markdown', outfile=str(outfile), progress=lambda i, t: print("{} of {}".format(i, t), file=sys.stderr))
    _, errtext = capsys.readouterr()
    assert "0 of 3\n1 of 3\n2 of 3\n3 of 3\n" == errtext
Esempio n. 14
0
def test_default_table_format():
    data_out = io.BytesIO()
    tables = {'type': Counter(['human', 'human', 'elf'])}
    assert npc.formatters.html.report(tables, data_out)

    with open(fixture_dir('formatters', 'html',
                          'report.txt')) as table_fixture:
        assert data_out.getvalue().decode() == table_fixture.read()
Esempio n. 15
0
def lint_changeling(filename, **kwargs):
    prefs = npc.settings.Settings()
    char_file = fixture_dir('linter', 'changeling', filename)
    character = npc.parser.parse_character(char_file)
    problems = npc.linters.changeling.lint(character,
                                           sk_data=prefs.get('changeling'),
                                           **kwargs)
    return '/'.join(problems)
Esempio n. 16
0
def test_extra_json_metadata(list_json_output, prefs):
    """The extra json metdata should be included for the json output type."""
    prefs.load_more(fixture_dir('listing', 'settings-metadata.json'))
    listing = list_json_output('valid-json', metadata='json', prefs=prefs)
    for c in listing:
        if 'meta' in c:
            assert c['test'] == 'yes'
            assert c['test-type'] == 'json'
Esempio n. 17
0
 def make_report(tags, *search_parts, outformat='json', prefs=prefs):
     outfile = tmp_path / 'output.json'
     search = fixture_dir('report', *search_parts)
     npc.commands.report(tags,
                         search=[search],
                         fmt=outformat,
                         outfile=str(outfile),
                         prefs=prefs)
     return load_json(outfile)
Esempio n. 18
0
    def populate_from_fixture_dir(self, fixture_path):
        """Copy the files and folders from a fixture directory into the campaign
        root.

        The path given should be relative to the npc/tests/fixtures directory in
        this package. It will be run through `fixture_dir` first.
        """
        srcpath = fixture_dir(fixture_path)
        dir_util.copy_tree(srcpath, str(self.basedir))
Esempio n. 19
0
    def test_invalid_metadata_arg(self):
        """Using metadata formats other than yfm and mmd is not supported for
        the markdown output type.

        The json output type ignores the format argument entirely, which is not
        tested.
        """
        search = fixture_dir(['listing', 'valid-json'])
        result = npc.commands.listing(search, fmt='md', metadata='json')
        assert not result.success
Esempio n. 20
0
def test_invalid_metadata_arg():
    """Using metadata formats other than yfm and mmd is not supported for
    the markdown output type.

    The json output type ignores the format argument entirely, which is not
    tested.
    """
    search = fixture_dir('listing', 'valid-json')
    result = npc.commands.listing.make_list(search, fmt='md', metadata='json')
    assert not result.success
Esempio n. 21
0
def test_md_yfm_metadata(metaformat, tmp_path):
    """The 'yfm' and 'yaml' metadata args should both result in YAML front
    matter being prepended to markdown output."""

    outfile = tmp_path / 'output.md'
    search = fixture_dir('listing', 'valid-json')
    npc.commands.listing.make_list(search, fmt='markdown', metadata=metaformat, outfile=str(outfile))
    match = re.match(r'(?sm)\s*---(.*)---\s*', outfile.read_text())
    assert match is not None
    assert 'title: NPC Listing' in match.group(1)
Esempio n. 22
0
    def test_md_yfm_metadata(self, metaformat, tmpdir):
        """The 'yfm' and 'yaml' metadata args should both result in YAML front
        matter being prepended to markdown output."""

        outfile = tmpdir.join("output.md")
        search = fixture_dir(['listing', 'valid-json'])
        npc.commands.listing(search, fmt='markdown', metadata=metaformat, outfile=str(outfile))
        match = re.match('(?sm)\s*---(.*)---\s*', outfile.read())
        assert match is not None
        assert 'title: NPC Listing' in match.group(1)
Esempio n. 23
0
def test_sort(list_json_output):
    """Tests that the dumped, sorted output identical to the internal sorted data"""
    raw_data = npc.parser.get_characters(search_paths=[fixture_dir(['dump'])])
    sorted_data = npc.commands._sort_chars(raw_data)
    dump_data = list_json_output(sort=True)
    it = iter(sorted_data)
    with pytest.raises(StopIteration) as e:
        i = next(it)
        for x in dump_data:
            if x == i:
                i = next(it)
Esempio n. 24
0
    def populate_from_fixture_dir(self, *fixture_path):
        """
        Copy the files and folders from a fixture directory into the campaign
        root.

        Args:
            *fixture_path (str): Path elements to combine. All should be under
                the npc/tests/fixtures directory in this package. It will be run
                through `util.fixture_dir` first.
        """
        srcpath = fixture_dir(*fixture_path)
        dir_util.copy_tree(srcpath, str(self.basedir))
Esempio n. 25
0
 def make_character(filename):
     parseables = fixture_dir(['parsing', 'tags', filename])
     characters = list(npc.parser.get_characters(search_paths=[parseables]))
     return characters[0]
Esempio n. 26
0
def test_missing_vice():
    char_file = fixture_dir('linter', 'nwod', 'Gotta Nada.nwod')
    with open(char_file, 'r') as char_file:
        problems = npc.linters.nwod.lint_vice_virtue(char_file.read())
        assert 'Missing vice' in problems
Esempio n. 27
0
 def test_ignore_dir(self):
     parseables = fixture_dir(['parsing', 'characters'])
     ignore_me = fixture_dir(['parsing', 'characters', 'Fetches'])
     characters = npc.parser.get_characters(search_paths=[parseables], ignore_paths=[ignore_me])
     for c in characters:
         assert c.get_first('type') != 'Fetch'
Esempio n. 28
0
 def make_list(*search_parts, outformat='json', metadata=None, prefs=prefs, title=None):
     tmpdir = tmpdir_factory.mktemp('list')
     outfile = tmpdir.join("output.json")
     search = fixture_dir('listing', *search_parts)
     npc.commands.listing.make_list(search, fmt=outformat, metadata=metadata, outfile=str(outfile), prefs=prefs, title=title)
     return json.load(outfile)
Esempio n. 29
0
def test_output_to_file(argparser, tmpdir):
    outfile = tmpdir.join("output.json")
    search = fixture_dir(['dump'])
    npc.commands.dump(search, outfile=str(outfile))
    assert outfile.read()
Esempio n. 30
0
 def make_list(search_parts, outformat='json', metadata=None, prefs=prefs, title=None):
     outfile = tmpdir.join("output.json")
     search = fixture_dir(['listing'] + search_parts)
     npc.commands.listing(search, fmt=outformat, metadata=metadata, outfile=str(outfile), prefs=prefs, title=title)
     return json.load(outfile)
Esempio n. 31
0
 def test_ignore_file(self):
     parseables = fixture_dir(['parsing', 'characters'])
     ignore_me = fixture_dir(['parsing', 'characters', 'Changelings', 'Kabana Matansa.nwod'])
     characters = npc.parser.get_characters(search_paths=[parseables], ignore_paths=[ignore_me])
     for c in characters:
         assert 'Kabana Matansa' not in c['name']
Esempio n. 32
0
def test_output_no_file(capsys, outopt):
    search = fixture_dir(['listing', 'valid-json'])
    npc.commands.listing(search, outfile=outopt)
    output, _ = capsys.readouterr()
    assert output
Esempio n. 33
0
 def test_conflict_file(self, ):
     """Always parse a file when it is in the search and ignore lists"""
     parseables = fixture_dir(['parsing', 'characters', 'Changelings', 'Kabana Matansa.nwod'])
     ignore_me = fixture_dir(['parsing', 'characters', 'Changelings', 'Kabana Matansa.nwod'])
     characters = npc.parser.get_characters(search_paths=[parseables], ignore_paths=[ignore_me])
     assert len(list(characters)) == 1
Esempio n. 34
0
def test_remove_filename_comments():
    parseables = fixture_dir(['parsing', 'characters', 'Fetches'])
    characters = list(npc.parser.get_characters(search_paths=[parseables]))
    assert characters[0]['name'][0] == 'macho mannersson'
Esempio n. 35
0
 def do_lint(charname, strict=False):
     search = fixture_dir(['linter', 'characters', 'Humans', charname])
     npc.commands.lint(search, strict=strict)
     output, _ = capsys.readouterr()
     return output
Esempio n. 36
0
 def test_allow_apostrophes_in_names(self):
     parseables = fixture_dir('parsing', 'characters', 'Fetches',
                              "manny o'mann - super faker.nwod")
     characters = list(npc.parser.get_characters(search_paths=[parseables]))
     assert characters[0].tags('name')[0] == "manny o'mann"
Esempio n. 37
0
 def test_allow_commas_in_names(self):
     parseables = fixture_dir('parsing', 'characters', 'Fetches',
                              "Manners Mann, Ph.D. - fakierest.nwod")
     characters = list(npc.parser.get_characters(search_paths=[parseables]))
     assert characters[0].tags('name')[0] == "Manners Mann, Ph.D."
Esempio n. 38
0
 def test_allow_hyphens_in_names(self):
     parseables = fixture_dir('parsing', 'characters', 'Fetches',
                              "Manny Manly-Mann - fakiest.nwod")
     characters = list(npc.parser.get_characters(search_paths=[parseables]))
     assert characters[0].tags('name')[0] == "Manny Manly-Mann"
Esempio n. 39
0
def test_output_to_file(tmpdir):
    outfile = tmpdir.join("output.json")
    search = fixture_dir(['listing', 'valid-json'])
    npc.commands.listing(search, outfile=str(outfile))
    assert outfile.read()
Esempio n. 40
0
def test_remove_filename_comments():
    parseables = fixture_dir('parsing', 'characters', 'Fetches',
                             'macho mannersson - faker.nwod')
    characters = list(npc.parser.get_characters(search_paths=[parseables]))
    assert characters[0].tags('name')[0] == 'macho mannersson'
Esempio n. 41
0
 def make_character(filename):
     parseables = fixture_dir('parsing', 'tags', filename)
     characters = list(
         npc.parser.get_characters(search_paths=[parseables]))
     return characters[0]
Esempio n. 42
0
 def test_ignore_comments(self):
     filepath = fixture_dir('util', 'load_json', 'commented.json')
     loaded = util.load_json(filepath)
     assert "freedom" in loaded["data"]
Esempio n. 43
0
 def test_conflict_dir(self):
     """Ignore a directory when it is in both the search and ignore lists"""
     parseables = fixture_dir(['parsing', 'characters'])
     ignore_me = fixture_dir(['parsing', 'characters'])
     characters = npc.parser.get_characters(search_paths=[parseables], ignore_paths=[ignore_me])
     assert not len(list(characters))
Esempio n. 44
0
 def test_ignore_trailing_commas(self):
     filepath = fixture_dir('util', 'load_json', 'trailing_commas.json')
     loaded = util.load_json(filepath)
     assert "freedom" in loaded["data"]
     assert ", }" in loaded['list']
Esempio n. 45
0
def test_dump_matches_internal(list_json_output):
    dump_data = list_json_output()
    raw_data = npc.parser.get_characters(search_paths=[fixture_dir(['dump'])])
    assert dump_data == list(raw_data)
Esempio n. 46
0
 def test_bad_syntax(self):
     filepath = fixture_dir('util', 'load_json', 'bad_syntax.json')
     with pytest.raises(json.decoder.JSONDecodeError) as err:
         loaded = util.load_json(filepath)
     assert "Bad syntax" in err.value.nicemsg
Esempio n. 47
0
def test_output_no_file(capsys, outopt):
    search = fixture_dir(['dump'])
    npc.commands.dump(search, outfile=outopt)
    output, _ = capsys.readouterr()
    assert output
Esempio n. 48
0
def test_open_files(prefs):
    override_path = fixture_dir('util', 'open_files', 'settings-echo.json')
    prefs.load_more(override_path)
    result = util.open_files('not a real path', 'seriously, no', prefs=prefs)
    assert 'not a real path' in result.args
    assert 'seriously, no' in result.args
Esempio n. 49
0
    def make_list(search_parts=[], metadata=False, sort=False):
        outfile = tmpdir.join("output.json")
        search = fixture_dir(['dump'] + search_parts)

        npc.commands.dump(search, outfile=str(outfile), metadata=metadata, sort=sort)
        return json.load(outfile)
Esempio n. 50
0
def test_output_no_file(capsys, outopt):
    search = fixture_dir(['report', 'valid-json'])
    npc.commands.report('type', search=[search], outfile=outopt)
    output, _ = capsys.readouterr()
    assert output
Esempio n. 51
0
def test_has_virtue():
    char_file = fixture_dir('linter', 'nwod', 'Has Virtue.nwod')
    with open(char_file, 'r') as char_file:
        problems = npc.linters.nwod.lint_vice_virtue(char_file.read())
        assert 'Missing virtue' not in problems
Esempio n. 52
0
 def test_unknown_metadata_arg(self):
     """Unrecognized metadata options should result in an error"""
     search = fixture_dir(['listing', 'valid-json'])
     result = npc.commands.listing(search, fmt='md', metadata='asdf')
     assert not result.success
Esempio n. 53
0
 def test_hides_footer(self, prefs):
     prefs.load_more(
         fixture_dir('listing', 'html', 'footer', 'settings.json'))
     listing = Listing(partial=True, prefs=prefs)
     assert listing.result
     assert "I'm footer content! Woohoo!" not in listing.output
Esempio n. 54
0
 def make_report(tags, search_parts, outformat='json', prefs=prefs):
     outfile = tmpdir.join("output.json")
     search = fixture_dir(['report'] + search_parts)
     npc.commands.report(tags, search=[search], fmt=outformat, outfile=str(outfile), prefs=prefs)
     return json.load(outfile)