Beispiel #1
0
    def test_dependency_list(self):
        mgr = ComponentManager()
        loader = YamlConfigurationLoader(
            os.path.join(os.path.dirname(__file__),
                         "test_dependency_list.yml"))
        mgr.launch_configuration(loader.load_configuration())
        a = mgr.components["a"]
        b = mgr.components["b"]
        c = mgr.components["c"]
        d = mgr.components["d"]

        self.assertListEqual(a.others.get_list(), [b, c, d])

        for comp in (b, c, d):
            self.assertListEqual(comp.others.get_list(), [])

        # list.index implementation
        self.assertEqual(a.others.index(b), 0)
        self.assertEqual(a.others.index(c), 1)
        self.assertEqual(a.others.index(d), 2)

        # list subscript implementation
        self.assertEqual(a.others[0], b)
        self.assertEqual(a.others[1], c)
        self.assertEqual(a.others[2], d)

        # list.count implementation
        self.assertEqual(a.others.count(b), 1)
        self.assertEqual(a.others.count(c), 1)
        self.assertEqual(a.others.count(d), 1)

        # list __reversed__ implementation
        self.assertListEqual(list(reversed(a.others)), [d, c, b])
Beispiel #2
0
    def test_configuration_extension(self):
        mgr = ComponentManager()
        loader = YamlConfigurationLoader(
            os.path.join(os.path.dirname(__file__),
                         "test_configuration_child.yml"))
        mgr.launch_configuration(loader.load_configuration(), debug=3)
        a = mgr.components["a"]
        b = mgr.components["b"]

        self.assertEqual(b.next, a)
Beispiel #3
0
    def test_dependency_list(self):
        mgr = ComponentManager()
        loader = PythonLoader('epoxy.test.test_python_loader:data')
        mgr.launch_configuration(loader.load_configuration())
        a = mgr.components["a"]
        b = mgr.components["b"]
        c = mgr.components["c"]

        self.assertEqual(b.next, a)
        self.assertEqual(c.next, b)
Beispiel #4
0
 def test_graph_ordering(self):
     mgr = ComponentManager()
     loader = YamlConfigurationLoader(
         os.path.join(os.path.dirname(__file__), "test.yml"))
     graph = mgr.build_component_graph(loader.load_configuration())
     ordering = graph.get_ordering()
     o = [x.name for x in ordering]
     self.assertEqual(len(ordering), 5)  # our 4 plus component_manager
     self.assert_(o.index("b") > o.index("a"))
     self.assert_(o.index("c") > o.index("a"))
     self.assert_(o.index("d") > o.index("c"))
Beispiel #5
0
    def test_subgraph_cycle_detection(self):
        mgr = ComponentManager()
        loader = YamlConfigurationLoader(
            os.path.join(os.path.dirname(__file__), "test.yml"))
        configuration = loader.load_configuration()

        # Change class to invalid component
        configuration['components']['a']['dependencies'] = {'previous': 'd'}

        with self.assertRaises(ValueError):
            mgr.launch_subgraph(configuration, 'd:main')
Beispiel #6
0
    def test_missing_component(self):
        mgr = ComponentManager()
        loader = YamlConfigurationLoader(
            os.path.join(os.path.dirname(__file__), "test.yml"))
        configuration = loader.load_configuration()

        # Delete required component
        del configuration['components']['a']

        with self.assertRaises(ValueError):
            mgr.launch_subgraph(configuration, 'd:main')
Beispiel #7
0
    def test_missing_item_in_dep_list(self):
        mgr = ComponentManager()
        loader = YamlConfigurationLoader(
            os.path.join(os.path.dirname(__file__),
                         "test_dependency_list.yml"))
        configuration = loader.load_configuration()

        # Delete component b
        del configuration['components']['b']

        with self.assertRaises(ValueError):
            mgr.launch_configuration(configuration)
Beispiel #8
0
    def test_invalid_class(self):
        mgr = ComponentManager()
        loader = YamlConfigurationLoader(
            os.path.join(os.path.dirname(__file__), "test.yml"))
        configuration = loader.load_configuration()

        # Change class to invalid component
        configuration['components']['a']['class'] = \
            'epoxy.test.test_core:InvalidComponent'

        with self.assertRaises(AttributeError):
            mgr.launch_subgraph(configuration, 'd:main')
Beispiel #9
0
 def test_graph_construction(self):
     mgr = ComponentManager()
     loader = YamlConfigurationLoader(
         os.path.join(os.path.dirname(__file__), "test.yml"))
     mgr.launch_configuration(loader.load_configuration())
     a = mgr.components["a"]
     b = mgr.components["b"]
     c = mgr.components["c"]
     d = mgr.components["d"]
     self.assertEqual(a.previous, None)
     self.assertEqual(b.previous, a)
     self.assertEqual(c.previous, a)
     self.assertEqual(d.previous, c)
Beispiel #10
0
    def test_subgraph_construction(self):
        mgr = ComponentManager()
        loader = YamlConfigurationLoader(
            os.path.join(os.path.dirname(__file__), "test.yml"))
        mgr.launch_subgraph(loader.load_configuration(), 'd:main')

        a = mgr.components["a"]
        with self.assertRaises(KeyError):
            mgr.components["b"]
        c = mgr.components["c"]
        d = mgr.components["d"]

        self.assertEqual(a.previous, None)
        self.assertEqual(c.previous, a)
        self.assertEqual(d.previous, c)

        self.assertFalse(a.is_main)
        self.assertFalse(c.is_main)
        self.assertTrue(d.is_main)
Beispiel #11
0
    def test_entry_point(self):
        mgr = ComponentManager()
        loader = YamlConfigurationLoader(
            os.path.join(os.path.dirname(__file__), "test.yml"))
        configuration = loader.load_configuration()

        # Add entry-point to configuration
        configuration['entry-point'] = 'd:main'

        mgr.launch_configuration(configuration)

        a = mgr.components["a"]
        b = mgr.components["b"]
        c = mgr.components["c"]
        d = mgr.components["d"]

        self.assertFalse(a.is_main)
        self.assertFalse(b.is_main)
        self.assertFalse(c.is_main)
        self.assertTrue(d.is_main)
Beispiel #12
0
 def setUp(self):
     self.mgr = ComponentManager()
     self.loader = YamlConfigurationLoader(VALID_TEST_YAML)
     self.invalid_loader = YamlConfigurationLoader(INVALID_TEST_YAML)
     self.log = mock.Mock()
     epoxy_core.log = self.log