From 8031c7770041cff1be74655cec0745af5cdba480 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 18 Dec 2012 18:21:51 +0100 Subject: [PATCH] fix some tests, break some others :-) Signed-off-by: Nico Schottelius --- cdist/core/cdist_object.py | 19 +++++-- cdist/test/object/__init__.py | 57 ++++++++++++------- .../object/__first/child/.cdist/.keep | 0 .../fixtures/object/__first/dog/.cdist/.keep | 0 .../object/__first/woman/.cdist/.keep | 0 .../object/__second/under-the/.cdist/.keep | 0 6 files changed, 52 insertions(+), 24 deletions(-) create mode 100644 cdist/test/object/fixtures/object/__first/child/.cdist/.keep create mode 100644 cdist/test/object/fixtures/object/__first/dog/.cdist/.keep create mode 100644 cdist/test/object/fixtures/object/__first/woman/.cdist/.keep create mode 100644 cdist/test/object/fixtures/object/__second/under-the/.cdist/.keep diff --git a/cdist/core/cdist_object.py b/cdist/core/cdist_object.py index 7d757e67..3e5e33b7 100644 --- a/cdist/core/cdist_object.py +++ b/cdist/core/cdist_object.py @@ -20,6 +20,7 @@ # # +import fnmatch import logging import os import collections @@ -232,11 +233,19 @@ class CdistObject(object): [, , ] """ - object_names = self.list_object_names(self.base_path) + + # FIXME: think about where to store this - probably not here + self.objects = dict((o.name, o) for o in self.list_objects(self.base_path, self.cdist_type.base_path)) + object_names = self.objects.keys() + + print("a:%s" % self.objects) + print("b:%s" % object_names) + for pattern in requirements: found = False for requirement in fnmatch.filter(object_names, pattern): found = True + print("c:%s" % self.objects[requirement]) yield self.objects[requirement] if not found: # FIXME: get rid of the singleton object_id, it should be invisible to the code -> hide it in Object @@ -252,11 +261,11 @@ class CdistObject(object): a complete list of requirements is returned """ - all_requirements = [] - all_requirements.extend(self.find_requirements_by_name(self.requirements)) - all_requirements.extend(self.find_requirements_by_name(self.autorequire)) + all_reqs= [] + all_reqs.extend(self.find_requirements_by_name(self.requirements)) + all_reqs.extend(self.find_requirements_by_name(self.autorequire)) - return unique(all_requirements) + return set(all_reqs) class CircularReferenceError(cdist.Error): diff --git a/cdist/test/object/__init__.py b/cdist/test/object/__init__.py index 531300a7..ec6e25c1 100644 --- a/cdist/test/object/__init__.py +++ b/cdist/test/object/__init__.py @@ -37,8 +37,16 @@ type_base_path = op.join(fixtures, 'type') class ObjectClassTestCase(test.CdistTestCase): def test_list_object_names(self): - object_names = list(core.CdistObject.list_object_names(object_base_path)) - self.assertEqual(object_names, ['__first/man', '__second/on-the', '__third/moon']) + found_object_names = sorted(list(core.CdistObject.list_object_names(object_base_path))) + expected_object_names = sorted([ + '__first/child', + '__first/dog', + '__first/man', + '__first/woman', + '__second/on-the', + '__second/under-the', + '__third/moon']) + self.assertEqual(found_object_names, expected_object_names) def test_list_type_names(self): type_names = list(cdist.core.CdistObject.list_type_names(object_base_path)) @@ -209,6 +217,9 @@ class ObjectResolveRequirementsTestCase(test.CdistTestCase): def setUp(self): self.objects = list(core.CdistObject.list_objects(object_base_path, type_base_path)) self.object_index = dict((o.name, o) for o in self.objects) + self.object_names = [o.name for o in self.objects] + + print(self.objects) self.cdist_type = core.CdistType(type_base_path, '__third') self.cdist_object = core.CdistObject(self.cdist_type, object_base_path, 'moon') @@ -218,23 +229,28 @@ class ObjectResolveRequirementsTestCase(test.CdistTestCase): o.requirements = [] def test_find_requirements_by_name_string(self): - """Check that resolving requirements by name works""" - requirements = ['__first/man', '__second/on-the', '__third/moon'] + """Check that resolving requirements by name works (require all objects)""" + requirements = self.object_names - required_objects = [self.object_index[name] for name in requirements] - self.assertEqual(sorted(list(self.dependency_resolver.find_requirements_by_name(requirements))), - sorted(required_objects)) + self.cdist_object.requirements = requirements + + found_requirements = sorted(self.cdist_object.find_requirements_by_name(self.cdist_object.requirements)) + expected_requirements = sorted(self.objects) + + self.assertEqual(found_requirements, expected_requirements) def test_find_requirements_by_name_pattern(self): + """Test whether pattern matching on requirements works""" + + # Matches all objects in the end requirements = ['__first/*', '__second/*-the', '__third/moon'] - requirements_expanded = [ - '__first/child', '__first/dog', '__first/man', '__first/woman', - '__second/on-the', '__second/under-the', - '__third/moon' - ] - required_objects = [self.object_index[name] for name in requirements_expanded] - self.assertEqual(sorted(list(self.dependency_resolver.find_requirements_by_name(requirements))), - sorted(required_objects)) + + self.cdist_object.requirements = requirements + + expected_requirements = sorted(self.objects) + found_requirements = sorted(self.cdist_object.find_requirements_by_name(self.cdist_object.requirements)) + + self.assertEqual(expected_requirements, found_requirements) def test_dependency_resolution(self): first_man = self.object_index['__first/man'] @@ -242,10 +258,13 @@ class ObjectResolveRequirementsTestCase(test.CdistTestCase): third_moon = self.object_index['__third/moon'] first_man.requirements = [second_on_the.name] second_on_the.requirements = [third_moon.name] - self.assertEqual( - self.dependency_resolver.dependencies['__first/man'], - [third_moon, second_on_the, first_man] - ) + + # FIXME :-) + self.assertTrue(False) +# self.assertEqual( +# self.dependency_resolver.dependencies['__first/man'], +# [third_moon, second_on_the, first_man] +# ) def test_requirement_not_found(self): first_man = self.object_index['__first/man'] diff --git a/cdist/test/object/fixtures/object/__first/child/.cdist/.keep b/cdist/test/object/fixtures/object/__first/child/.cdist/.keep new file mode 100644 index 00000000..e69de29b diff --git a/cdist/test/object/fixtures/object/__first/dog/.cdist/.keep b/cdist/test/object/fixtures/object/__first/dog/.cdist/.keep new file mode 100644 index 00000000..e69de29b diff --git a/cdist/test/object/fixtures/object/__first/woman/.cdist/.keep b/cdist/test/object/fixtures/object/__first/woman/.cdist/.keep new file mode 100644 index 00000000..e69de29b diff --git a/cdist/test/object/fixtures/object/__second/under-the/.cdist/.keep b/cdist/test/object/fixtures/object/__second/under-the/.cdist/.keep new file mode 100644 index 00000000..e69de29b