summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorTarek Ziadé <ziade.tarek@gmail.com>2009-09-21 12:19:07 (GMT)
committerTarek Ziadé <ziade.tarek@gmail.com>2009-09-21 12:19:07 (GMT)
commit6d2db3784aff7f85aa4b814e7312e599b124498e (patch)
treeb122a9f20ca1ac4e6bd4d9da4f9d825678b1d1d7 /Lib
parent1d18b5b92919493526ed021d83479777f0bb6700 (diff)
downloadcpython-6d2db3784aff7f85aa4b814e7312e599b124498e.zip
cpython-6d2db3784aff7f85aa4b814e7312e599b124498e.tar.gz
cpython-6d2db3784aff7f85aa4b814e7312e599b124498e.tar.bz2
improved distutils test coverage: now the DEBUG mode is covered too (will help fix the issue #6954 in py3k branch)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/distutils/tests/test_ccompiler.py24
-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.py19
-rw-r--r--Lib/distutils/tests/test_install.py14
5 files changed, 93 insertions, 2 deletions
diff --git a/Lib/distutils/tests/test_ccompiler.py b/Lib/distutils/tests/test_ccompiler.py
index 58c8c5d..2c219b7 100644
--- a/Lib/distutils/tests/test_ccompiler.py
+++ b/Lib/distutils/tests/test_ccompiler.py
@@ -1,8 +1,10 @@
"""Tests for distutils.ccompiler."""
import os
import unittest
+from test.test_support import captured_stdout
-from distutils.ccompiler import gen_lib_options
+from distutils.ccompiler import gen_lib_options, CCompiler
+from distutils import debug
class FakeCompiler(object):
def library_dir_option(self, dir):
@@ -30,6 +32,26 @@ class CCompilerTestCase(unittest.TestCase):
'-lname2']
self.assertEquals(opts, wanted)
+ def test_debug_print(self):
+
+ class MyCCompiler(CCompiler):
+ executables = {}
+
+ compiler = MyCCompiler()
+ with captured_stdout() as stdout:
+ compiler.debug_print('xxx')
+ stdout.seek(0)
+ self.assertEquals(stdout.read(), '')
+
+ debug.DEBUG = True
+ try:
+ with captured_stdout() as stdout:
+ compiler.debug_print('xxx')
+ stdout.seek(0)
+ self.assertEquals(stdout.read(), 'xxx\n')
+ finally:
+ debug.DEBUG = False
+
def test_suite():
return unittest.makeSuite(CCompilerTestCase)
diff --git a/Lib/distutils/tests/test_cmd.py b/Lib/distutils/tests/test_cmd.py
index d6438b5..2174efb 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.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 e481e8d..3c26fdd 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.test_support
+from test.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.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 cf64c74..0cbb48b 100644
--- a/Lib/distutils/tests/test_filelist.py
+++ b/Lib/distutils/tests/test_filelist.py
@@ -1,7 +1,10 @@
"""Tests for distutils.filelist."""
from os.path import join
import unittest
+from test.test_support import captured_stdout
+
from distutils.filelist import glob_to_re, FileList
+from distutils import debug
MANIFEST_IN = """\
include ok
@@ -59,6 +62,22 @@ class FileListTestCase(unittest.TestCase):
self.assertEquals(file_list.files, wanted)
+ 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..d2b8c8e 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.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)