fix some tests, break some others :-)

Signed-off-by: Nico Schottelius <nico@brief.schottelius.org>
This commit is contained in:
Nico Schottelius 2012-12-18 18:21:51 +01:00
parent 4faec43493
commit 8031c77700
6 changed files with 52 additions and 24 deletions

View file

@ -20,6 +20,7 @@
#
#
import fnmatch
import logging
import os
import collections
@ -232,11 +233,19 @@ class CdistObject(object):
[<Object __type/object_id>, <Object __other_type/any>, <Object __other_type/match>]
"""
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):

View file

@ -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']