[Python-checkins] distutils2: Remove spurious output with runtests.py (+ modernize test_config)

tarek.ziade python-checkins at python.org
Sat Oct 2 00:52:19 CEST 2010


tarek.ziade pushed efe244b78376 to distutils2:

http://hg.python.org/distutils2/rev/efe244b78376
changeset:   696:efe244b78376
user:        ?ric Araujo <merwok at netwok.org>
date:        Tue Sep 28 11:27:08 2010 +0200
summary:     Remove spurious output with runtests.py (+ modernize test_config)
files:       distutils2/tests/test_config.py, distutils2/tests/test_register.py, distutils2/tests/test_test.py

diff --git a/distutils2/tests/test_config.py b/distutils2/tests/test_config.py
--- a/distutils2/tests/test_config.py
+++ b/distutils2/tests/test_config.py
@@ -1,8 +1,9 @@
 """Tests for distutils.config."""
+import os
 import sys
-import os
-import copy
+from StringIO import StringIO
 
+from distutils2.core import setup
 from distutils2.tests import support, run_unittest
 from distutils2.tests.support import unittest
 
@@ -17,26 +18,23 @@
 class ConfigTestCase(support.TempdirManager,
                      unittest.TestCase):
 
+    def setUp(self):
+        super(ConfigTestCase, self).setUp()
+        self.addCleanup(setattr, sys, 'argv', sys.argv)
+        self.addCleanup(setattr, sys, 'stdout', sys.stdout)
+        self.addCleanup(os.chdir, os.getcwd())
+
     def test_config(self):
         tempdir = self.mkdtemp()
-        setup_cfg = os.path.join(tempdir, 'setup.cfg')
-        f = open(setup_cfg, 'w')
-        try:
-            f.write(SETUP_CFG)
-        finally:
-            f.close()
+        os.chdir(tempdir)
+        self.write_file('setup.cfg', SETUP_CFG)
 
-        # trying to load the metadata now
-        old_args = copy.copy(sys.argv)
+        # try to load the metadata now
+        sys.stdout = StringIO()
         sys.argv[:] = ['setup.py', '--version']
-        old_wd = os.getcwd()
-        os.chdir(tempdir)
-        try:
-            from distutils2.core import setup
-            dist = setup()
-        finally:
-            os.chdir(old_wd)
-            sys.argv[:] = old_args
+        dist = setup()
+        # sanity check
+        self.assertEqual(sys.stdout.getvalue(), '1.0' + os.linesep)
 
         # check what was done
         self.assertEqual(dist.metadata['Author'], 'tarek')
diff --git a/distutils2/tests/test_register.py b/distutils2/tests/test_register.py
--- a/distutils2/tests/test_register.py
+++ b/distutils2/tests/test_register.py
@@ -68,7 +68,7 @@
         return 'xxx'
 
 class RegisterTestCase(support.TempdirManager, support.EnvironGuard,
-                       unittest.TestCase):
+                       support.LoggingCatcher, unittest.TestCase):
 
     def setUp(self):
         super(RegisterTestCase, self).setUp()
diff --git a/distutils2/tests/test_test.py b/distutils2/tests/test_test.py
--- a/distutils2/tests/test_test.py
+++ b/distutils2/tests/test_test.py
@@ -9,7 +9,7 @@
 from operator import getitem, setitem, delitem
 from StringIO import StringIO
 from distutils2.core import Command
-from distutils2.tests.support import unittest, TempdirManager
+from distutils2.tests.support import unittest, TempdirManager, LoggingCatcher
 from distutils2.command.test import test
 from distutils2.dist import Distribution
 
@@ -29,6 +29,7 @@
 here = os.path.dirname(os.path.abspath(__file__))
 
 class TestTest(TempdirManager,
+               LoggingCatcher,
                unittest.TestCase):
 
     def setUp(self):
@@ -73,7 +74,7 @@
 
         orig_has_attr = _hasattr(obj, attr)
         if orig_has_attr:
-            orig_val = _getattr(obj, attr) 
+            orig_val = _getattr(obj, attr)
 
         if delete is False:
             _setattr(obj, attr, new_val)

--
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list