def test_complex_lookup_config_is_supplied___correct_instance_is_created_with_correct_config_path(self, supplier, model, version, complex_lookup_data): with TemporaryDirectory() as d: keys_path = os.path.join(d, 'keys') os.mkdir(keys_path) version_path = os.path.join(d, 'version.csv') self.write_version_file(supplier, model, version, version_path) module_path = os.path.join(d, '{}_lookup.py'.format(model)) self.write_py_module(model, module_path) complex_lookup_config_path = os.path.join(d, 'lookup_config.json'.format(model)) self.write_complex_config_file(complex_lookup_data, complex_lookup_config_path) output_directory = os.path.join(d, 'output') os.mkdir(output_directory) _, instance = olf.create( model_keys_data_path=keys_path, model_version_file_path=version_path, lookup_module_path=module_path, complex_lookup_config_fp=complex_lookup_config_path, output_directory=output_directory ) self.assertEqual(type(instance).__name__, '{}KeysLookup'.format(model)) self.assertEqual(instance.supplier, supplier) self.assertEqual(instance.model_name, model) self.assertEqual(instance.model_version, version) self.assertEqual(instance.keys_data_directory, keys_path) self.assertEqual(instance.complex_lookup_config_fp, complex_lookup_config_path) self.assertEqual(instance.output_directory, output_directory)
def test_model_version_file_path_not_supplied___correct_exception_raised( self, model): with TemporaryDirectory() as d: module_path = os.path.join(d, '{}_lookup.py'.format(model)) self.write_py_module(model, module_path) with self.assertRaisesRegexp( OasisException, r"Unable to get model version data without model_version_file_path" ): _, instance = olf.create(lookup_package_path=module_path)
def test_lookup_package_path_not_supplied___correct_exception_raised( self, supplier, model, version): with TemporaryDirectory() as d: version_path = os.path.join(d, 'version.csv') self.write_version_file(supplier, model, version, version_path) with self.assertRaisesRegexp( OasisException, r"Unable to import lookup package without lookup_package_path" ): _, instance = olf.create(model_version_file_path=version_path)
def test_version_file_missing___correct_exception_raised(self, model): with TemporaryDirectory() as d: version_path = os.path.join(d, 'version.csv') module_path = os.path.join(d, '{}_lookup.py'.format(model)) self.write_py_module(model, module_path) with self.assertRaisesRegexp( OasisException, r"model_version_file_path does not exist.*"): _, instance = olf.create(model_version_file_path=version_path)
def test_lookup_package_path_missing___correct_exception_raised( self, supplier, model, version): with TemporaryDirectory() as d: version_path = os.path.join(d, 'version.csv') self.write_version_file(supplier, model, version, version_path) module_path = os.path.join(d, '{}_lookup.py'.format(model)) with self.assertRaisesRegex( OasisException, r"lookup_package_path does not exist.*"): _, instance = olf.create(model_version_file_path=version_path, lookup_package_path=module_path)
def test_model_version_file_path_not_supplied___correct_exception_raised(self, model): with TemporaryDirectory() as d: keys_path = os.path.join(d, 'keys') os.mkdir(keys_path) module_path = os.path.join(d, '{}_lookup.py'.format(model)) self.write_py_module(model, module_path) with self.assertRaisesRegex(OasisException, r"The path None \(model_version_file_path\) is indicated as preexisting" r" but is not a valid path"): _, instance = olf.create( model_keys_data_path=keys_path, lookup_module_path=module_path )
def test_model_keys_data_path_missing___correct_exception_raised(self, supplier, model, version): with TemporaryDirectory() as d: keys_path = os.path.join(d, 'keys') version_path = os.path.join(d, 'version.csv') self.write_version_file(supplier, model, version, version_path) module_path = os.path.join(d, '{}_lookup.py'.format(model)) self.write_py_module(model, module_path) with self.assertRaisesRegex(OasisException, r"The path .*/keys \(model_keys_data_path\) is indicated as preexisting" r" but does not exist"): _, instance = olf.create( model_version_file_path=version_path, lookup_module_path=module_path, model_keys_data_path=keys_path )
def test_keys_path_not_supplied___correct_instance_is_created_with_correct_model_info_and_keys_path(self, supplier, model, version): with TemporaryDirectory() as d: version_path = os.path.join(d, 'version.csv') self.write_version_file(supplier, model, version, version_path) module_path = os.path.join(d, '{}_lookup.py'.format(model)) self.write_py_module(model, module_path) _, instance = olf.create( model_version_file_path=version_path, lookup_module_path=module_path ) self.assertEqual(type(instance).__name__, '{}KeysLookup'.format(model)) self.assertEqual(instance.supplier, supplier) self.assertEqual(instance.model_name, model) self.assertEqual(instance.model_version, version) self.assertEqual(instance.keys_data_directory, os.path.join(os.sep, 'var', 'oasis', 'keys_data')) self.assertEqual(instance.complex_lookup_config_fp, None)
def test_keys_path_is_supplied___correct_instance_is_created_with_correct_model_info_and_keys_path(self, supplier, model, version): with TemporaryDirectory() as d: keys_path = os.path.join(d, 'keys') os.mkdir(keys_path) version_path = os.path.join(d, 'version.csv') self.write_version_file(supplier, model, version, version_path) module_path = os.path.join(d, '{}_lookup.py'.format(model)) self.write_py_module(model, module_path) _, instance = olf.create( model_keys_data_path=keys_path, model_version_file_path=version_path, lookup_package_path=module_path, ) self.assertEqual(type(instance).__name__, '{}KeysLookup'.format(model)) self.assertEqual(instance.supplier, supplier) self.assertEqual(instance.model_name, model) self.assertEqual(instance.model_version, version) self.assertEqual(instance.keys_data_directory, keys_path)