def test_locations_substrate(self): """Обрабатываются локации Substrate""" with pathlib.Path('./testdata/ldf/test_location_substrate.ldf' ).absolute().open() as stream: ldf = stream.read() builder = processing.LocationsBuilder(ldf_base=ldf) result = builder.make_text() self.assertEqual(result, ldf)
def test_locations_database(self): """Создаётся база локаций""" with pathlib.Path('./testdata/ldf/test_locations.ldf').absolute().open( ) as stream: ldf = stream.read() builder = processing.LocationsBuilder(ldf_base=ldf) result = builder.make_text() self.assertEqual(result, ldf)
def test_add_incorrect(self): """Выбрасывается исключение на добавление локации недопустимого типа""" builder = processing.LocationsBuilder() def add_location(): """Добавить локацию""" builder.add('wrong_type', 0, 0, 0) self.assertRaises(Exception, add_location)
def test_add_correct(self): """Добавляются корректные локации""" builder = processing.LocationsBuilder() try: for name in processing.LOCATION_TYPES: builder.add(name, 0, 0, 0) except Exception as exception: # pylint: disable=W0703 self.fail(exception) count = 0 for name in builder.locations: count += len(builder.locations[name]) self.assertEqual(count, len(processing.LOCATION_TYPES))
def update_ldb(self, tvd: model.Tvd): """Обновление базы локаций до актуального состояния""" logging.debug('Generating Locations Data Base (LDB)...') with self.config.mgen.ldf_templates[self.name].open() as stream: ldf = stream.read() builder = processing.LocationsBuilder(ldf_base=ldf) builder.apply_tvd_setup(tvd) ldf_text = builder.make_text() with pathlib.Path(self.config.mgen.ldf_files[self.name]).open( mode='w') as stream: stream.write(ldf_text) logging.debug('... LDB done')