示例#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])
示例#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])
示例#3
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)
示例#4
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)
示例#5
0
    def test_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_configuration(configuration)
示例#6
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)
示例#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)
示例#8
0
    def test_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_configuration(configuration)
示例#9
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)
示例#10
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)
示例#11
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)
示例#12
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)
示例#13
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)
示例#14
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)
示例#15
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')
示例#16
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')