[Python-checkins] distutils2: basic functional test for the test command
tarek.ziade
python-checkins at python.org
Sun Sep 19 10:20:20 CEST 2010
tarek.ziade pushed d476e0ad4e15 to distutils2:
http://hg.python.org/distutils2/rev/d476e0ad4e15
changeset: 595:d476e0ad4e15
user: Konrad Delong <konryd at gmail.com>
date: Tue Jul 27 14:31:15 2010 +0200
summary: basic functional test for the test command
files: src/distutils2/command/test.py, src/distutils2/tests/test_test.py
diff --git a/src/distutils2/command/test.py b/src/distutils2/command/test.py
new file mode 100644
--- /dev/null
+++ b/src/distutils2/command/test.py
@@ -0,0 +1,30 @@
+import os, sys
+from distutils2.core import Command
+import unittest
+
+class test(Command):
+
+ description = "" # TODO
+ user_options = [
+ ('test-suite=','s',
+ "Test suite to run (e.g. 'some_module.test_suite')"),
+ ]
+
+ def initialize_options(self):
+ self.test_suite = None
+
+ def finalize_options(self):
+ pass
+
+ def distpath(self):
+ self.run_command('build')
+ build_cmd = self.get_finalized_command("build")
+ return os.path.join(build_cmd.build_base, "lib")
+
+ def run(self):
+ orig_path = sys.path[:]
+ try:
+ sys.path.insert(0, self.distpath())
+ unittest.main(module=self.test_suite, argv=sys.argv[:1])
+ finally:
+ sys.path[:] = orig_path
diff --git a/src/distutils2/tests/test_test.py b/src/distutils2/tests/test_test.py
new file mode 100644
--- /dev/null
+++ b/src/distutils2/tests/test_test.py
@@ -0,0 +1,73 @@
+import os, sys
+from copy import copy
+from os.path import join
+from StringIO import StringIO
+from distutils2.tests.support import unittest, TempdirManager
+from distutils2.command.test import test
+import subprocess
+
+TEST_BODY = '''\
+import unittest
+class SomeTest(unittest.TestCase):
+ def test_blah(self):
+ self.fail("horribly")
+testSuite = unittest.makeSuite(SomeTest)
+'''
+
+SETUP_PY = '''\
+from distutils2.core import setup
+setup(name='somedist',
+ version='0.1',
+ py_modules=['myowntestmodule', 'somemod'],
+)
+'''
+
+EXPECTED_OUTPUT = '''\
+FAIL: test_blah (myowntestmodule.SomeTest)
+----------------------------------------------------------------------
+Traceback (most recent call last):
+ File "build/lib/myowntestmodule.py", line 4, in test_blah
+ self.fail("horribly")
+AssertionError: horribly
+'''
+
+class TestTest(TempdirManager, unittest.TestCase):
+
+ def setUp(self):
+ super(TestTest, self).setUp()
+ self.pkg_dir = self.prepare_dist()
+ self.cwd = os.getcwd()
+ os.chdir(self.pkg_dir)
+ self.orig_environ = copy(os.environ)
+ distutils2path = join(__file__, '..', '..', '..')
+ distutils2path = os.path.abspath(distutils2path)
+ self.old_pythonpath = os.environ.get('PYTHONPATH', '')
+ os.environ['PYTHONPATH'] = distutils2path + ":" + self.old_pythonpath
+
+ def tearDown(self):
+ super(TestTest, self).tearDown()
+ os.chdir(self.cwd)
+ os.environ['PYTHONPATH'] = self.old_pythonpath
+
+ def prepare_dist(self):
+ # prepare distribution
+ pkg_dir = self.mkdtemp()
+ self.write_file(join(pkg_dir, "setup.py"), SETUP_PY)
+ self.write_file(join(pkg_dir, "somemod.py"), "")
+ self.write_file(join(pkg_dir, "myowntestmodule.py"), TEST_BODY)
+ return pkg_dir
+
+ def test_runs_simple_tests(self):
+ command = [sys.executable, "setup.py", "test"]
+ command += ['--test-suite', 'myowntestmodule']
+ test_proc = subprocess.Popen(command, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
+ _, errors = test_proc.communicate()
+
+ # ensure right output
+ self.assertIn(EXPECTED_OUTPUT, errors)
+
+ def _test_setup_py_accepts_options(self):
+ pass
+
+ def _test_options_preparation(self):
+ pass
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list