def test_get_all_definitions(self): complex_dir = _create_fake_models_tree(self.root_models_dir, self.complex_models) model_loc = ModelLocation(path=complex_dir) defs_expected = [] for def_name in self.complex_models['definitions']: for subdef_name in self.complex_models['definitions'][def_name]: if subdef_name.endswith('.xml'): new_def = DefinitionLocation( name=os.path.splitext(subdef_name)[0], fqn=os.path.splitext(def_name)[0], path=os.path.join(complex_dir, 'definitions', def_name, subdef_name)) new_def.fqn = '{model_name}{sep}{def_name}{sep}{subdef_name}'.format( model_name=model_loc.name, sep=registries._SEPARATOR, subdef_name=os.path.splitext(subdef_name)[0], def_name=def_name) defs_expected.append(new_def) else: for sub_subdef_name in self.complex_models['definitions'][ def_name][subdef_name]: new_def = DefinitionLocation( name=os.path.splitext(sub_subdef_name)[0], fqn=os.path.splitext(def_name)[0], path=os.path.join(complex_dir, 'definitions', subdef_name, sub_subdef_name)) new_def.fqn = '{model_name}{sep}{def_name}{sep}{subdef_name}{sep}{sub_subdef_name}'.format( model_name=model_loc.name, sep=registries._SEPARATOR, subdef_name=subdef_name, sub_subdef_name=os.path.splitext( sub_subdef_name)[0], def_name=def_name) defs_expected.append(new_def) defs_received = model_loc.get_all_definitions() self.assertEqual(sorted(defs_expected), sorted(defs_received)) defs_expected = [] def_root_name = 'subdef_1' for def_name in self.complex_models['definitions'][def_root_name]: new_def = DefinitionLocation(name=os.path.splitext(def_name)[0], fqn=os.path.splitext(def_name)[0], path=os.path.join( complex_dir, 'definitions', def_root_name, def_name)) new_def.fqn = '{model_name}{sep}{def_root_name}{sep}{def_name}'.format( model_name=model_loc.name, sep=registries._SEPARATOR, def_root_name=def_root_name, def_name=os.path.splitext(def_name)[0]) defs_expected.append(new_def) defs_received = model_loc.get_all_definitions( root_def_name="{model_name}{sep}{def_root_name}".format( model_name=model_loc.name, sep=registries._SEPARATOR, def_root_name=def_root_name)) self.assertEqual(sorted(defs_expected), sorted(defs_received))
def test_get_definition(self): # test new way to specify profiles and definitions simple_dir = _create_fake_models_tree(self.root_models_dir, self.simple_models) model_loc = ModelLocation(path=simple_dir) def_fqn = '{}{}{}'.format( model_loc.name, registries._SEPARATOR, os.path.splitext( list(self.simple_models['definitions'].keys())[0])[0]) defloc_expected_name = os.path.splitext( list(self.simple_models['definitions'].keys())[0])[0] defloc_expected = DefinitionLocation( name=defloc_expected_name, path=os.path.join(simple_dir, 'definitions', defloc_expected_name + '.xml')) defloc_expected.fqn = "{}{}{}".format( model_loc.name, registries._SEPARATOR, os.path.splitext( list(self.simple_models['definitions'].keys())[0])[0]) defloc_received = model_loc.get_definition(def_fqn) self.assertEqual(defloc_expected, defloc_received) complex_dir = _create_fake_models_tree(self.root_models_dir, self.complex_models) model_loc = ModelLocation(path=complex_dir) subdef_name = 'subdef_1' def_name = 'def_1_1' def_fqn = '{model_name}{sep}{subdef_name}{sep}{def_name}'.format( model_name=model_loc.name, sep=registries._SEPARATOR, subdef_name=subdef_name, def_name=def_name) defloc_expected = DefinitionLocation( name=def_name, path=os.path.join(complex_dir, 'definitions', subdef_name, def_name + '.xml')) defloc_expected.fqn = def_fqn defloc_received = model_loc.get_definition(def_fqn) self.assertEqual(defloc_expected, defloc_received)
def test_get_all_definitions(self): complex_dir = _create_fake_models_tree(self.root_models_dir, self.complex_models) model_loc = ModelLocation(path=complex_dir) defs_expected = [] for def_name in self.complex_models['definitions']: for subdef_name in self.complex_models['definitions'][def_name]: new_def = DefinitionLocation( name=os.path.splitext(subdef_name)[0], path=os.path.join(complex_dir, 'definitions', def_name, subdef_name)) new_def.fqn = '{model_name}{sep}{def_name}{sep}{subdef_name}'.format( model_name=model_loc.name, sep=registries._separator, subdef_name=os.path.splitext(subdef_name)[0], def_name=def_name) defs_expected.append(new_def) defs_received = model_loc.get_all_definitions() self.assertEqual(sorted(defs_expected), sorted(defs_received)) defs_expected = [] def_root_name = 'subdef_1' for def_name in self.complex_models['definitions'][def_root_name]: new_def = DefinitionLocation(name=os.path.splitext(def_name)[0], path=os.path.join( complex_dir, 'definitions', def_root_name, def_name)) new_def.fqn = '{model_name}{sep}{def_root_name}{sep}{def_name}'.format( model_name=model_loc.name, sep=registries._separator, def_root_name=def_root_name, def_name=os.path.splitext(def_name)[0]) defs_expected.append(new_def) defs_received = model_loc.get_all_definitions( root_def_name="{model_name}{sep}{def_root_name}".format( model_name=model_loc.name, sep=registries._separator, def_root_name=def_root_name)) self.assertEqual(sorted(defs_expected), sorted(defs_received)) # test old way to specify profiles and defitions simple_dir = _create_fake_models_tree(self.root_models_dir, self.simple_models) model_loc = ModelLocation(profile_dir=os.path.join( simple_dir, 'profiles'), def_dir=os.path.join(simple_dir, 'definitions')) defs_expected = [ DefinitionLocation(name=os.path.splitext(d)[0], path=os.path.join(simple_dir, 'definitions', d)) for d in self.simple_models['definitions'] ] defs_received = model_loc.get_all_definitions() self.assertEqual(sorted(defs_expected), sorted(defs_received)) with self.assertRaises(ValueError) as ctx: model_loc.get_all_definitions(root_def_name='foobar') self.assertEqual( str(ctx.exception), "root_def_name foobar does not match with any definitions")