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 logging
import os import os
import collections import collections
@ -232,11 +233,19 @@ class CdistObject(object):
[<Object __type/object_id>, <Object __other_type/any>, <Object __other_type/match>] [<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: for pattern in requirements:
found = False found = False
for requirement in fnmatch.filter(object_names, pattern): for requirement in fnmatch.filter(object_names, pattern):
found = True found = True
print("c:%s" % self.objects[requirement])
yield self.objects[requirement] yield self.objects[requirement]
if not found: if not found:
# FIXME: get rid of the singleton object_id, it should be invisible to the code -> hide it in Object # 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 a complete list of requirements is returned
""" """
all_requirements = [] all_reqs= []
all_requirements.extend(self.find_requirements_by_name(self.requirements)) all_reqs.extend(self.find_requirements_by_name(self.requirements))
all_requirements.extend(self.find_requirements_by_name(self.autorequire)) all_reqs.extend(self.find_requirements_by_name(self.autorequire))
return unique(all_requirements) return set(all_reqs)
class CircularReferenceError(cdist.Error): class CircularReferenceError(cdist.Error):

View file

@ -37,8 +37,16 @@ type_base_path = op.join(fixtures, 'type')
class ObjectClassTestCase(test.CdistTestCase): class ObjectClassTestCase(test.CdistTestCase):
def test_list_object_names(self): def test_list_object_names(self):
object_names = list(core.CdistObject.list_object_names(object_base_path)) found_object_names = sorted(list(core.CdistObject.list_object_names(object_base_path)))
self.assertEqual(object_names, ['__first/man', '__second/on-the', '__third/moon']) 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): def test_list_type_names(self):
type_names = list(cdist.core.CdistObject.list_type_names(object_base_path)) type_names = list(cdist.core.CdistObject.list_type_names(object_base_path))
@ -209,6 +217,9 @@ class ObjectResolveRequirementsTestCase(test.CdistTestCase):
def setUp(self): def setUp(self):
self.objects = list(core.CdistObject.list_objects(object_base_path, type_base_path)) 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_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_type = core.CdistType(type_base_path, '__third')
self.cdist_object = core.CdistObject(self.cdist_type, object_base_path, 'moon') self.cdist_object = core.CdistObject(self.cdist_type, object_base_path, 'moon')
@ -218,23 +229,28 @@ class ObjectResolveRequirementsTestCase(test.CdistTestCase):
o.requirements = [] o.requirements = []
def test_find_requirements_by_name_string(self): def test_find_requirements_by_name_string(self):
"""Check that resolving requirements by name works""" """Check that resolving requirements by name works (require all objects)"""
requirements = ['__first/man', '__second/on-the', '__third/moon'] requirements = self.object_names
required_objects = [self.object_index[name] for name in requirements] self.cdist_object.requirements = requirements
self.assertEqual(sorted(list(self.dependency_resolver.find_requirements_by_name(requirements))),
sorted(required_objects)) 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): 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 = ['__first/*', '__second/*-the', '__third/moon']
requirements_expanded = [
'__first/child', '__first/dog', '__first/man', '__first/woman', self.cdist_object.requirements = requirements
'__second/on-the', '__second/under-the',
'__third/moon' expected_requirements = sorted(self.objects)
] found_requirements = sorted(self.cdist_object.find_requirements_by_name(self.cdist_object.requirements))
required_objects = [self.object_index[name] for name in requirements_expanded]
self.assertEqual(sorted(list(self.dependency_resolver.find_requirements_by_name(requirements))), self.assertEqual(expected_requirements, found_requirements)
sorted(required_objects))
def test_dependency_resolution(self): def test_dependency_resolution(self):
first_man = self.object_index['__first/man'] first_man = self.object_index['__first/man']
@ -242,10 +258,13 @@ class ObjectResolveRequirementsTestCase(test.CdistTestCase):
third_moon = self.object_index['__third/moon'] third_moon = self.object_index['__third/moon']
first_man.requirements = [second_on_the.name] first_man.requirements = [second_on_the.name]
second_on_the.requirements = [third_moon.name] second_on_the.requirements = [third_moon.name]
self.assertEqual(
self.dependency_resolver.dependencies['__first/man'], # FIXME :-)
[third_moon, second_on_the, first_man] self.assertTrue(False)
) # self.assertEqual(
# self.dependency_resolver.dependencies['__first/man'],
# [third_moon, second_on_the, first_man]
# )
def test_requirement_not_found(self): def test_requirement_not_found(self):
first_man = self.object_index['__first/man'] first_man = self.object_index['__first/man']