コード例 #1
0
ファイル: test_core.py プロジェクト: nastevens/epoxy
    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")
コード例 #2
0
ファイル: test_core.py プロジェクト: nastevens/epoxy
    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")
コード例 #3
0
ファイル: test_core.py プロジェクト: nastevens/epoxy
    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")
コード例 #4
0
ファイル: test_core.py プロジェクト: swstack/epoxy
    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')
コード例 #5
0
ファイル: test_core.py プロジェクト: swstack/epoxy
    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')
コード例 #6
0
ファイル: test_core.py プロジェクト: swstack/epoxy
    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')
コード例 #7
0
ファイル: test_core.py プロジェクト: nastevens/epoxy
    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)
コード例 #8
0
ファイル: test_core.py プロジェクト: swstack/epoxy
    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)
コード例 #9
0
ファイル: test_core.py プロジェクト: digidotcom/epoxy
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')
コード例 #10
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')