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_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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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')
    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 #15
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 #16
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 #17
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 #18
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 #19
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 #20
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 #21
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 #22
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 #23
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
Beispiel #24
0
class TestDependencyGraphResolution(unittest.TestCase):

    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

    def test_graph_ordering(self):
        graph = self.mgr.build_component_graph(self.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"))

    def test_graph_construction(self):
        self.mgr.launch_configuration(self.loader.load_configuration())
        a = self.mgr.components["a"]
        b = self.mgr.components["b"]
        c = self.mgr.components["c"]
        d = self.mgr.components["d"]
        self.assertEqual(a.previous, None)
        self.assertEqual(b.previous, a)
        self.assertEqual(c.previous, a)
        self.assertEqual(d.previous, c)

    def test_subgraph_construction(self):
        self.mgr.launch_subgraph(self.loader.load_configuration(), 'd:main')

        a = self.mgr.components["a"]
        with self.assertRaises(KeyError):
            self.mgr.components["b"]
        c = self.mgr.components["c"]
        d = self.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)

    def test_subgraph_bad_entry_point(self):
        with self.assertRaises(AttributeError):
            self.mgr.launch_subgraph(self.loader.load_configuration(), 'd:fake')
        last_log_message = self.log.call_args_list[0][0][0]
        self.assertEqual(last_log_message, "Bad entry point 'd:fake'")

    def test_bad_entry_point(self):
        cfg = self.invalid_loader.load_configuration()
        with self.assertRaises(AttributeError):
            self.mgr.launch_configuration(cfg)
        last_log_message = self.log.call_args_list[0][0][0]
        self.assertEqual(last_log_message, "Bad entry point 'a:fake_method'")

    def test_entry_point(self):
        configuration = self.loader.load_configuration()

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

        self.mgr.launch_configuration(configuration)

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

        self.assertFalse(a.is_main)
        self.assertFalse(b.is_main)
        self.assertFalse(c.is_main)
        self.assertTrue(d.is_main)

    def test_invalid_class(self):
        configuration = self.loader.load_configuration()

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

        with self.assertRaises(AttributeError):
            self.mgr.launch_subgraph(configuration, 'd:main')
        last_logged_msg = self.log.call_args_list[0][0][0]
        self.assertEqual(last_logged_msg,
                         "Class path '%s' is invalid, check your epoxy config" % invalid_comp)

    def test_missing_component(self):
        configuration = self.loader.load_configuration()

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

        with self.assertRaises(ValueError):
            self.mgr.launch_subgraph(configuration, 'd:main')

    def test_cycle_detection(self):
        configuration = self.loader.load_configuration()

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

        with self.assertRaises(ValueError):
            self.mgr.launch_configuration(configuration)

    def test_subgraph_cycle_detection(self):
        configuration = self.loader.load_configuration()

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

        with self.assertRaises(ValueError):
            self.mgr.launch_subgraph(configuration, 'd:main')

    def test_settings(self):
        config = self.loader.load_configuration()
        self.mgr.launch_configuration(config)
        a = self.mgr.components["a"]
        b = self.mgr.components["b"]
        c = self.mgr.components["c"]
        d = self.mgr.components["d"]
        self.assertEqual(a.name, 'alfred')
        self.assertEqual(b.name, 'barry')
        self.assertEqual(c.name, 'charles')
        self.assertEqual(d.name, 'daniel')
Beispiel #25
0
class TestDependencyGraphResolution(unittest.TestCase):
    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

    def test_graph_ordering(self):
        graph = self.mgr.build_component_graph(
            self.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"))

    def test_graph_construction(self):
        self.mgr.launch_configuration(self.loader.load_configuration())
        a = self.mgr.components["a"]
        b = self.mgr.components["b"]
        c = self.mgr.components["c"]
        d = self.mgr.components["d"]
        self.assertEqual(a.previous, None)
        self.assertEqual(b.previous, a)
        self.assertEqual(c.previous, a)
        self.assertEqual(d.previous, c)

    def test_subgraph_construction(self):
        self.mgr.launch_subgraph(self.loader.load_configuration(), 'd:main')

        a = self.mgr.components["a"]
        with self.assertRaises(KeyError):
            self.mgr.components["b"]
        c = self.mgr.components["c"]
        d = self.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)

    def test_subgraph_bad_entry_point(self):
        with self.assertRaises(AttributeError):
            self.mgr.launch_subgraph(self.loader.load_configuration(),
                                     'd:fake')
        last_log_message = self.log.call_args_list[0][0][0]
        self.assertEqual(last_log_message, "Bad entry point 'd:fake'")

    def test_bad_entry_point(self):
        cfg = self.invalid_loader.load_configuration()
        with self.assertRaises(AttributeError):
            self.mgr.launch_configuration(cfg)
        last_log_message = self.log.call_args_list[0][0][0]
        self.assertEqual(last_log_message, "Bad entry point 'a:fake_method'")

    def test_entry_point(self):
        configuration = self.loader.load_configuration()

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

        self.mgr.launch_configuration(configuration)

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

        self.assertFalse(a.is_main)
        self.assertFalse(b.is_main)
        self.assertFalse(c.is_main)
        self.assertTrue(d.is_main)

    def test_invalid_class(self):
        configuration = self.loader.load_configuration()

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

        with self.assertRaises(AttributeError):
            self.mgr.launch_subgraph(configuration, 'd:main')
        last_logged_msg = self.log.call_args_list[0][0][0]
        self.assertEqual(
            last_logged_msg,
            "Class path '%s' is invalid, check your epoxy config" %
            invalid_comp)

    def test_missing_component(self):
        configuration = self.loader.load_configuration()

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

        with self.assertRaises(ValueError):
            self.mgr.launch_subgraph(configuration, 'd:main')

    def test_cycle_detection(self):
        configuration = self.loader.load_configuration()

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

        with self.assertRaises(ValueError):
            self.mgr.launch_configuration(configuration)

    def test_subgraph_cycle_detection(self):
        configuration = self.loader.load_configuration()

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

        with self.assertRaises(ValueError):
            self.mgr.launch_subgraph(configuration, 'd:main')

    def test_settings(self):
        config = self.loader.load_configuration()
        self.mgr.launch_configuration(config)
        a = self.mgr.components["a"]
        b = self.mgr.components["b"]
        c = self.mgr.components["c"]
        d = self.mgr.components["d"]
        self.assertEqual(a.name, 'alfred')
        self.assertEqual(b.name, 'barry')
        self.assertEqual(c.name, 'charles')
        self.assertEqual(d.name, 'daniel')
Beispiel #26
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