Example #1
0
def parse_based_on_filepath(filepath):
    # figure out which type of tinyworld file we've been pointed at
    file_type = get_file_type(filepath)

    if file_type not in PARSER_LOOKUP:
        fmt = 'No parser found for file type: "{}"'
        raise RuntimeError(fmt.format(file_type))

    args = PARSER_LOOKUP[file_type]
    payload, errors = parse_from_file(filepath, *args)

    return payload, errors
Example #2
0
    def test_parse_all_files(self):
        """
        parse all of the stock CircleMUD files in the CAW archive
        """
        for file_type, args in parse.PARSER_LOOKUP.items():
            filenames = self.get_all_filenames(file_type)

            for filename in filenames:
                payload, errors = parse_from_file(filename, *args)

                if os.path.split(filename)[1] == '0.obj':
                    self.assertEqual(len(errors), 1)
                    expected = '0\nbug~\na bug~\nThis object is BAD!'
                    self.assertIn(expected, errors[0]['text'])
                else:
                    self.assertListEqual(errors, [])