changeset 616:dd64ca07ecae

Move tests that can be run with only the slave modules present to a separate `slave_tests` package
author dfraser
date Wed, 05 Aug 2009 09:34:04 +0000
parents d960021f902f
children 327dca35a74f
files bitten/slave_tests/__init__.py bitten/slave_tests/recipe.py bitten/slave_tests/slave.py bitten/tests/__init__.py bitten/tests/recipe.py bitten/tests/slave.py
diffstat 6 files changed, 198 insertions(+), 172 deletions(-) [+]
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/bitten/slave_tests/__init__.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2005-2007 Christopher Lenz <cmlenz@gmx.de>
+# Copyright (C) 2007 Edgewall Software
+# All rights reserved.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at http://bitten.edgewall.org/wiki/License.
+
+import unittest
+from bitten.slave_tests import recipe, slave
+from bitten.build import tests as build
+from bitten.util import tests as util
+
+def suite():
+    suite = unittest.TestSuite()
+    suite.addTest(recipe.suite())
+    suite.addTest(slave.suite())
+    suite.addTest(build.suite())
+    suite.addTest(util.suite())
+    return suite
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='suite')
new file mode 100644
--- /dev/null
+++ b/bitten/slave_tests/recipe.py
@@ -0,0 +1,129 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2005-2007 Christopher Lenz <cmlenz@gmx.de>
+# Copyright (C) 2007 Edgewall Software
+# All rights reserved.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at http://bitten.edgewall.org/wiki/License.
+
+import os
+import shutil
+import tempfile
+import unittest
+
+from bitten.build.config import Configuration
+from bitten.recipe import Context, Recipe, InvalidRecipeError
+from bitten.util import xmlio
+
+
+class ContextTestCase(unittest.TestCase):
+
+    def setUp(self):
+        self.basedir = os.path.realpath(tempfile.mkdtemp())
+
+    def tearDown(self):
+        shutil.rmtree(self.basedir)
+
+    def test_vars_basedir(self):
+        config = Configuration(properties={'foo.bar': 'baz'})
+        ctxt = Context('%s/${path}/${foo.bar}' % os.path.realpath('/foo'),
+                        config, {'path': 'bar'})
+
+        self.assertEquals(os.path.realpath('/foo/bar/baz'),
+                        ctxt.vars['basedir'])
+
+
+class RecipeTestCase(unittest.TestCase):
+
+    def setUp(self):
+        self.basedir = os.path.realpath(tempfile.mkdtemp())
+
+    def tearDown(self):
+        shutil.rmtree(self.basedir)
+
+    def test_empty_recipe(self):
+        xml = xmlio.parse('<build/>')
+        recipe = Recipe(xml, basedir=self.basedir)
+        self.assertEqual(self.basedir, recipe.ctxt.basedir)
+        steps = list(recipe)
+        self.assertEqual(0, len(steps))
+
+    def test_empty_step(self):
+        xml = xmlio.parse('<build>'
+                          ' <step id="foo" description="Bar"></step>'
+                          '</build>')
+        recipe = Recipe(xml, basedir=self.basedir)
+        steps = list(recipe)
+        self.assertEqual(1, len(steps))
+        self.assertEqual('foo', steps[0].id)
+        self.assertEqual('Bar', steps[0].description)
+        self.assertEqual('fail', steps[0].onerror)
+
+    def test_validate_bad_root(self):
+        xml = xmlio.parse('<foo></foo>')
+        recipe = Recipe(xml, basedir=self.basedir)
+        self.assertRaises(InvalidRecipeError, recipe.validate)
+
+    def test_validate_no_steps(self):
+        xml = xmlio.parse('<build></build>')
+        recipe = Recipe(xml, basedir=self.basedir)
+        self.assertRaises(InvalidRecipeError, recipe.validate)
+
+    def test_validate_child_not_step(self):
+        xml = xmlio.parse('<build><foo/></build>')
+        recipe = Recipe(xml, basedir=self.basedir)
+        self.assertRaises(InvalidRecipeError, recipe.validate)
+
+    def test_validate_child_not_step(self):
+        xml = xmlio.parse('<build><foo/></build>')
+        recipe = Recipe(xml, basedir=self.basedir)
+        self.assertRaises(InvalidRecipeError, recipe.validate)
+
+    def test_validate_step_without_id(self):
+        xml = xmlio.parse('<build><step><cmd/></step></build>')
+        recipe = Recipe(xml, basedir=self.basedir)
+        self.assertRaises(InvalidRecipeError, recipe.validate)
+
+    def test_validate_step_with_empty_id(self):
+        xml = xmlio.parse('<build><step id=""><cmd/></step></build>')
+        recipe = Recipe(xml, basedir=self.basedir)
+        self.assertRaises(InvalidRecipeError, recipe.validate)
+
+    def test_validate_step_without_commands(self):
+        xml = xmlio.parse('<build><step id="test"/></build>')
+        recipe = Recipe(xml, basedir=self.basedir)
+        self.assertRaises(InvalidRecipeError, recipe.validate)
+
+    def test_validate_step_with_command_children(self):
+        xml = xmlio.parse('<build><step id="test">'
+                          '<somecmd><child1/><child2/></somecmd>'
+                          '</step></build>')
+        recipe = Recipe(xml, basedir=self.basedir)
+        self.assertRaises(InvalidRecipeError, recipe.validate)
+
+    def test_validate_step_with_duplicate_id(self):
+        xml = xmlio.parse('<build>'
+                          '<step id="test"><somecmd></somecmd></step>'
+                          '<step id="test"><othercmd></othercmd></step>'
+                          '</build>')
+        recipe = Recipe(xml, basedir=self.basedir)
+        self.assertRaises(InvalidRecipeError, recipe.validate)
+
+    def test_validate_successful(self):
+        xml = xmlio.parse('<build>'
+                          '<step id="foo"><somecmd></somecmd></step>'
+                          '<step id="bar"><othercmd></othercmd></step>'
+                          '</build>')
+        recipe = Recipe(xml, basedir=self.basedir)
+        recipe.validate()
+
+def suite():
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(ContextTestCase, 'test'))
+    suite.addTest(unittest.makeSuite(RecipeTestCase, 'test'))
+    return suite
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='suite')
new file mode 100644
--- /dev/null
+++ b/bitten/slave_tests/slave.py
@@ -0,0 +1,42 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2005-2007 Christopher Lenz <cmlenz@gmx.de>
+# Copyright (C) 2007 Edgewall Software
+# All rights reserved.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at http://bitten.edgewall.org/wiki/License.
+
+import os
+import shutil
+import tempfile
+import unittest
+
+from bitten.slave import BuildSlave, ExitSlave
+
+class BuildSlaveTestCase(unittest.TestCase):
+
+    def setUp(self):
+        self.work_dir = tempfile.mkdtemp(prefix='bitten_test')
+        self.slave = BuildSlave([], work_dir=self.work_dir)
+
+    def tearDown(self):
+        shutil.rmtree(self.work_dir)
+
+    def _create_file(self, *path):
+        filename = os.path.join(self.work_dir, *path)
+        fd = file(filename, 'w')
+        fd.close()
+        return filename
+
+    def test_quit_raises(self):
+        self.assertRaises(ExitSlave, self.slave.quit)
+
+def suite():
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(BuildSlaveTestCase, 'test'))
+    return suite
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='suite')
--- a/bitten/tests/__init__.py
+++ b/bitten/tests/__init__.py
@@ -9,7 +9,8 @@
 # are also available at http://bitten.edgewall.org/wiki/License.
 
 import unittest
