예제 #1
0
class TestComponentResolving(unittest.TestCase):
    def setUp(self):
        self.l = LogCapture()
        
    def tearDown(self):
        self.l.uninstall()
        
    def test_that_resolve_does_not_warn_if_component_list_empty(self):
        root = ET.Element('component')
        op = ComponentParser()
        
        op.parse(root)
        op.resolve([])
        
        assert_that(self.l.__str__(), is_("No logging captured"))
        
    def test_that_resolve_does_not_warn_if_all_categories_found(self):
        category_name = 'something'
        category = MockCategory(category_name)
        name = 'sample component'
        root = _component_tree_with_category(category_name, name)
        op = ComponentParser()
        
        op.parse(root)
        op.resolve([category])
        
        assert_that(self.l.__str__(), is_("No logging captured"))
        
    def test_that_resolve_links_to_category(self):
        category_name = 'something'
        category = MockCategory(category_name)
        name = 'sample component'
        root = _component_tree_with_category(category_name, name)
        op = ComponentParser()
        
        op.parse(root)
        op.resolve([category])
        result = op.components[name]
        
        assert_that(result.category(category_name), is_(same_instance(category)))
        assert_that(category.set_component_was_called, is_(True))
        assert_that(category.component, is_(same_instance(result)))
        
    def test_that_resolve_warns_if_category_referenced_which_does_not_exist(self):
        category = 'something'
        name = 'sample component'
        root = _component_tree_with_category(category, name)
        op = ComponentParser()
        
        op.parse(root)
        op.resolve([])
        
        self.l.check(('root', 'WARNING', "Component '{0}' references undefined category '{1}'".format(name, category)))
예제 #2
0
class TestUsesResolving(unittest.TestCase):
    
    def setUp(self):
        self.l = LogCapture()
        
    def tearDown(self):
        self.l.uninstall()
        
    def test_that_resolving_warns_about_missing_category_backend_if_no_includes_found(self):
        op = UsesParser()
        category = MockCategory()
        
        op.resolve([category], [])
        
        self.l.check(('root', 'WARNING', "Category '{0}' has no backend specified".format(category.catid)))
        
    def test_that_resolving_does_not_warn_if_category_missing_backend_but_include_all_specified(self):
        root = ET.Element('config')
        uses = ET.SubElement(root, 'uses')
        backend = 'db'
        use = ET.SubElement(uses, 'use', {'backend':backend})
        ET.SubElement(use, 'includeall')  
        op = UsesParser()
        category = MockCategory()
        op.parse(root)

        op.resolve([category], [], {backend:MockBackend()})
        
        assert_that(self.l.__str__(), is_("No logging captured"))        
    
    def test_that_resolving_does_not_warn_if_category_missing_backend_but_component_includes_it(self):
        backend = 'db'
        category = MockCategory()
        example_component = Component(categories = [category.catid]) 
        component_name = 'example'
        root = _build_tree_with_valid_component_include(backend, component_name)
        op = UsesParser()
        op.parse(root)        
        
        op.resolve([category], {component_name:example_component}, {backend:MockBackend()})
        
        assert_that(self.l.__str__(), is_("No logging captured"))
        
    def test_that_component_level_exclude_overrides_include_all(self):
        category = MockCategory()      
        example_component = Component(categories = [category.catid]) 
        component_name = 'example'
        root = ET.Element('config')
        uses = ET.SubElement(root, 'uses')
        backend = 'db'
        use = ET.SubElement(uses, 'use', {'backend':backend})
        ET.SubElement(use, 'includeall')
        exclude = ET.SubElement(use, 'exclude')
        ET.SubElement(exclude, 'component', {'name':component_name})
        op = UsesParser()  
        op.parse(root)      
        
        op.resolve([category], {component_name:example_component})
        
        self.l.check(('root', 'WARNING', "Category '{0}' has no backend specified".format(category.catid)))
        
    def test_that_resolve_warns_if_category_linked_to_nonexistant_backend(self):
        backend = 'db'
        category = MockCategory()
        root = _build_tree_with_valid_category_include(backend, category)
        op = UsesParser()
        op.parse(root)
        
        op.resolve([category], {})
        
        self.l.check(('root', 'WARNING', "Category '{0}' has link to nonexistant backend {1}".format(category.catid, backend)))
        
    def test_that_resolve_links_categories_to_backend(self):
        backend = 'db'
        category = MockCategory()
        root = _build_tree_with_valid_category_include(backend, category)
        op = UsesParser()
        op.parse(root)
        example_backend = MockBackend()
        
        op.resolve([category], {}, {backend:example_backend})
        
        assert_that(category.set_backend_called, is_(True))
        assert_that(category.backend, is_(same_instance(example_backend)))
        
    def test_that_resolve_links_backends_to_categories(self):
        backend_name = 'db'
        category = MockCategory()
        root = _build_tree_with_valid_category_include(backend_name, category)
        op = UsesParser()
        op.parse(root)
        backend = MockBackend()
        
        op.resolve([category], {}, {backend_name:backend})
        
        assert_that(backend.add_category_called, is_(True))
        assert_that(backend.categories, has_item(same_instance(category)))
        
    def test_that_resolve_warns_if_component_include_is_not_in_components_list(self): 
        component_name = 'nonexistant'
        root = ET.Element('config')
        uses = ET.SubElement(root, 'uses')
        backend = 'db'
        use = ET.SubElement(uses, 'use', {'backend':backend})
        include = ET.SubElement(use, 'include')
        ET.SubElement(include, 'component', {'name':component_name})
        op = UsesParser()  
        op.parse(root)      
        category_name = "don't care"
        op.resolve([MockCategory(category_name)], {})
        
        # TODO We don't care about the second method here.  Create a better matcher than l.check to allow checking for only a subset of the messages 
        self.l.check(('root', 'WARNING', "Component '{0}' is included/excluded for backend {1}, but does not exist".format(component_name, backend)),
                      ('root', 'WARNING', "Category '{0}' has no backend specified".format(category_name)))