示例#1
0
 def test_basically_works(self):
     r = CSVReader(str(fixtures_root / 'tests' / 'fixtures' /
                       'alphabet.csv'),
                   skip_first_line=False)
     source = self._source(r)
     source.reload()
     self.assertListEqual(list(source.keys()), ['a', 'e', 'i'])
     self.assertEqual(source['a'], StringyRow('a', 'b', 'c', 'd'))
     self.assertIn('a', source)
示例#2
0
    def test_dislikes_duplicate_keys(self):
        ds = self._datastore()
        ds.add_sources_with_glob(
            str(fixtures_root / 'tests' / 'fixtures' / '*.csv'),
            lambda path: CSVReader(path))

        def _add_duplicates():
            ds.add_source(FakeReader([['a', 'b', 'c', 'd'], ['e', 'f', 'g', 'h']]))

        self.assertRaises(ValueError, _add_duplicates)
示例#3
0
 def test_multiple_sources(self):
     ds = self._datastore()
     ds.add_sources_with_glob(
         str(fixtures_root / 'tests' / 'fixtures' / '*.csv'),
         lambda path: CSVReader(path))
     self.assertListEqual(list(ds.keys()), ['e', 'i', '5', '9'])
     self.assertEqual(ds['e'], ds.row_class('e', 'f', 'g', 'h'))
     self.assertEqual(ds.e, ds.row_class('e', 'f', 'g', 'h'))
     self.assertEqual(ds['5'], ds.row_class('5', '6', '7', '8'))
     self.assertEqual(ds.r_5, ds.row_class('5', '6', '7', '8'))
     self.assertRaises(KeyError, lambda: ds['x'])
示例#4
0
def reload():
    terrain_types.unload()
    entity_names.unload()
    verbs.unload()
    room_types.unload()
    monster_types.unload()
    item_types.unload()
    key_bindings.unload()

    terrain_types.add_source(CSVReader(str(GAME_ROOT / 'data' /
                                           'terrain.csv')))
    entity_names.add_source(CSVReader(str(GAME_ROOT / 'data' / 'names.csv')))
    verbs.add_source(CSVReader(str(GAME_ROOT / 'data' / 'verbs.csv')))
    room_types.add_source(CSVReader(str(GAME_ROOT / 'data' / 'rooms.csv')))
    monster_types.add_source(
        CSVReader(str(GAME_ROOT / 'data' / 'monsters.csv')))
    item_types.add_source(ItemTypeReader(str(GAME_ROOT / 'data' /
                                             'items.csv')))
    key_bindings.add_source(
        KeyBindingsReader(str(GAME_ROOT / 'data' / 'key_bindings.csv'),
                          skip_first_line=False))
示例#5
0
 def test_reads_alphabet_noskip(self):
     r = CSVReader(str(fixtures_root / 'tests' / 'fixtures' /
                       'alphabet.csv'),
                   skip_first_line=False)
     self.assertListEqual(list(r.read()), ALPHABET_VALUE)
示例#6
0
 def test_reads_alphabet_default(self):
     r = CSVReader(
         str(fixtures_root / 'tests' / 'fixtures' / 'alphabet.csv'))
     self.assertListEqual(list(r.read()), ALPHABET_VALUE[1:])