diff options
| author | Tarek Ziade <tarek@ziade.org> | 2010-11-05 02:29:52 +0100 |
|---|---|---|
| committer | Tarek Ziade <tarek@ziade.org> | 2010-11-05 02:29:52 +0100 |
| commit | fc473b39e9789ce7197b60314eb9cef2621d0852 (patch) | |
| tree | 3e30c6ab4a04c35aa928d23faf55d45172a4fe71 /distutils2/tests | |
| parent | fb36122e28fcda72c672ca4cddcf04b778ce6b8b (diff) | |
| download | disutils2-fc473b39e9789ce7197b60314eb9cef2621d0852.tar.gz | |
finished the removal of the log module
Diffstat (limited to 'distutils2/tests')
| -rw-r--r-- | distutils2/tests/support.py | 23 | ||||
| -rw-r--r-- | distutils2/tests/test_Mixin2to3.py | 3 | ||||
| -rw-r--r-- | distutils2/tests/test_command_config.py | 21 | ||||
| -rw-r--r-- | distutils2/tests/test_command_sdist.py | 6 | ||||
| -rw-r--r-- | distutils2/tests/test_command_upload_docs.py | 2 | ||||
| -rw-r--r-- | distutils2/tests/test_depgraph.py | 1 | ||||
| -rw-r--r-- | distutils2/tests/test_metadata.py | 45 |
7 files changed, 30 insertions, 71 deletions
diff --git a/distutils2/tests/support.py b/distutils2/tests/support.py index fe343dc..c33bf32 100644 --- a/distutils2/tests/support.py +++ b/distutils2/tests/support.py @@ -28,10 +28,10 @@ import shutil import tempfile import warnings from copy import deepcopy +import logging -from distutils2 import log +from distutils2 import logger from distutils2.dist import Distribution -from distutils2.log import DEBUG, INFO, WARN, ERROR, FATAL from distutils2.tests import unittest __all__ = ['LoggingCatcher', 'WarningsCatcher', 'TempdirManager', @@ -49,23 +49,18 @@ class LoggingCatcher(object): def setUp(self): super(LoggingCatcher, self).setUp() - self.threshold = log.set_threshold(FATAL) - # when log is replaced by logging we won't need - # such monkey-patching anymore - self._old_log = log.Log._log - log.Log._log = self._log + self.old_log = logger._log + logger._log = self._log + logger.setLevel(logging.INFO) self.logs = [] + def _log(self, *args, **kw): + self.logs.append(args) + def tearDown(self): - log.set_threshold(self.threshold) - log.Log._log = self._old_log + logger._log = self.old_log super(LoggingCatcher, self).tearDown() - def _log(self, level, msg, args): - if level not in (DEBUG, INFO, WARN, ERROR, FATAL): - raise ValueError('%s wrong log level' % level) - self.logs.append((level, msg, args)) - def get_logs(self, *levels): """Return a list of caught messages with level in `levels`. diff --git a/distutils2/tests/test_Mixin2to3.py b/distutils2/tests/test_Mixin2to3.py index 2ffd248..c6661a6 100644 --- a/distutils2/tests/test_Mixin2to3.py +++ b/distutils2/tests/test_Mixin2to3.py @@ -7,7 +7,8 @@ from distutils2.tests import unittest, support from distutils2.compat import Mixin2to3 -class Mixin2to3TestCase(support.TempdirManager, unittest.TestCase): +class Mixin2to3TestCase(support.TempdirManager, support.WarningsCatcher, + unittest.TestCase): @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher') def test_convert_code_only(self): diff --git a/distutils2/tests/test_command_config.py b/distutils2/tests/test_command_config.py index cf4bbe1..ec519a6 100644 --- a/distutils2/tests/test_command_config.py +++ b/distutils2/tests/test_command_config.py @@ -4,26 +4,11 @@ import sys from distutils2.command.config import dump_file, config from distutils2.tests import unittest, support -from distutils2 import log class ConfigTestCase(support.LoggingCatcher, support.TempdirManager, unittest.TestCase): - def _info(self, msg, *args): - for line in msg.splitlines(): - self._logs.append(line) - - def setUp(self): - super(ConfigTestCase, self).setUp() - self._logs = [] - self.old_log = log.info - log.info = self._info - - def tearDown(self): - log.info = self.old_log - super(ConfigTestCase, self).tearDown() - def test_dump_file(self): this_file = os.path.splitext(__file__)[0] + '.py' f = open(this_file) @@ -33,7 +18,11 @@ class ConfigTestCase(support.LoggingCatcher, f.close() dump_file(this_file, 'I am the header') - self.assertEqual(len(self._logs), numlines+1) + logs = [] + for log in self.logs: + log = log[1] + logs.extend([log for log in log.split('\n')]) + self.assertEqual(len(logs), numlines+2) def test_search_cpp(self): if sys.platform == 'win32': diff --git a/distutils2/tests/test_command_sdist.py b/distutils2/tests/test_command_sdist.py index eedbc02..ae37cf5 100644 --- a/distutils2/tests/test_command_sdist.py +++ b/distutils2/tests/test_command_sdist.py @@ -3,6 +3,7 @@ import os import shutil import zipfile import tarfile +import logging # zlib is not used here, but if it's not available # the tests that use zipfile may fail @@ -30,7 +31,6 @@ from distutils2.tests import unittest from distutils2.errors import DistutilsExecError, DistutilsOptionError from distutils2.util import find_executable from distutils2.tests import support -from distutils2.log import WARN try: from shutil import get_archive_formats except ImportError: @@ -247,7 +247,7 @@ class SDistTestCase(support.TempdirManager, support.LoggingCatcher, # with the `check` subcommand cmd.ensure_finalized() cmd.run() - warnings = self.get_logs(WARN) + warnings = self.get_logs(logging.WARN) self.assertEqual(len(warnings), 1) # trying with a complete set of metadata @@ -256,7 +256,7 @@ class SDistTestCase(support.TempdirManager, support.LoggingCatcher, cmd.ensure_finalized() cmd.metadata_check = 0 cmd.run() - warnings = self.get_logs(WARN) + warnings = self.get_logs(logging.WARN) # removing manifest generated warnings warnings = [warn for warn in warnings if not warn.endswith('-- skipping')] diff --git a/distutils2/tests/test_command_upload_docs.py b/distutils2/tests/test_command_upload_docs.py index 8135e24..4b1dc82 100644 --- a/distutils2/tests/test_command_upload_docs.py +++ b/distutils2/tests/test_command_upload_docs.py @@ -176,7 +176,7 @@ class UploadDocsTestCase(support.TempdirManager, support.EnvironGuard, self.pypi.default_response_status = '301 Moved Permanently' self.pypi.default_response_headers.append(("Location", "brand_new_location")) self.cmd.run() - message, _ = calls[-1] + message = calls[-1][0] self.assertIn('brand_new_location', message) def test_reads_pypirc_data(self): diff --git a/distutils2/tests/test_depgraph.py b/distutils2/tests/test_depgraph.py index abd0836..3ab9975 100644 --- a/distutils2/tests/test_depgraph.py +++ b/distutils2/tests/test_depgraph.py @@ -13,6 +13,7 @@ except ImportError: import StringIO class DepGraphTestCase(support.LoggingCatcher, + support.WarningsCatcher, unittest.TestCase): DISTROS_DIST = ('choxie', 'grammar', 'towel-stuff') diff --git a/distutils2/tests/test_metadata.py b/distutils2/tests/test_metadata.py index e05a713..32c6895 100644 --- a/distutils2/tests/test_metadata.py +++ b/distutils2/tests/test_metadata.py @@ -7,11 +7,12 @@ from StringIO import StringIO from distutils2.metadata import (DistributionMetadata, _interpret, PKG_INFO_PREFERRED_VERSION) from distutils2.tests import run_unittest, unittest -from distutils2.tests.support import LoggingCatcher +from distutils2.tests.support import LoggingCatcher, WarningsCatcher from distutils2.errors import (MetadataConflictError, MetadataUnrecognizedVersionError) -class DistributionMetadataTestCase(LoggingCatcher, unittest.TestCase): +class DistributionMetadataTestCase(LoggingCatcher, WarningsCatcher, + unittest.TestCase): def test_instantiation(self): PKG_INFO = os.path.join(os.path.dirname(__file__), 'PKG-INFO') @@ -195,49 +196,21 @@ class DistributionMetadataTestCase(LoggingCatcher, unittest.TestCase): values = (('Requires-Dist', 'Funky (Groovie)'), ('Requires-Python', '1-4')) - from distutils2 import metadata as m - old = m.warn - m.warns = 0 - - def _warn(*args): - m.warns += 1 - - m.warn = _warn - - try: - for name, value in values: - metadata.set(name, value) - finally: - m.warn = old - res = m.warns - del m.warns + for name, value in values: + metadata.set(name, value) # we should have a certain amount of warnings - num_wanted = len(values) - self.assertEqual(num_wanted, res) + self.assertEqual(len(self.logs), 2) def test_multiple_predicates(self): metadata = DistributionMetadata() - from distutils2 import metadata as m - old = m.warn - m.warns = 0 - - def _warn(*args): - m.warns += 1 - # see for "3" instead of "3.0" ??? # its seems like the MINOR VERSION can be omitted - m.warn = _warn - try: - metadata['Requires-Python'] = '>=2.6, <3.0' - metadata['Requires-Dist'] = ['Foo (>=2.6, <3.0)'] - finally: - m.warn = old - res = m.warns - del m.warns + metadata['Requires-Python'] = '>=2.6, <3.0' + metadata['Requires-Dist'] = ['Foo (>=2.6, <3.0)'] - self.assertEqual(res, 0) + self.assertEqual(len(self.warnings), 0) def test_project_url(self): metadata = DistributionMetadata() |
