def test_add_model_creates_package_for_model(self): pyde.install_dir = build_path('testing', 'test_environments', 'add_tests', 'add_model_test') pyde.meta = python_dev.get_module_metadata(pyde.install_dir) if path_exists(pyde.install_dir, 'add_model', 'model'): shutil.rmtree(build_path(pyde.install_dir, 'add_model', 'model')) add.model._model('MODEL') self.assertTrue( path_exists(pyde.install_dir, 'add_model', 'model', 'model.py'), 'package for model not created')
def test_add_model_creates_model_package_if_it_doesnt_exist(self): pyde.install_dir = build_path('testing', 'test_environments', 'add_tests', 'add_model_test') pyde.meta = python_dev.get_module_metadata(pyde.install_dir) if path_exists(pyde.install_dir, 'add_model', 'model'): shutil.rmtree(build_path(pyde.install_dir, 'add_model', 'model')) add.model._model('MODEL') self.assertTrue( path_exists(pyde.install_dir, 'add_model', 'model'), 'model package is not created') self.assertTrue( path_exists(pyde.install_dir, 'add_model', 'model', '__init__.py'), '__init__.py not created in model package')
def test_load_location_returns_dict_from_yaml_file(self): data = python_dev.load_location(utils.build_path('testing', 'test_environments', 'load_location', 'test_load.yaml')) expected = { 'name': 'NAME', 'description': 'DESCRIPTION' } self.assertEqual(expected, data, 'Loaded dict not returned by load_location')
def test_add_model_adds_model_to_model_barrel(self): pyde.install_dir = build_path('testing', 'test_environments', 'add_tests', 'add_model_test') pyde.meta = python_dev.get_module_metadata(pyde.install_dir) if path_exists(pyde.install_dir, 'add_model', 'model'): shutil.rmtree(build_path(pyde.install_dir, 'add_model', 'model')) add.model._model('MODEL') assert_in_file( build_path(pyde.install_dir, 'add_model', 'model', '__init__.py'), 'from json_model import register_models', 'register_models not imported into barrel') assert_in_file( build_path(pyde.install_dir, 'add_model', 'model', '__init__.py'), 'from .model import Model', 'Model not added to model barrel') assert_in_file( build_path(pyde.install_dir, 'add_model', 'model', '__init__.py'), 'register_models(__name__)', 'register_models not called in barrel')
def test_add_config_meta(self): meta = Meta() cfg = configuration.read_config(utils.build_path('testing', 'test_environments', 'configuration', 'with_meta_data.ini')) python_dev._add_config_meta(meta, cfg) self.assertTrue(hasattr(meta, 'custom')) self.assertEqual('NAME', meta.custom.name) self.assertEqual('DESCRIPTION', meta.custom.description) self.assertTrue(hasattr(meta, 'custom2')) self.assertEqual('NAME_2', meta.custom2.name2) self.assertEqual('DESCRIPTION_2', meta.custom2.description2)
def test_load_location_returns_dict_from_ini_file(self): data = python_dev.load_location(utils.build_path('testing', 'test_environments', 'load_location', 'test_load.ini')) expected = { 'DEFAULT': { }, 'group 1': { 'name': 'NAME', 'description': 'DESCRIPTION' }, 'group 2': { 'foo': 'bar' } } self.assertEqual(expected, data, 'Loaded config not returned by load_location')
def _add_model_to_barrel(model_dir, schema): model_init = utils.build_path(model_dir, '__init__.py') with open(model_init, 'r') as fp: init = fp.readlines() found = False model_import = 'from .{module} import {cls}'.format( module=schema.module_name(), cls=schema.class_name()) with open(model_init, 'w') as fp: for line in init: if line.startswith('register_models(') and not found: fp.write(model_import+os.linesep) fp.write(line) found = True continue if line.strip() == model_import: fp.write(line) found = True continue fp.write(line) if not found: fp.write(model_import+os.linesep)
def test_config_to_obj(self): cfg = configuration.read_config(utils.build_path('testing', 'test_environments', 'configuration', 'test_1.ini')) cfg_obj = configuration.config_to_obj(cfg) self.assertEqual('VALUE', cfg_obj.pyde.name) self.assertEqual('META_VALUE', cfg_obj.Meta.meta_name)
def test_load_open_api(self): api = python_dev.load_open_api(utils.build_path('testing', 'test_environments', 'load_api', 'petstore.yaml')) # print(json.dumps(api.to_dict(), indent=4)) api = python_dev.load_open_api(utils.build_path('testing', 'test_environments', 'load_api', 'petstore.yaml'))