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)
# 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
"""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)
"""Convert a long option name to a valid Python identifier by
changing "-" to "_".
"""
- return longopt_xlate(opt)
+ return opt.translate(longopt_xlate)
class OptionDummy:
"""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):
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)
import shutil
import sys
import test.support
+from test.support import captured_stdout
import unittest
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
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)
"""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):
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)
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
from distutils.tests import support
-
class InstallTestCase(support.TempdirManager,
support.LoggingSilencer,
unittest.TestCase):
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)