From b1d661f4c03d5475ea418007427e12424c888a5f Mon Sep 17 00:00:00 2001
From: Nico Schottelius <nico@bento.schottelius.org>
Date: Thu, 20 Jun 2013 11:30:20 +0200
Subject: [PATCH] merge ResolverTestCase and AutorequireTestCase into
 ExecutionOrderTestCase

Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
---
 cdist/test/execution_order/__init__.py | 81 +++++++++++++-------------
 1 file changed, 41 insertions(+), 40 deletions(-)

diff --git a/cdist/test/execution_order/__init__.py b/cdist/test/execution_order/__init__.py
index 785b7ba8..5457e7dc 100644
--- a/cdist/test/execution_order/__init__.py
+++ b/cdist/test/execution_order/__init__.py
@@ -39,46 +39,7 @@ type_base_path = op.join(fixtures, 'type')
 add_conf_dir = op.join(fixtures, 'conf')
 
 
-class ResolverTestCase(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)
-
-    def tearDown(self):
-        for o in self.objects:
-            o.requirements = []
-
-    def test_dependency_resolution(self):
-        first_man = self.object_index['__first/man']
-        second_on_the = self.object_index['__second/on-the']
-        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]
-        )
-        self.assertTrue(False)
-
-    def test_circular_reference(self):
-        first_man = self.object_index['__first/man']
-        first_woman = self.object_index['__first/woman']
-        first_man.requirements = [first_woman.name]
-        first_woman.requirements = [first_man.name]
-        with self.assertRaises(resolver.CircularReferenceError):
-            self.dependency_resolver.dependencies
-        self.assertTrue(False)
-
-    def test_requirement_not_found(self):
-        first_man = self.object_index['__first/man']
-        first_man.requirements = ['__does/not/exist']
-        with self.assertRaises(cdist.Error):
-            self.dependency_resolver.dependencies
-        self.assertTrue(False)
-
-class AutorequireTestCase(test.CdistTestCase):
-
+class ExecutionOrderTestCase(test.CdistTestCase):
     def setUp(self):
         self.orig_environ = os.environ
         os.environ = os.environ.copy()
@@ -100,10 +61,50 @@ class AutorequireTestCase(test.CdistTestCase):
 
         self.config = config.Config(self.context)
 
+        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)
+
     def tearDown(self):
         os.environ = self.orig_environ
         shutil.rmtree(self.temp_dir)
 
+        for o in self.objects:
+            o.requirements = []
+
+    def test_dependency_resolution(self):
+        """Check that the runtime respects the right order"""
+        first_man = self.object_index['__first/man']
+        second_on_the = self.object_index['__second/on-the']
+        third_moon = self.object_index['__third/moon']
+
+        first_man.requirements = [second_on_the.name]
+        second_on_the.requirements = [third_moon.name]
+
+        self.config.iterate_once()
+
+
+        self.assertEqual(
+            self.dependency_resolver.dependencies['__first/man'],
+            [third_moon, second_on_the, first_man]
+        )
+        self.assertTrue(False)
+
+    def test_circular_reference(self):
+        first_man = self.object_index['__first/man']
+        first_woman = self.object_index['__first/woman']
+        first_man.requirements = [first_woman.name]
+        first_woman.requirements = [first_man.name]
+        with self.assertRaises(resolver.CircularReferenceError):
+            self.dependency_resolver.dependencies
+        self.assertTrue(False)
+
+    def test_requirement_not_found(self):
+        first_man = self.object_index['__first/man']
+        first_man.requirements = ['__does/not/exist']
+        with self.assertRaises(cdist.Error):
+            self.dependency_resolver.dependencies
+        self.assertTrue(False)
+
     def test_implicit_dependencies(self):
         self.context.initial_manifest = os.path.join(self.context.local.manifest_path, 'implicit_dependencies')
         self.config.stage_prepare()