-from bitten.tests import admin, master, model, recipe, queue, slave, web_ui, notify
+from bitten.tests import admin, master, model, queue, web_ui, notify
+from bitten.slave_tests import slave, recipe
 from bitten.build import tests as build
 from bitten.report import tests as report
 from bitten.util import tests as util
deleted file mode 100644
--- a/bitten/tests/recipe.py
+++ /dev/null
@@ -1,129 +0,0 @@
-# -*- coding: utf-8 -*-
-#
-# Copyright (C) 2005-2007 Christopher Lenz <cmlenz@gmx.de>
-# Copyright (C) 2007 Edgewall Software
-# All rights reserved.
-#
-# This software is licensed as described in the file COPYING, which
-# you should have received as part of this distribution. The terms
-# are also available at http://bitten.edgewall.org/wiki/License.
-
-import os
-import shutil
-import tempfile
-import unittest
-
-from bitten.build.config import Configuration
-from bitten.recipe import Context, Recipe, InvalidRecipeError
-from bitten.util import xmlio
-
-
-class ContextTestCase(unittest.TestCase):
-
-    def setUp(self):
-        self.basedir = os.path.realpath(tempfile.mkdtemp())
-
-    def tearDown(self):
-        shutil.rmtree(self.basedir)
-
-    def test_vars_basedir(self):
-        config = Configuration(properties={'foo.bar': 'baz'})
-        ctxt = Context('%s/${path}/${foo.bar}' % os.path.realpath('/foo'),
-                        config, {'path': 'bar'})
-
-        self.assertEquals(os.path.realpath('/foo/bar/baz'),
-                        ctxt.vars['basedir'])
-
-
-class RecipeTestCase(unittest.TestCase):
-
-    def setUp(self):
-        self.basedir = os.path.realpath(tempfile.mkdtemp())
-
-    def tearDown(self):
-        shutil.rmtree(self.basedir)
-
-    def test_empty_recipe(self):
-        xml = xmlio.parse('<build/>')
-        recipe = Recipe(xml, basedir=self.basedir)
-        self.assertEqual(self.basedir, recipe.ctxt.basedir)
-        steps = list(recipe)
-        self.assertEqual(0, len(steps))
-
-    def test_empty_step(self):
-        xml = xmlio.parse('<build>'
-                          ' <step id="foo" description="Bar"></step>'
-                          '</build>')
-        recipe = Recipe(xml, basedir=self.basedir)
-        steps = list(recipe)
-        self.assertEqual(1, len(steps))
-        self.assertEqual('foo', steps[0].id)
-        self.assertEqual('Bar', steps[0].description)
-        self.assertEqual('fail', steps[0].onerror)
-
-    def test_validate_bad_root(self):
-        xml = xmlio.parse('<foo></foo>')
-        recipe = Recipe(xml, basedir=self.basedir)
-        self.assertRaises(InvalidRecipeError, recipe.validate)
-
-    def test_validate_no_steps(self):
-        xml = xmlio.parse('<build></build>')
-        recipe = Recipe(xml, basedir=self.basedir)
-        self.assertRaises(InvalidRecipeError, recipe.validate)
-
-    def test_validate_child_not_step(self):
-        xml = xmlio.parse('<build><foo/></build>')
-        recipe = Recipe(xml, basedir=self.basedir)
-        self.assertRaises(InvalidRecipeError, recipe.validate)
-
-    def test_validate_child_not_step(self):
-        xml = xmlio.parse('<build><foo/></build>')
-        recipe = Recipe(xml, basedir=self.basedir)
-        self.assertRaises(InvalidRecipeError, recipe.validate)
-
-    def test_validate_step_without_id(self):
-        xml = xmlio.parse('<build><step><cmd/></step></build>')
-        recipe = Recipe(xml, basedir=self.basedir)
-        self.assertRaises(InvalidRecipeError, recipe.validate)
-
-    def test_validate_step_with_empty_id(self):
-        xml = xmlio.parse('<build><step id=""><cmd/></step></build>')
-        recipe = Recipe(xml, basedir=self.basedir)
-        self.assertRaises(InvalidRecipeError, recipe.validate)
-
-    def test_validate_step_without_commands(self):
-        xml = xmlio.parse('<build><step id="test"/></build>')
-        recipe = Recipe(xml, basedir=self.basedir)
-        self.assertRaises(InvalidRecipeError, recipe.validate)
-
-    def test_validate_step_with_command_children(self):
-        xml = xmlio.parse('<build><step id="test">'
-                          '<somecmd><child1/><child2/></somecmd>'
-                          '</step></build>')
-        recipe = Recipe(xml, basedir=self.basedir)
-        self.assertRaises(InvalidRecipeError, recipe.validate)
-
-    def test_validate_step_with_duplicate_id(self):
-        xml = xmlio.parse('<build>'
-                          '<step id="test"><somecmd></somecmd></step>'
-                          '<step id="test"><othercmd></othercmd></step>'
-                          '</build>')
-        recipe = Recipe(xml, basedir=self.basedir)
-        self.assertRaises(InvalidRecipeError, recipe.validate)
-
-    def test_validate_successful(self):
-        xml = xmlio.parse('<build>'
-                          '<step id="foo"><somecmd></somecmd></step>'
-                          '<step id="bar"><othercmd></othercmd></step>'
-                          '</build>')
-        recipe = Recipe(xml, basedir=self.basedir)
-        recipe.validate()
-
-def suite():
-    suite = unittest.TestSuite()
-    suite.addTest(unittest.makeSuite(ContextTestCase, 'test'))
-    suite.addTest(unittest.makeSuite(RecipeTestCase, 'test'))
-    return suite
-
-if __name__ == '__main__':
-    unittest.main(defaultTest='suite')
deleted file mode 100644
--- a/bitten/tests/slave.py
+++ /dev/null
@@ -1,42 +0,0 @@
-# -*- coding: utf-8 -*-
-#
-# Copyright (C) 2005-2007 Christopher Lenz <cmlenz@gmx.de>
-# Copyright (C) 2007 Edgewall Software
-# All rights reserved.
-#
-# This software is licensed as described in the file COPYING, which
-# you should have received as part of this distribution. The terms
-# are also available at http://bitten.edgewall.org/wiki/License.
-
-import os
-import shutil
-import tempfile
-import unittest
-
-from bitten.slave import BuildSlave, ExitSlave
-
-class BuildSlaveTestCase(unittest.TestCase):
-
-    def setUp(self):
-        self.work_dir = tempfile.mkdtemp(prefix='bitten_test')
-        self.slave = BuildSlave([], work_dir=self.work_dir)
-
-    def tearDown(self):
-        shutil.rmtree(self.work_dir)
-
-    def _create_file(self, *path):
-        filename = os.path.join(self.work_dir, *path)
-        fd = file(filename, 'w')
-        fd.close()
-        return filename
-
-    def test_quit_raises(self):
-        self.assertRaises(ExitSlave, self.slave.quit)
-
-def suite():
-    suite = unittest.TestSuite()
-    suite.addTest(unittest.makeSuite(BuildSlaveTestCase, 'test'))
-    return suite
-
-if __name__ == '__main__':
-    unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software