Exemple #1
0
    def test_resolve_child_module_registries_lineage_malformed_loop(self):
        working_set = mocks.WorkingSet({})
        root = BaseModuleRegistry(
            'root', _working_set=working_set)
        parent = ChildModuleRegistry(
            'root.child', _parent=root, _working_set=working_set)
        child = ChildModuleRegistry(
            'root.child.child', _parent=parent, _working_set=working_set)
        grandchild = ChildModuleRegistry(
            'root.child.child.child', _parent=child, _working_set=working_set)
        # force a bad loop
        parent.parent = grandchild

        with pretty_logging(stream=mocks.StringIO()) as log:
            with self.assertRaises(TypeError) as e:
                resolve_child_module_registries_lineage(parent)

        self.assertEqual(
            "registry 'root.child' was already recorded in the lineage, "
            "indicating that it may be some (grand)child of itself, which is "
            "an illegal reference in the registry system; previously resolved "
            "lineage is: ['root.child.child', 'root.child.child.child', "
            "'root.child']", str(e.exception))
        self.assertIn(
            "the parent registry 'root.child.child.child' somehow has a "
            "longer name than its child registry 'root.child'; the underlying "
            "registry class may be constructed in an invalid manner",
            log.getvalue()
        )
Exemple #2
0
    def test_resolve_child_module_registries_lineage_malformed_loop(self):
        working_set = mocks.WorkingSet({})
        root = BaseModuleRegistry('root', _working_set=working_set)
        parent = ChildModuleRegistry('root.child',
                                     _parent=root,
                                     _working_set=working_set)
        child = ChildModuleRegistry('root.child.child',
                                    _parent=parent,
                                    _working_set=working_set)
        grandchild = ChildModuleRegistry('root.child.child.child',
                                         _parent=child,
                                         _working_set=working_set)
        # force a bad loop
        parent.parent = grandchild

        with pretty_logging(stream=mocks.StringIO()) as log:
            with self.assertRaises(TypeError) as e:
                resolve_child_module_registries_lineage(parent)

        self.assertEqual(
            "registry 'root.child' was already recorded in the lineage, "
            "indicating that it may be some (grand)child of itself, which is "
            "an illegal reference in the registry system; previously resolved "
            "lineage is: ['root.child.child', 'root.child.child.child', "
            "'root.child']", str(e.exception))
        self.assertIn(
            "the parent registry 'root.child.child.child' somehow has a "
            "longer name than its child registry 'root.child'; the underlying "
            "registry class may be constructed in an invalid manner",
            log.getvalue())
Exemple #3
0
 def test_resolve_child_module_registries_lineage_base(self):
     working_set = mocks.WorkingSet({})
     root = BaseModuleRegistry('root.module', _working_set=working_set)
     child = ChildModuleRegistry('root.module.child',
                                 _parent=root,
                                 _working_set=working_set)
     self.assertEqual([
         root,
         child,
     ], list(resolve_child_module_registries_lineage(child)))
Exemple #4
0
 def test_resolve_child_module_registries_lineage_base(self):
     working_set = mocks.WorkingSet({})
     root = BaseModuleRegistry(
         'root.module', _working_set=working_set)
     child = ChildModuleRegistry(
         'root.module.child', _parent=root, _working_set=working_set)
     self.assertEqual([
         root,
         child,
     ], list(resolve_child_module_registries_lineage(child)))
Exemple #5
0
 def test_resolve_child_module_registries_lineage_two_layers(self):
     working_set = mocks.WorkingSet({})
     root = BaseModuleRegistry('root.module', _working_set=working_set)
     child = ChildModuleRegistry('root.module.child',
                                 _parent=root,
                                 _working_set=working_set)
     grandchild = ChildModuleRegistry('root.module.child.child',
                                      _parent=child,
                                      _working_set=working_set)
     greatgrandchild = ChildModuleRegistry('root.module.child.child.child',
                                           _parent=grandchild,
                                           _working_set=working_set)
     self.assertEqual([
         root,
         child,
         grandchild,
     ], list(resolve_child_module_registries_lineage(grandchild)))
     self.assertEqual([
         root,
         child,
         grandchild,
         greatgrandchild,
     ], list(resolve_child_module_registries_lineage(greatgrandchild)))
Exemple #6
0
 def test_resolve_child_module_registries_lineage_two_layers(self):
     working_set = mocks.WorkingSet({})
     root = BaseModuleRegistry(
         'root.module', _working_set=working_set)
     child = ChildModuleRegistry(
         'root.module.child', _parent=root, _working_set=working_set)
     grandchild = ChildModuleRegistry(
         'root.module.child.child', _parent=child,
         _working_set=working_set)
     greatgrandchild = ChildModuleRegistry(
         'root.module.child.child.child', _parent=grandchild,
         _working_set=working_set)
     self.assertEqual([
         root,
         child,
         grandchild,
     ], list(resolve_child_module_registries_lineage(grandchild)))
     self.assertEqual([
         root,
         child,
         grandchild,
         greatgrandchild,
     ], list(resolve_child_module_registries_lineage(
         greatgrandchild)))
Exemple #7
0
    def test_resolve_child_module_registries_lineage_mismatched_prefixes(self):
        working_set = mocks.WorkingSet({})
        root = BaseModuleRegistry('root', _working_set=working_set)
        parent = ChildModuleRegistry('root.child',
                                     _parent=root,
                                     _working_set=working_set)
        child = ChildModuleRegistry('root_child.child',
                                    _parent=parent,
                                    _working_set=working_set)

        with pretty_logging(stream=mocks.StringIO()) as log:
            it = resolve_child_module_registries_lineage(child)

        self.assertIn(
            "child registry 'root_child.child' does not share the same common "
            "prefix as its parent registry 'root.child'; there may be errors "
            "with how the related registries are set up or constructed",
            log.getvalue())
        self.assertEqual(['root', 'root.child', 'root_child.child'],
                         [r.registry_name for r in it])
Exemple #8
0
    def test_resolve_child_module_registries_lineage_mismatched_prefixes(self):
        working_set = mocks.WorkingSet({})
        root = BaseModuleRegistry(
            'root', _working_set=working_set)
        parent = ChildModuleRegistry(
            'root.child', _parent=root, _working_set=working_set)
        child = ChildModuleRegistry(
            'root_child.child', _parent=parent, _working_set=working_set)

        with pretty_logging(stream=mocks.StringIO()) as log:
            it = resolve_child_module_registries_lineage(child)

        self.assertIn(
            "child registry 'root_child.child' does not share the same common "
            "prefix as its parent registry 'root.child'; there may be errors "
            "with how the related registries are set up or constructed",
            log.getvalue()
        )
        self.assertEqual([
            'root', 'root.child', 'root_child.child'
        ], [r.registry_name for r in it])
Exemple #9
0
 def test_resolve_child_module_registries_lineage_solo(self):
     working_set = mocks.WorkingSet({})
     root = BaseModuleRegistry('root.module', _working_set=working_set)
     it = resolve_child_module_registries_lineage(root)
     self.assertEqual(root, next(it))
     self.assertEqual([], list(it))
Exemple #10
0
 def test_resolve_child_module_registries_lineage_solo(self):
     working_set = mocks.WorkingSet({})
     root = BaseModuleRegistry('root.module', _working_set=working_set)
     it = resolve_child_module_registries_lineage(root)
     self.assertEqual(root, next(it))
     self.assertEqual([], list(it))