# HG changeset patch # User osimons # Date 1260457056 0 # Node ID df8d2cd7e50e31b87aaea694b45133d87d7da1e6 # Parent fcab3b625fb166bf171e595beb1c3035191e25fd 0.6dev: Merge [803] from trunk. diff --git a/MANIFEST-SLAVE.in b/MANIFEST-SLAVE.in --- a/MANIFEST-SLAVE.in +++ b/MANIFEST-SLAVE.in @@ -18,6 +18,6 @@ include bitten/build/tests/*.py include bitten/recipe.py include bitten/slave.py -include bitten/slave_tests/*.py +include bitten/tests_slave/*.py include bitten/util/*.py include bitten/util/tests/*.py diff --git a/bitten/slave_tests/__init__.py b/bitten/slave_tests/__init__.py deleted file mode 100644 --- a/bitten/slave_tests/__init__.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2005-2007 Christopher Lenz -# 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') diff --git a/bitten/slave_tests/recipe.py b/bitten/slave_tests/recipe.py deleted file mode 100644 --- a/bitten/slave_tests/recipe.py +++ /dev/null @@ -1,185 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2005-2007 Christopher Lenz -# 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'), - os.path.realpath(ctxt.vars['basedir'])) - if os.name == 'nt': - # Make sure paths are double-escaped - self.failUnless('\\\\' in ctxt.vars['basedir']) - - def test_run_wrong_arg(self): - ctxt = Context(self.basedir) - try: - ctxt.run(1, 'http://bitten.edgewall.org/tools/sh', 'exec', {'foo':'bar'}) - self.fail("InvalidRecipeError expected") - except InvalidRecipeError, e: - self.failUnless("Unsupported argument 'foo'" in str(e)) - - def test_attach_file_non_existing(self): - # Verify that it raises error and that it gets logged - ctxt = Context(self.basedir, Configuration()) - ctxt.attach(file_='nonexisting.txt', - description='build build') - - self.assertEquals(1, len(ctxt.output)) - self.assertEquals(Recipe.ERROR, ctxt.output[0][0]) - self.assertEquals('Failed to read file nonexisting.txt as attachment', - ctxt.output[0][3]) - - def test_attach_file_config(self): - # Verify output from attaching a file to a config - ctxt = Context(self.basedir, Configuration()) - test_file = open(os.path.join(self.basedir, 'config.txt'), 'w') - test_file.write('hello config') - test_file.close() - - ctxt.attach(file_='config.txt', description='config config', - resource='config') - self.assertEquals(1, len(ctxt.output)) - self.assertEquals(Recipe.ATTACH, ctxt.output[0][0]) - attach_xml = ctxt.output[0][3] - self.assertEquals('' - 'aGVsbG8gY29uZmln\n' - '', str(attach_xml)) - - def test_attach_file_build(self): - # Verify output from attaching a file to a build - ctxt = Context(self.basedir, Configuration()) - test_file = open(os.path.join(self.basedir, 'build.txt'), 'w') - test_file.write('hello build') - test_file.close() - - ctxt.attach(file_='build.txt', description='build build') - self.assertEquals(1, len(ctxt.output)) - self.assertEquals(Recipe.ATTACH, ctxt.output[0][0]) - attach_xml = ctxt.output[0][3] - self.assertEquals('' - 'aGVsbG8gYnVpbGQ=\n' - '', str(attach_xml)) - -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('') - 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('' - ' ' - '') - 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('') - recipe = Recipe(xml, basedir=self.basedir) - self.assertRaises(InvalidRecipeError, recipe.validate) - - def test_validate_no_steps(self): - xml = xmlio.parse('') - recipe = Recipe(xml, basedir=self.basedir) - self.assertRaises(InvalidRecipeError, recipe.validate) - - def test_validate_child_not_step(self): - xml = xmlio.parse('') - recipe = Recipe(xml, basedir=self.basedir) - self.assertRaises(InvalidRecipeError, recipe.validate) - - def test_validate_child_not_step(self): - xml = xmlio.parse('') - recipe = Recipe(xml, basedir=self.basedir) - self.assertRaises(InvalidRecipeError, recipe.validate) - - def test_validate_step_without_id(self): - xml = xmlio.parse('') - recipe = Recipe(xml, basedir=self.basedir) - self.assertRaises(InvalidRecipeError, recipe.validate) - - def test_validate_step_with_empty_id(self): - xml = xmlio.parse('') - recipe = Recipe(xml, basedir=self.basedir) - self.assertRaises(InvalidRecipeError, recipe.validate) - - def test_validate_step_without_commands(self): - xml = xmlio.parse('') - recipe = Recipe(xml, basedir=self.basedir) - self.assertRaises(InvalidRecipeError, recipe.validate) - - def test_validate_step_with_command_children(self): - xml = xmlio.parse('' - '' - '') - recipe = Recipe(xml, basedir=self.basedir) - self.assertRaises(InvalidRecipeError, recipe.validate) - - def test_validate_step_with_duplicate_id(self): - xml = xmlio.parse('' - '' - '' - '') - recipe = Recipe(xml, basedir=self.basedir) - self.assertRaises(InvalidRecipeError, recipe.validate) - - def test_validate_successful(self): - xml = xmlio.parse('' - '' - '' - '') - 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') diff --git a/bitten/slave_tests/slave.py b/bitten/slave_tests/slave.py deleted file mode 100644 --- a/bitten/slave_tests/slave.py +++ /dev/null @@ -1,42 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2005-2007 Christopher Lenz -# 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') diff --git a/bitten/tests/__init__.py b/bitten/tests/__init__.py --- a/bitten/tests/__init__.py +++ b/bitten/tests/__init__.py @@ -33,8 +33,8 @@ suite.addTest(master_suite()) except ImportError: print "\nTrac not installed -- Skipping master tests\n" - import bitten.slave_tests - suite.addTest(bitten.slave_tests.suite()) + import bitten.tests_slave + suite.addTest(bitten.tests_slave.suite()) return suite if __name__ == '__main__': diff --git a/bitten/tests_slave/__init__.py b/bitten/tests_slave/__init__.py new file mode 100644 --- /dev/null +++ b/bitten/tests_slave/__init__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2005-2007 Christopher Lenz +# 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.tests_slave 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') diff --git a/bitten/tests_slave/recipe.py b/bitten/tests_slave/recipe.py new file mode 100644 --- /dev/null +++ b/bitten/tests_slave/recipe.py @@ -0,0 +1,185 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2005-2007 Christopher Lenz +# 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'), + os.path.realpath(ctxt.vars['basedir'])) + if os.name == 'nt': + # Make sure paths are double-escaped + self.failUnless('\\\\' in ctxt.vars['basedir']) + + def test_run_wrong_arg(self): + ctxt = Context(self.basedir) + try: + ctxt.run(1, 'http://bitten.edgewall.org/tools/sh', 'exec', {'foo':'bar'}) + self.fail("InvalidRecipeError expected") + except InvalidRecipeError, e: + self.failUnless("Unsupported argument 'foo'" in str(e)) + + def test_attach_file_non_existing(self): + # Verify that it raises error and that it gets logged + ctxt = Context(self.basedir, Configuration()) + ctxt.attach(file_='nonexisting.txt', + description='build build') + + self.assertEquals(1, len(ctxt.output)) + self.assertEquals(Recipe.ERROR, ctxt.output[0][0]) + self.assertEquals('Failed to read file nonexisting.txt as attachment', + ctxt.output[0][3]) + + def test_attach_file_config(self): + # Verify output from attaching a file to a config + ctxt = Context(self.basedir, Configuration()) + test_file = open(os.path.join(self.basedir, 'config.txt'), 'w') + test_file.write('hello config') + test_file.close() + + ctxt.attach(file_='config.txt', description='config config', + resource='config') + self.assertEquals(1, len(ctxt.output)) + self.assertEquals(Recipe.ATTACH, ctxt.output[0][0]) + attach_xml = ctxt.output[0][3] + self.assertEquals('' + 'aGVsbG8gY29uZmln\n' + '', str(attach_xml)) + + def test_attach_file_build(self): + # Verify output from attaching a file to a build + ctxt = Context(self.basedir, Configuration()) + test_file = open(os.path.join(self.basedir, 'build.txt'), 'w') + test_file.write('hello build') + test_file.close() + + ctxt.attach(file_='build.txt', description='build build') + self.assertEquals(1, len(ctxt.output)) + self.assertEquals(Recipe.ATTACH, ctxt.output[0][0]) + attach_xml = ctxt.output[0][3] + self.assertEquals('' + 'aGVsbG8gYnVpbGQ=\n' + '', str(attach_xml)) + +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('') + 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('' + ' ' + '') + 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('') + recipe = Recipe(xml, basedir=self.basedir) + self.assertRaises(InvalidRecipeError, recipe.validate) + + def test_validate_no_steps(self): + xml = xmlio.parse('') + recipe = Recipe(xml, basedir=self.basedir) + self.assertRaises(InvalidRecipeError, recipe.validate) + + def test_validate_child_not_step(self): + xml = xmlio.parse('') + recipe = Recipe(xml, basedir=self.basedir) + self.assertRaises(InvalidRecipeError, recipe.validate) + + def test_validate_child_not_step(self): + xml = xmlio.parse('') + recipe = Recipe(xml, basedir=self.basedir) + self.assertRaises(InvalidRecipeError, recipe.validate) + + def test_validate_step_without_id(self): + xml = xmlio.parse('') + recipe = Recipe(xml, basedir=self.basedir) + self.assertRaises(InvalidRecipeError, recipe.validate) + + def test_validate_step_with_empty_id(self): + xml = xmlio.parse('') + recipe = Recipe(xml, basedir=self.basedir) + self.assertRaises(InvalidRecipeError, recipe.validate) + + def test_validate_step_without_commands(self): + xml = xmlio.parse('') + recipe = Recipe(xml, basedir=self.basedir) + self.assertRaises(InvalidRecipeError, recipe.validate) + + def test_validate_step_with_command_children(self): + xml = xmlio.parse('' + '' + '') + recipe = Recipe(xml, basedir=self.basedir) + self.assertRaises(InvalidRecipeError, recipe.validate) + + def test_validate_step_with_duplicate_id(self): + xml = xmlio.parse('' + '' + '' + '') + recipe = Recipe(xml, basedir=self.basedir) + self.assertRaises(InvalidRecipeError, recipe.validate) + + def test_validate_successful(self): + xml = xmlio.parse('' + '' + '' + '') + 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') diff --git a/bitten/tests_slave/slave.py b/bitten/tests_slave/slave.py new file mode 100644 --- /dev/null +++ b/bitten/tests_slave/slave.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2005-2007 Christopher Lenz +# 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') diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -141,7 +141,7 @@ "bitten.util.testrunner", "bitten.util.xmlio", ], - test_suite = 'bitten.slave_tests.suite', + test_suite = 'bitten.tests_slave.suite', tests_require = [ 'figleaf', ],