[Python-checkins] distutils2: refactoring tests for warnings
tarek.ziade
python-checkins at python.org
Sun Sep 19 10:20:22 CEST 2010
tarek.ziade pushed ba829371a028 to distutils2:
http://hg.python.org/distutils2/rev/ba829371a028
changeset: 640:ba829371a028
user: Konrad Delong <konryd at gmail.com>
date: Sun Aug 15 20:51:59 2010 +0200
summary: refactoring tests for warnings
files: src/distutils2/tests/__init__.py, src/distutils2/tests/test_build_ext.py, src/distutils2/tests/test_cygwinccompiler.py, src/distutils2/tests/test_dist.py
diff --git a/src/distutils2/tests/__init__.py b/src/distutils2/tests/__init__.py
--- a/src/distutils2/tests/__init__.py
+++ b/src/distutils2/tests/__init__.py
@@ -18,7 +18,6 @@
import os
import sys
-import warnings
from distutils2.tests.support import unittest
from test.test_support import TESTFN # use TESTFN from stdlib/test_support.
diff --git a/src/distutils2/tests/test_build_ext.py b/src/distutils2/tests/test_build_ext.py
--- a/src/distutils2/tests/test_build_ext.py
+++ b/src/distutils2/tests/test_build_ext.py
@@ -2,7 +2,6 @@
import os
import shutil
from StringIO import StringIO
-import warnings
import distutils2.tests
from distutils2.tests.support import unittest
diff --git a/src/distutils2/tests/test_cygwinccompiler.py b/src/distutils2/tests/test_cygwinccompiler.py
--- a/src/distutils2/tests/test_cygwinccompiler.py
+++ b/src/distutils2/tests/test_cygwinccompiler.py
@@ -1,7 +1,6 @@
"""Tests for distutils.cygwinccompiler."""
import sys
import os
-import warnings
try:
import sysconfig
except ImportError:
diff --git a/src/distutils2/tests/test_dist.py b/src/distutils2/tests/test_dist.py
--- a/src/distutils2/tests/test_dist.py
+++ b/src/distutils2/tests/test_dist.py
@@ -23,6 +23,7 @@
def initialize_options(self):
self.sample_option = None
+ def finalize_options(self): pass
class TestDistribution(Distribution):
@@ -39,6 +40,7 @@
class DistributionTestCase(support.TempdirManager,
support.LoggingSilencer,
+ support.WarningsCatcher,
support.EnvironGuard,
unittest.TestCase):
@@ -156,23 +158,14 @@
def test_bad_attr(self):
cls = Distribution
- # catching warnings
- warns = []
- def _warn(msg):
- warns.append(msg)
+ dist = cls(attrs={'author': 'xxx',
+ 'name': 'xxx',
+ 'version': 'xxx',
+ 'url': 'xxxx',
+ 'badoptname': 'xxx'})
- old_warn = warnings.warn
- warnings.warn = _warn
- try:
- dist = cls(attrs={'author': 'xxx',
- 'name': 'xxx',
- 'version': 'xxx',
- 'url': 'xxxx',
- 'badoptname': 'xxx'})
- finally:
- warnings.warn = old_warn
-
- self.assertTrue(len(warns)==1 and "Unknown distribution" in warns[0])
+ self.assertTrue(len(self.warnings)==1)
+ self.assertTrue("Unknown distribution" in self.warnings[0]['message'].args[0])
def test_empty_options(self):
# an empty options dictionary should not stay in the
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list