summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarek Ziadé <ziade.tarek@gmail.com>2009-09-21 13:10:05 (GMT)
committerTarek Ziadé <ziade.tarek@gmail.com>2009-09-21 13:10:05 (GMT)
commit83496698249fbcfd0efb875d882a6e883db4bf6d (patch)
treeb7c466f0156cd565341483fca2fcec347c487ea0
parent14214261c418bff713dd67fcf5cd6db69fa7e77e (diff)
downloadcpython-83496698249fbcfd0efb875d882a6e883db4bf6d.zip
cpython-83496698249fbcfd0efb875d882a6e883db4bf6d.tar.gz
cpython-83496698249fbcfd0efb875d882a6e883db4bf6d.tar.bz2
Merged revisions 74990 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r74990 | tarek.ziade | 2009-09-21 15:01:54 +0200 (Mon, 21 Sep 2009) | 9 lines Merged revisions 74988 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r74988 | tarek.ziade | 2009-09-21 14:19:07 +0200 (Mon, 21 Sep 2009) | 1 line improved distutils test coverage: now the DEBUG mode is covered too (will help fix the issue #6954 in py3k branch) ........ ................
-rw-r--r--Lib/distutils/cmd.py2
-rw-r--r--Lib/distutils/fancy_getopt.py6
-rw-r--r--Lib/distutils/tests/test_cmd.py18
-rw-r--r--Lib/distutils/tests/test_core.py20
-rw-r--r--Lib/distutils/tests/test_filelist.py21
-rw-r--r--Lib/distutils/tests/test_install.py14
6 files changed, 75 insertions, 6 deletions
diff --git a/Lib/distutils/cmd.py b/Lib/distutils/cmd.py
index aff7d68..ae4efc7 100644
--- a/Lib/distutils/cmd.py
+++ b/Lib/distutils/cmd.py
@@ -157,7 +157,7 @@ class Command:
self.announce(indent + header, level=log.INFO)
indent = indent + " "
for (option, _, _) in self.user_options:
- option = longopt_xlate(option)
+ option = option.translate(longopt_xlate)
if option[-1] == "=":
option = option[:-1]
value = getattr(self, option)
diff --git a/Lib/distutils/fancy_getopt.py b/Lib/distutils/fancy_getopt.py
index 72441fb..879d4d2 100644
--- a/Lib/distutils/fancy_getopt.py
+++ b/Lib/distutils/fancy_getopt.py
@@ -26,7 +26,7 @@ neg_alias_re = re.compile("^(%s)=!(%s)$" % (longopt_pat, longopt_pat))
# This is used to translate long options to legitimate Python identifiers
# (for use as attributes of some object).
-longopt_xlate = lambda s: s.replace('-', '_')
+longopt_xlate = str.maketrans('-', '_')
class FancyGetopt:
"""Wrapper around the standard 'getopt()' module that provides some
@@ -107,7 +107,7 @@ class FancyGetopt:
"""Translate long option name 'long_option' to the form it
has as an attribute of some object: ie., translate hyphens
to underscores."""
- return longopt_xlate(long_option)
+ return long_option.translate(longopt_xlate)
def _check_alias_dict(self, aliases, what):
assert isinstance(aliases, dict)
@@ -432,7 +432,7 @@ def translate_longopt(opt):
"""Convert a long option name to a valid Python identifier by
changing "-" to "_".
"""
- return longopt_xlate(opt)
+ return opt.translate(longopt_xlate)
class OptionDummy:
diff --git a/Lib/distutils/tests/test_cmd.py b/Lib/distutils/tests/test_cmd.py
index d6438b5..55ae421 100644
--- a/Lib/distutils/tests/test_cmd.py
+++ b/Lib/distutils/tests/test_cmd.py
@@ -1,10 +1,12 @@
"""Tests for distutils.cmd."""
import unittest
import os
+from test.support import captured_stdout
from distutils.cmd import Command
from distutils.dist import Distribution
from distutils.errors import DistutilsOptionError
+from distutils import debug
class MyCmd(Command):
def initialize_options(self):
@@ -102,6 +104,22 @@ class CommandTestCase(unittest.TestCase):
cmd.option2 = 'xxx'
self.assertRaises(DistutilsOptionError, cmd.ensure_dirname, 'option2')
+ def test_debug_print(self):
+ cmd = self.cmd
+ with captured_stdout() as stdout:
+ cmd.debug_print('xxx')
+ stdout.seek(0)
+ self.assertEquals(stdout.read(), '')
+
+ debug.DEBUG = True
+ try:
+ with captured_stdout() as stdout:
+ cmd.debug_print('xxx')
+ stdout.seek(0)
+ self.assertEquals(stdout.read(), 'xxx\n')
+ finally:
+ debug.DEBUG = False
+
def test_suite():
return unittest.makeSuite(CommandTestCase)
diff --git a/Lib/distutils/tests/test_core.py b/Lib/distutils/tests/test_core.py
index 7f021dc..b5f391f 100644
--- a/Lib/distutils/tests/test_core.py
+++ b/Lib/distutils/tests/test_core.py
@@ -6,6 +6,7 @@ import os
import shutil
import sys
import test.support
+from test.support import captured_stdout
import unittest
@@ -33,10 +34,12 @@ class CoreTestCase(unittest.TestCase):
def setUp(self):
self.old_stdout = sys.stdout
self.cleanup_testfn()
+ self.old_argv = sys.argv[:]
def tearDown(self):
sys.stdout = self.old_stdout
self.cleanup_testfn()
+ sys.argv = self.old_argv[:]
def cleanup_testfn(self):
path = test.support.TESTFN
@@ -73,6 +76,23 @@ class CoreTestCase(unittest.TestCase):
output = output[:-1]
self.assertEqual(cwd, output)
+ def test_debug_mode(self):
+ # this covers the code called when DEBUG is set
+ sys.argv = ['setup.py', '--name']
+ with captured_stdout() as stdout:
+ distutils.core.setup(name='bar')
+ stdout.seek(0)
+ self.assertEquals(stdout.read(), 'bar\n')
+
+ distutils.core.DEBUG = True
+ try:
+ with captured_stdout() as stdout:
+ distutils.core.setup(name='bar')
+ finally:
+ distutils.core.DEBUG = False
+ stdout.seek(0)
+ wanted = "options (after parsing config files):\n"
+ self.assertEquals(stdout.readlines()[0], wanted)
def test_suite():
return unittest.makeSuite(CoreTestCase)
diff --git a/Lib/distutils/tests/test_filelist.py b/Lib/distutils/tests/test_filelist.py
index 86db557..b9db8f6 100644
--- a/Lib/distutils/tests/test_filelist.py
+++ b/Lib/distutils/tests/test_filelist.py
@@ -1,6 +1,9 @@
"""Tests for distutils.filelist."""
import unittest
-from distutils.filelist import glob_to_re
+
+from distutils.filelist import glob_to_re, FileList
+from test.support import captured_stdout
+from distutils import debug
class FileListTestCase(unittest.TestCase):
@@ -16,6 +19,22 @@ class FileListTestCase(unittest.TestCase):
self.assertEquals(glob_to_re('foo????'), r'foo[^/][^/][^/][^/]$')
self.assertEquals(glob_to_re(r'foo\\??'), r'foo\\\\[^/][^/]$')
+ def test_debug_print(self):
+ file_list = FileList()
+ with captured_stdout() as stdout:
+ file_list.debug_print('xxx')
+ stdout.seek(0)
+ self.assertEquals(stdout.read(), '')
+
+ debug.DEBUG = True
+ try:
+ with captured_stdout() as stdout:
+ file_list.debug_print('xxx')
+ stdout.seek(0)
+ self.assertEquals(stdout.read(), 'xxx\n')
+ finally:
+ debug.DEBUG = False
+
def test_suite():
return unittest.makeSuite(FileListTestCase)
diff --git a/Lib/distutils/tests/test_install.py b/Lib/distutils/tests/test_install.py
index d0ad5ce..2087a0e 100644
--- a/Lib/distutils/tests/test_install.py
+++ b/Lib/distutils/tests/test_install.py
@@ -6,6 +6,8 @@ import sys
import unittest
import site
+from test.support import captured_stdout
+
from distutils.command.install import install
from distutils.command import install as install_module
from distutils.command.install import INSTALL_SCHEMES
@@ -14,7 +16,6 @@ from distutils.errors import DistutilsOptionError
from distutils.tests import support
-
class InstallTestCase(support.TempdirManager,
support.LoggingSilencer,
unittest.TestCase):
@@ -183,6 +184,17 @@ class InstallTestCase(support.TempdirManager,
with open(cmd.record) as f:
self.assertEquals(len(f.readlines()), 1)
+ def test_debug_mode(self):
+ # this covers the code called when DEBUG is set
+ old_logs_len = len(self.logs)
+ install_module.DEBUG = True
+ try:
+ with captured_stdout() as stdout:
+ self.test_record()
+ finally:
+ install_module.DEBUG = False
+ self.assertTrue(len(self.logs) > old_logs_len)
+
def test_suite():
return unittest.makeSuite(InstallTestCase)