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_parse_returns_a_uses_if_one_is_specified(self): root = ET.Element('config') ET.SubElement(root, 'uses') op = UsesParser() op.parse(root) result = op.uses assert_that(result, is_not(None)) assert_that(type(result), is_(type(Uses)))
def test_that_parse_ignores_uses_which_dont_reference_a_backend(self): root = ET.Element('config') uses = ET.SubElement(root, 'uses') ET.SubElement(uses, 'use') op = UsesParser() op.parse(root) result = op.uses assert_that(len(result.uses), is_(0))
def test_that_category_is_added_to_includes_for_backend_if_include_specified_in_use_element(self): backend = 'db' category = MockCategory() root = _build_tree_with_valid_category_include(backend, category) op = UsesParser() op.parse(root) result = op.uses assert_that(result.backend_for(category.catid), is_(backend))
def test_that_parse_returns_a_uses_including_a_dictionary_of_use_sets_if_at_least_one_is_specified(self): root = ET.Element('config') uses = ET.SubElement(root, 'uses') ET.SubElement(uses, 'use', {'backend':'db'}) op = UsesParser() op.parse(root) result = op.uses assert_that(result.uses, is_not(None)) assert_that(result.uses, has_key('db'))
def test_that_category_is_added_to_included_in_backend_with_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() op.parse(root) result = op.uses assert_that(result.backend_for('anything'), is_(backend))
def test_that_parsing_two_uses_elements_with_a_category_include_each_includes_both(self): backend = 'db' category1 = MockCategory('publication') category2 = MockCategory('another') root1 = _build_tree_with_valid_category_include(backend, category1) root2 = _build_tree_with_valid_category_include(backend, category2) op = UsesParser() op.parse(root1) op.parse(root2) result = op.uses assert_that(result.backend_for(category1.catid), is_(backend)) assert_that(result.backend_for(category2.catid), is_(backend))
def test_that_two_uses_in_same_tree_can_both_add_includes(self): root = ET.Element('config') backend1 = 'db' category1 = 'publication' backend2 = 'cass' category2 = 'another' self._add_uses_element(root, backend1, category1) self._add_uses_element(root, backend2, category2) op = UsesParser() op.parse(root) result = op.uses assert_that(result.backend_for(category1), is_(backend1)) assert_that(result.backend_for(category2), is_(backend2))
def test_that_excluded_category_overrides_include_all_element(self): root = ET.Element('config') uses = ET.SubElement(root, 'uses') backend = 'db' use = ET.SubElement(uses, 'use', {'backend':backend}) ET.SubElement(use, 'includeall') include = ET.SubElement(use, 'exclude') category = 'publication' ET.SubElement(include, 'category', {'name':category}) op = UsesParser() op.parse(root) result = op.uses assert_that(result.backend_for(category), is_(None))
def __init__(self, component_parser=ComponentParser(), backend_parser=BackendParser(), uses_parser=UsesParser()): self._uses_parser = uses_parser self._component_parser = component_parser self._backend_parser = backend_parser self._parsers = [component_parser, backend_parser, uses_parser]
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_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_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_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_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)))
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)))