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)
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)
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'])
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))
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)
def test_reads_alphabet_default(self): r = CSVReader( str(fixtures_root / 'tests' / 'fixtures' / 'alphabet.csv')) self.assertListEqual(list(r.read()), ALPHABET_VALUE[1:])