Esempio n. 1
0
 def test_greater(self):
     model_name = 'aaa'
     model_path = '/path/to/systems/Foo_system/models/aaa'
     mdfl_1 = DefinitionLocation(name=model_name, path=model_path)
     model_name = 'zzz'
     model_path = '/path/to/systems/Foo_system/models/zzz'
     mdfl_2 = DefinitionLocation(name=model_name, path=model_path)
     self.assertGreater(mdfl_2, mdfl_1)
Esempio n. 2
0
 def test_hash(self):
     mdfl_1 = DefinitionLocation(name='/foo/model_1',
                                 path='/path/to/model_1.xml')
     mdfl_2 = DefinitionLocation(name='/foo/model_1',
                                 path='/path/to/model_1.xml')
     mdfl_3 = DefinitionLocation(name='/foo/model_3',
                                 path='/path/to/model_3.xml')
     self.assertTrue(isinstance(hash(mdfl_1), int))
     self.assertEqual(hash(mdfl_1), hash(mdfl_2))
     self.assertNotEqual(hash(mdfl_1), hash(mdfl_3))
Esempio n. 3
0
    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))
Esempio n. 4
0
 def test_eq(self):
     model_name = 'foo'
     model_fqn = 'Foo_system/models/foo'
     model_path = '/path/to/systems/Foo_system/models/foo'
     mdfl_1 = DefinitionLocation(name=model_name,
                                 fqn=model_fqn,
                                 path=model_path)
     mdfl_2 = DefinitionLocation(name=model_name,
                                 fqn=model_fqn,
                                 path=model_path)
     self.assertEqual(mdfl_1, mdfl_2)
Esempio n. 5
0
    def test_add_submodel(self):
        model_name = 'foo'
        model_path = '/path/to/systems/Foo_system/models/foo'
        mdfl = DefinitionLocation(name=model_name, path=model_path)
        submodel_name = 'bar'
        submodel_path = '/path/to/systems/Foo_system/models/foo/bar.xml'
        submodel = DefinitionLocation(name=submodel_name, path=submodel_path)
        mdfl.add_subdefinition(submodel)

        self.assertEqual(len(mdfl.subdefinitions), 1)
        self.assertEqual(mdfl.subdefinitions[submodel_name], submodel)
Esempio n. 6
0
 def test_lesser(self):
     model_name = 'aaa'
     model_fqn = 'Foo_system/models/aaa'
     model_path = '/path/to/systems/Foo_system/models/aaa'
     mdfl_1 = DefinitionLocation(name=model_name,
                                 fqn=model_fqn,
                                 path=model_path)
     model_name = 'zzz'
     model_fqn = 'Foo_system/models/zzz'
     model_path = '/path/to/systems/Foo_system/models/zzz'
     mdfl_2 = DefinitionLocation(name=model_name,
                                 fqn=model_fqn,
                                 path=model_path)
     self.assertLess(mdfl_1, mdfl_2)
Esempio n. 7
0
 def test_DefinitionLocationn(self):
     model_name = 'foo'
     model_path = '/path/to/model.xml'
     mdfl = DefinitionLocation(name=model_name, path=model_path)
     self.assertEqual(mdfl.name, model_name)
     self.assertEqual(mdfl.path, model_path)
     self.assertIsNone(mdfl.subdefinitions)
Esempio n. 8
0
 def test_family_name(self):
     model_name = 'foo'
     model_path = '/path/to/foo.xml'
     family_name = 'family'
     model_fqn = f"{family_name}/{model_name}"
     mdfl = DefinitionLocation(name=model_name,
                               fqn=model_fqn,
                               path=model_path)
     self.assertEqual(mdfl.family_name, family_name)
Esempio n. 9
0
 def test_all(self):
     model_name = 'foo'
     model_path = '/path/to/systems/Foo_system/models/foo'
     mdfl = DefinitionLocation(name=model_name, path=model_path)
     submodel_name1 = 'foo/bar'
     submodel_path1 = '/path/to/systems/Foo_system/models/foo/bar.xml'
     submodel1 = DefinitionLocation(name=submodel_name1,
                                    path=submodel_path1)
     mdfl.add_subdefinition(submodel1)
     submodel_name2 = 'foo/baz'
     submodel_path2 = '/path/to/systems/Foo_system/models/foo/baz.xml'
     submodel2 = DefinitionLocation(name=submodel_name2,
                                    path=submodel_path2)
     mdfl.add_subdefinition(submodel2)
     self.assertListEqual(sorted(mdfl.all()), sorted([submodel1,
                                                      submodel2]))
Esempio n. 10
0
    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)
Esempio n. 11
0
 def test_str(self):
     def_name = 'foo'
     def_fqn = 'foo'
     def_path = '/path/to/model.xml'
     mdfl = DefinitionLocation(name=def_name, fqn=def_fqn, path=def_path)
     self.assertEqual('foo', str(mdfl))
Esempio n. 12
0
 def test_root_name(self):
     self.assertEqual(DefinitionLocation.root_name('/foo/bar'), 'foo')
Esempio n. 13
0
 def test_split_fqn(self):
     self.assertListEqual(DefinitionLocation.split_fqn('/foo/bar'),
                          ['foo', 'bar'])
Esempio n. 14
0
 def test_str(self):
     model_name = 'foo'
     model_path = '/path/to/model.xml'
     mdfl = DefinitionLocation(name=model_name, path=model_path)
     self.assertEqual('foo', str(mdfl))
Esempio n. 15
0
 def test_family_name(self):
     model_name = 'foo'
     model_path = '/path/to/model.xml'
     mdfl = DefinitionLocation(name=model_name, path=model_path)
     self.assertEqual(mdfl.family_name, model_name)
Esempio n. 16
0
    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")