Merged revisions 78351 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r78351 | r.david.murray | 2010-02-22 19:24:49 -0500 (Mon, 22 Feb 2010) | 5 lines

  Issue 6292: for the moment at least, the test suite passes if run
  with -OO.  Tests requiring docstrings are skipped.  Patch by
  Brian Curtin, thanks to Matias Torchinsky for helping review and
  improve the patch.
........
This commit is contained in:
R. David Murray 2010-02-24 01:46:21 +00:00
parent 72aee3dcab
commit 378c0cf5ab
19 changed files with 211 additions and 42 deletions

View File

@ -16,7 +16,7 @@ class BuildPyTestCase(support.TempdirManager,
support.LoggingSilencer, support.LoggingSilencer,
unittest.TestCase): unittest.TestCase):
def test_package_data(self): def _setup_package_data(self):
sources = self.mkdtemp() sources = self.mkdtemp()
f = open(os.path.join(sources, "__init__.py"), "w") f = open(os.path.join(sources, "__init__.py"), "w")
f.write("# Pretend this is a package.") f.write("# Pretend this is a package.")
@ -52,10 +52,19 @@ class BuildPyTestCase(support.TempdirManager,
self.assertEqual(len(cmd.get_outputs()), 3) self.assertEqual(len(cmd.get_outputs()), 3)
pkgdest = os.path.join(destination, "pkg") pkgdest = os.path.join(destination, "pkg")
files = os.listdir(pkgdest) files = os.listdir(pkgdest)
return files
def test_package_data(self):
files = self._setup_package_data()
self.assertTrue("__init__.py" in files) self.assertTrue("__init__.py" in files)
self.assertTrue("__init__.pyc" in files)
self.assertTrue("README.txt" in files) self.assertTrue("README.txt" in files)
@unittest.skipIf(sys.flags.optimize >= 2,
"pyc files are not written with -O2 and above")
def test_package_data_pyc(self):
files = self._setup_package_data()
self.assertTrue("__init__.pyc" in files)
def test_empty_package_dir (self): def test_empty_package_dir (self):
# See SF 1668596/1720897. # See SF 1668596/1720897.
cwd = os.getcwd() cwd = os.getcwd()

View File

@ -1,6 +1,7 @@
"""Tests for distutils.extension.""" """Tests for distutils.extension."""
import unittest
import os import os
import sys
import unittest
import warnings import warnings
from test.support import check_warnings from test.support import check_warnings
@ -32,16 +33,22 @@ class ExtensionTestCase(unittest.TestCase):
self.assertEquals(names, wanted) self.assertEquals(names, wanted)
def test_extension_init(self): @unittest.skipIf(sys.flags.optimize >= 2,
# the first argument, which is the name, must be a string "Assertions are omitted with -O2 and above")
def test_extension_init_assertions(self):
# The first argument, which is the name, must be a string.
self.assertRaises(AssertionError, Extension, 1, []) self.assertRaises(AssertionError, Extension, 1, [])
ext = Extension('name', [])
self.assertEquals(ext.name, 'name')
# the second argument, which is the list of files, must # the second argument, which is the list of files, must
# be a list of strings # be a list of strings
self.assertRaises(AssertionError, Extension, 'name', 'file') self.assertRaises(AssertionError, Extension, 'name', 'file')
self.assertRaises(AssertionError, Extension, 'name', ['file', 1]) self.assertRaises(AssertionError, Extension, 'name', ['file', 1])
def test_extension_init(self):
ext = Extension('name', [])
self.assertEquals(ext.name, 'name')
ext = Extension('name', ['file1', 'file2']) ext = Extension('name', ['file1', 'file2'])
self.assertEquals(ext.sources, ['file1', 'file2']) self.assertEquals(ext.sources, ['file1', 'file2'])

View File

@ -1,6 +1,6 @@
"""Tests for distutils.command.install_data.""" """Tests for distutils.command.install_data."""
import sys
import os import os
import sys
import unittest import unittest
from distutils.command.install_lib import install_lib from distutils.command.install_lib import install_lib
@ -31,9 +31,7 @@ class InstallLibTestCase(support.TempdirManager,
cmd.finalize_options() cmd.finalize_options()
self.assertEquals(cmd.optimize, 2) self.assertEquals(cmd.optimize, 2)
@unittest.skipUnless(not sys.dont_write_bytecode, def _setup_byte_compile(self):
'byte-compile not supported')
def test_byte_compile(self):
pkg_dir, dist = self.create_dist() pkg_dir, dist = self.create_dist()
cmd = install_lib(dist) cmd = install_lib(dist)
cmd.compile = cmd.optimize = 1 cmd.compile = cmd.optimize = 1
@ -41,8 +39,15 @@ class InstallLibTestCase(support.TempdirManager,
f = os.path.join(pkg_dir, 'foo.py') f = os.path.join(pkg_dir, 'foo.py')
self.write_file(f, '# python file') self.write_file(f, '# python file')
cmd.byte_compile([f]) cmd.byte_compile([f])
self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyc'))) return pkg_dir
self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyo')))
@unittest.skipIf(sys.dont_write_bytecode, 'byte-compile not enabled')
def test_byte_compile(self):
pkg_dir = self._setup_byte_compile()
if sys.flags.optimize < 1:
self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyc')))
else:
self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyo')))
def test_get_outputs(self): def test_get_outputs(self):
pkg_dir, dist = self.create_dist() pkg_dir, dist = self.create_dist()

View File

@ -2192,6 +2192,19 @@ class DocTestCase(unittest.TestCase):
def shortDescription(self): def shortDescription(self):
return "Doctest: " + self._dt_test.name return "Doctest: " + self._dt_test.name
class SkipDocTestCase(DocTestCase):
def __init__(self):
DocTestCase.__init__(self, None)
def setUp(self):
self.skipTest("DocTestSuite will not work with -O2 and above")
def test_skip(self):
pass
def shortDescription(self):
return "Skipping tests from %s" % module.__name__
def DocTestSuite(module=None, globs=None, extraglobs=None, test_finder=None, def DocTestSuite(module=None, globs=None, extraglobs=None, test_finder=None,
**options): **options):
""" """
@ -2234,13 +2247,20 @@ def DocTestSuite(module=None, globs=None, extraglobs=None, test_finder=None,
module = _normalize_module(module) module = _normalize_module(module)
tests = test_finder.find(module, globs=globs, extraglobs=extraglobs) tests = test_finder.find(module, globs=globs, extraglobs=extraglobs)
if not tests:
if not tests and sys.flags.optimize >=2:
# Skip doctests when running with -O2
suite = unittest.TestSuite()
suite.addTest(SkipDocTestCase())
return suite
elif not tests:
# Why do we want to do this? Because it reveals a bug that might # Why do we want to do this? Because it reveals a bug that might
# otherwise be hidden. # otherwise be hidden.
raise ValueError(module, "has no tests") raise ValueError(module, "has no tests")
tests.sort() tests.sort()
suite = unittest.TestSuite() suite = unittest.TestSuite()
for test in tests: for test in tests:
if len(test.examples) == 0: if len(test.examples) == 0:
continue continue

View File

@ -239,6 +239,9 @@ from __future__ import print_function"""
finally: finally:
os.linesep = old_sep os.linesep = old_sep
@unittest.skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
def test_refactor_docstring(self): def test_refactor_docstring(self):
rt = self.rt() rt = self.rt()

View File

@ -10,6 +10,7 @@ from random import randrange, shuffle
import operator import operator
import keyword import keyword
import re import re
import sys
from collections import Hashable, Iterable, Iterator from collections import Hashable, Iterable, Iterator
from collections import Sized, Container, Callable from collections import Sized, Container, Callable
from collections import Set, MutableSet from collections import Set, MutableSet
@ -24,7 +25,6 @@ class TestNamedTuple(unittest.TestCase):
def test_factory(self): def test_factory(self):
Point = namedtuple('Point', 'x y') Point = namedtuple('Point', 'x y')
self.assertEqual(Point.__name__, 'Point') self.assertEqual(Point.__name__, 'Point')
self.assertEqual(Point.__doc__, 'Point(x, y)')
self.assertEqual(Point.__slots__, ()) self.assertEqual(Point.__slots__, ())
self.assertEqual(Point.__module__, __name__) self.assertEqual(Point.__module__, __name__)
self.assertEqual(Point.__getitem__, tuple.__getitem__) self.assertEqual(Point.__getitem__, tuple.__getitem__)
@ -51,6 +51,12 @@ class TestNamedTuple(unittest.TestCase):
self.assertRaises(TypeError, Point._make, [11]) # catch too few args self.assertRaises(TypeError, Point._make, [11]) # catch too few args
self.assertRaises(TypeError, Point._make, [11, 22, 33]) # catch too many args self.assertRaises(TypeError, Point._make, [11, 22, 33]) # catch too many args
@unittest.skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
def test_factory_doc_attr(self):
Point = namedtuple('Point', 'x y')
self.assertEqual(Point.__doc__, 'Point(x, y)')
def test_name_fixer(self): def test_name_fixer(self):
for spec, renamed in [ for spec, renamed in [
[('efg', 'g%hi'), ('efg', '_1')], # field with non-alpha char [('efg', 'g%hi'), ('efg', '_1')], # field with non-alpha char

View File

@ -4,6 +4,7 @@
import sys import sys
import os import os
import decimal import decimal
import sys
import tempfile import tempfile
import unittest import unittest
import threading import threading
@ -85,7 +86,7 @@ class ContextManagerTestCase(unittest.TestCase):
raise ZeroDivisionError(999) raise ZeroDivisionError(999)
self.assertEqual(state, [1, 42, 999]) self.assertEqual(state, [1, 42, 999])
def test_contextmanager_attribs(self): def _create_contextmanager_attribs(self):
def attribs(**kw): def attribs(**kw):
def decorate(func): def decorate(func):
for k,v in kw.items(): for k,v in kw.items():
@ -96,8 +97,17 @@ class ContextManagerTestCase(unittest.TestCase):
@attribs(foo='bar') @attribs(foo='bar')
def baz(spam): def baz(spam):
"""Whee!""" """Whee!"""
return baz
def test_contextmanager_attribs(self):
baz = self._create_contextmanager_attribs()
self.assertEqual(baz.__name__,'baz') self.assertEqual(baz.__name__,'baz')
self.assertEqual(baz.foo, 'bar') self.assertEqual(baz.foo, 'bar')
@unittest.skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
def test_contextmanager_doc_attrib(self):
baz = self._create_contextmanager_attribs()
self.assertEqual(baz.__doc__, "Whee!") self.assertEqual(baz.__doc__, "Whee!")
class ClosingTestCase(unittest.TestCase): class ClosingTestCase(unittest.TestCase):

View File

@ -1817,6 +1817,9 @@ order (MRO) for bases """
else: else:
self.fail("expected ZeroDivisionError from bad property") self.fail("expected ZeroDivisionError from bad property")
@unittest.skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
def test_properties_doc_attrib(self):
class E(object): class E(object):
def getter(self): def getter(self):
"getter method" "getter method"
@ -1829,6 +1832,7 @@ order (MRO) for bases """
prop2 = property(fset=setter) prop2 = property(fset=setter)
self.assertEqual(prop2.__doc__, None) self.assertEqual(prop2.__doc__, None)
def test_testcapi_no_segfault(self):
# this segfaulted in 2.5b2 # this segfaulted in 2.5b2
try: try:
import _testcapi import _testcapi

View File

@ -12,7 +12,11 @@ the example. It should be ignored:
""" """
import sys
import unittest
from test import support from test import support
if sys.flags.optimize >= 2:
raise unittest.SkipTest("Cannot test docstrings with -O2")
class C(object): class C(object):
"""Class C. """Class C.

View File

@ -1,5 +1,6 @@
from xmlrpc.server import DocXMLRPCServer from xmlrpc.server import DocXMLRPCServer
import http.client import http.client
import sys
from test import support from test import support
import threading import threading
import time import time
@ -7,6 +8,20 @@ import unittest
PORT = None PORT = None
def make_request_and_skipIf(condition, reason):
# If we skip the test, we have to make a request because the
# the server created in setUp blocks expecting one to come in.
if not condition:
return lambda func: func
def decorator(func):
def make_request_and_skip(self):
self.client.request("GET", "/")
self.client.getresponse()
raise unittest.SkipTest(reason)
return make_request_and_skip
return decorator
def server(evt, numrequests): def server(evt, numrequests):
serv = DocXMLRPCServer(("localhost", 0), logRequests=False) serv = DocXMLRPCServer(("localhost", 0), logRequests=False)
@ -110,10 +125,12 @@ class DocXMLRPCHTTPGETServer(unittest.TestCase):
b'&lt;lambda&gt;</strong></a>(x, y)</dt></dl>'), b'&lt;lambda&gt;</strong></a>(x, y)</dt></dl>'),
response.read()) response.read())
@make_request_and_skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
def test_autolinking(self): def test_autolinking(self):
"""Test that the server correctly automatically wraps references to PEPS """Test that the server correctly automatically wraps references to
and RFCs with links, and that it linkifies text starting with http or PEPS and RFCs with links, and that it linkifies text starting with
ftp protocol prefixes. http or ftp protocol prefixes.
The documentation for the "add" method contains the test material. The documentation for the "add" method contains the test material.
""" """
@ -132,11 +149,13 @@ class DocXMLRPCHTTPGETServer(unittest.TestCase):
b'auto-linked,&nbsp;too:<br>\n<a href="http://google.com">' b'auto-linked,&nbsp;too:<br>\n<a href="http://google.com">'
b'http://google.com</a>.</tt></dd></dl>'), response) b'http://google.com</a>.</tt></dd></dl>'), response)
@make_request_and_skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
def test_system_methods(self): def test_system_methods(self):
"""Test the precense of three consecutive system.* methods. """Test the precense of three consecutive system.* methods.
This also tests their use of parameter type recognition and the systems This also tests their use of parameter type recognition and the
related to that process. systems related to that process.
""" """
self.client.request("GET", "/") self.client.request("GET", "/")
response = self.client.getresponse().read() response = self.client.getresponse().read()

View File

@ -1,4 +1,5 @@
import functools import functools
import sys
import unittest import unittest
from test import support from test import support
from weakref import proxy from weakref import proxy
@ -180,7 +181,7 @@ class TestUpdateWrapper(unittest.TestCase):
for key in wrapped_attr: for key in wrapped_attr:
self.assertTrue(wrapped_attr[key] is wrapper_attr[key]) self.assertTrue(wrapped_attr[key] is wrapper_attr[key])
def test_default_update(self): def _default_update(self):
def f(): def f():
"""This is a test""" """This is a test"""
pass pass
@ -188,11 +189,20 @@ class TestUpdateWrapper(unittest.TestCase):
def wrapper(): def wrapper():
pass pass
functools.update_wrapper(wrapper, f) functools.update_wrapper(wrapper, f)
return wrapper, f
def test_default_update(self):
wrapper, f = self._default_update()
self.check_wrapper(wrapper, f) self.check_wrapper(wrapper, f)
self.assertEqual(wrapper.__name__, 'f') self.assertEqual(wrapper.__name__, 'f')
self.assertEqual(wrapper.__doc__, 'This is a test')
self.assertEqual(wrapper.attr, 'This is also a test') self.assertEqual(wrapper.attr, 'This is also a test')
@unittest.skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
def test_default_update_doc(self):
wrapper, f = self._default_update()
self.assertEqual(wrapper.__doc__, 'This is a test')
def test_no_update(self): def test_no_update(self):
def f(): def f():
"""This is a test""" """This is a test"""
@ -233,7 +243,7 @@ class TestUpdateWrapper(unittest.TestCase):
class TestWraps(TestUpdateWrapper): class TestWraps(TestUpdateWrapper):
def test_default_update(self): def _default_update(self):
def f(): def f():
"""This is a test""" """This is a test"""
pass pass
@ -242,10 +252,19 @@ class TestWraps(TestUpdateWrapper):
def wrapper(): def wrapper():
pass pass
self.check_wrapper(wrapper, f) self.check_wrapper(wrapper, f)
return wrapper
def test_default_update(self):
wrapper = self._default_update()
self.assertEqual(wrapper.__name__, 'f') self.assertEqual(wrapper.__name__, 'f')
self.assertEqual(wrapper.__doc__, 'This is a test')
self.assertEqual(wrapper.attr, 'This is also a test') self.assertEqual(wrapper.attr, 'This is also a test')
@unittest.skipIf(not sys.flags.optimize <= 1,
"Docstrings are omitted with -O2 and above")
def test_default_update_doc(self):
wrapper = self._default_update()
self.assertEqual(wrapper.__doc__, 'This is a test')
def test_no_update(self): def test_no_update(self):
def f(): def f():
"""This is a test""" """This is a test"""
@ -350,7 +369,6 @@ class TestReduce(unittest.TestCase):
def test_main(verbose=None): def test_main(verbose=None):
import sys
test_classes = ( test_classes = (
TestPartial, TestPartial,
TestPartialSubclass, TestPartialSubclass,

View File

@ -236,6 +236,8 @@ class TestRetrievingSourceCode(GetSourceBase):
self.assertEqual(functions, [('eggs', mod.eggs), self.assertEqual(functions, [('eggs', mod.eggs),
('spam', mod.spam)]) ('spam', mod.spam)])
@unittest.skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
def test_getdoc(self): def test_getdoc(self):
self.assertEqual(inspect.getdoc(mod), 'A module docstring.') self.assertEqual(inspect.getdoc(mod), 'A module docstring.')
self.assertEqual(inspect.getdoc(mod.StupidGit), self.assertEqual(inspect.getdoc(mod.StupidGit),

View File

@ -53,7 +53,8 @@ class TestPkg(unittest.TestCase):
def tearDown(self): def tearDown(self):
sys.path[:] = self.syspath sys.path[:] = self.syspath
support.modules_cleanup(*self.modules_before) support.modules_cleanup(*self.modules_before)
cleanout(self.root) if self.root: # Only clean if the test was actually run
cleanout(self.root)
# delete all modules concerning the tested hiearchy # delete all modules concerning the tested hiearchy
if self.pkgname: if self.pkgname:
@ -103,9 +104,6 @@ class TestPkg(unittest.TestCase):
] ]
self.mkhier(hier) self.mkhier(hier)
import t2
self.assertEqual(t2.__doc__, "doc for t2")
import t2.sub import t2.sub
import t2.sub.subsub import t2.sub.subsub
self.assertEqual(t2.__name__, "t2") self.assertEqual(t2.__name__, "t2")
@ -276,6 +274,17 @@ class TestPkg(unittest.TestCase):
self.assertFalse(sub) self.assertFalse(sub)
self.assertFalse(subsub) self.assertFalse(subsub)
@unittest.skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
def test_8(self):
hier = [
("t8", None),
("t8 __init__"+os.extsep+"py", "'doc for t8'"),
]
self.mkhier(hier)
import t8
self.assertEqual(t8.__doc__, "doc for t8")
def test_main(): def test_main():
support.run_unittest(__name__) support.run_unittest(__name__)

View File

@ -1,6 +1,7 @@
# Test case for property # Test case for property
# more tests are in test_descr # more tests are in test_descr
import sys
import unittest import unittest
from test.support import run_unittest from test.support import run_unittest
@ -91,7 +92,6 @@ class PropertyTests(unittest.TestCase):
base.spam = 20 base.spam = 20
self.assertEqual(base.spam, 20) self.assertEqual(base.spam, 20)
self.assertEqual(base._spam, 20) self.assertEqual(base._spam, 20)
self.assertEqual(base.__class__.spam.__doc__, "BaseClass.getter")
def test_property_decorator_subclass(self): def test_property_decorator_subclass(self):
# see #1620 # see #1620
@ -99,14 +99,27 @@ class PropertyTests(unittest.TestCase):
self.assertRaises(PropertyGet, getattr, sub, "spam") self.assertRaises(PropertyGet, getattr, sub, "spam")
self.assertRaises(PropertySet, setattr, sub, "spam", None) self.assertRaises(PropertySet, setattr, sub, "spam", None)
self.assertRaises(PropertyDel, delattr, sub, "spam") self.assertRaises(PropertyDel, delattr, sub, "spam")
@unittest.skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
def test_property_decorator_subclass_doc(self):
sub = SubClass()
self.assertEqual(sub.__class__.spam.__doc__, "SubClass.getter") self.assertEqual(sub.__class__.spam.__doc__, "SubClass.getter")
@unittest.skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
def test_property_decorator_baseclass_doc(self):
base = BaseClass()
self.assertEqual(base.__class__.spam.__doc__, "BaseClass.getter")
def test_property_decorator_doc(self): def test_property_decorator_doc(self):
base = PropertyDocBase() base = PropertyDocBase()
sub = PropertyDocSub() sub = PropertyDocSub()
self.assertEqual(base.__class__.spam.__doc__, "spam spam spam") self.assertEqual(base.__class__.spam.__doc__, "spam spam spam")
self.assertEqual(sub.__class__.spam.__doc__, "spam spam spam") self.assertEqual(sub.__class__.spam.__doc__, "spam spam spam")
@unittest.skipIf(sys.flags.optimize >= 1,
"Docstrings are omitted with -O2 and above")
def test_property_getter_doc_override(self): def test_property_getter_doc_override(self):
newgettersub = PropertySubNewGetter() newgettersub = PropertySubNewGetter()
self.assertEqual(newgettersub.spam, 5) self.assertEqual(newgettersub.spam, 5)
@ -126,16 +139,6 @@ class PropertySubSlots(property):
class PropertySubclassTests(unittest.TestCase): class PropertySubclassTests(unittest.TestCase):
def test_docstring_copy(self):
class Foo(object):
@PropertySub
def spam(self):
"""spam wrapped in property subclass"""
return 1
self.assertEqual(
Foo.spam.__doc__,
"spam wrapped in property subclass")
def test_slots_docstring_copy_exception(self): def test_slots_docstring_copy_exception(self):
try: try:
class Foo(object): class Foo(object):
@ -148,6 +151,20 @@ class PropertySubclassTests(unittest.TestCase):
else: else:
raise Exception("AttributeError not raised") raise Exception("AttributeError not raised")
@unittest.skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
def test_docstring_copy(self):
class Foo(object):
@PropertySub
def spam(self):
"""spam wrapped in property subclass"""
return 1
self.assertEqual(
Foo.spam.__doc__,
"spam wrapped in property subclass")
@unittest.skipIf(sys.flags.optimize <= 2,
"Docstrings are omitted with -O2 and above")
def test_property_setter_copies_getter_docstring(self): def test_property_setter_copies_getter_docstring(self):
class Foo(object): class Foo(object):
def __init__(self): self._spam = 1 def __init__(self): self._spam = 1
@ -179,6 +196,8 @@ class PropertySubclassTests(unittest.TestCase):
FooSub.spam.__doc__, FooSub.spam.__doc__,
"spam wrapped in property subclass") "spam wrapped in property subclass")
@unittest.skipIf(sys.flags.optimize <= 2,
"Docstrings are omitted with -O2 and above")
def test_property_new_getter_new_docstring(self): def test_property_new_getter_new_docstring(self):
class Foo(object): class Foo(object):

View File

@ -236,6 +236,8 @@ def print_diffs(text1, text2):
class PyDocDocTest(unittest.TestCase): class PyDocDocTest(unittest.TestCase):
@unittest.skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
def test_html_doc(self): def test_html_doc(self):
result, doc_loc = get_pydoc_html(pydoc_mod) result, doc_loc = get_pydoc_html(pydoc_mod)
mod_file = inspect.getabsfile(pydoc_mod) mod_file = inspect.getabsfile(pydoc_mod)
@ -249,6 +251,8 @@ class PyDocDocTest(unittest.TestCase):
print_diffs(expected_html, result) print_diffs(expected_html, result)
self.fail("outputs are not equal, see diff above") self.fail("outputs are not equal, see diff above")
@unittest.skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
def test_text_doc(self): def test_text_doc(self):
result, doc_loc = get_pydoc_text(pydoc_mod) result, doc_loc = get_pydoc_text(pydoc_mod)
expected_text = expected_text_pattern % \ expected_text = expected_text_pattern % \

View File

@ -2051,6 +2051,8 @@ class Test_TestResult(TestCase):
'testGetDescriptionWithoutDocstring (' + __name__ + 'testGetDescriptionWithoutDocstring (' + __name__ +
'.Test_TestResult)') '.Test_TestResult)')
@unittest.skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
def testGetDescriptionWithOneLineDocstring(self): def testGetDescriptionWithOneLineDocstring(self):
"""Tests getDescription() for a method with a docstring.""" """Tests getDescription() for a method with a docstring."""
result = unittest.TextTestResult(None, True, 1) result = unittest.TextTestResult(None, True, 1)
@ -2060,6 +2062,8 @@ class Test_TestResult(TestCase):
'(' + __name__ + '.Test_TestResult)\n' '(' + __name__ + '.Test_TestResult)\n'
'Tests getDescription() for a method with a docstring.')) 'Tests getDescription() for a method with a docstring.'))
@unittest.skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
def testGetDescriptionWithMultiLineDocstring(self): def testGetDescriptionWithMultiLineDocstring(self):
"""Tests getDescription() for a method with a longer docstring. """Tests getDescription() for a method with a longer docstring.
The second line of the docstring. The second line of the docstring.
@ -2489,12 +2493,16 @@ class Test_TestCase(TestCase, TestEquality, TestHashing):
def testShortDescriptionWithoutDocstring(self): def testShortDescriptionWithoutDocstring(self):
self.assertIsNone(self.shortDescription()) self.assertIsNone(self.shortDescription())
@unittest.skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
def testShortDescriptionWithOneLineDocstring(self): def testShortDescriptionWithOneLineDocstring(self):
"""Tests shortDescription() for a method with a docstring.""" """Tests shortDescription() for a method with a docstring."""
self.assertEqual( self.assertEqual(
self.shortDescription(), self.shortDescription(),
'Tests shortDescription() for a method with a docstring.') 'Tests shortDescription() for a method with a docstring.')
@unittest.skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
def testShortDescriptionWithMultiLineDocstring(self): def testShortDescriptionWithMultiLineDocstring(self):
"""Tests shortDescription() for a method with a longer docstring. """Tests shortDescription() for a method with a longer docstring.

View File

@ -383,6 +383,22 @@ def is_unavailable_exception(e):
if exc_mess and 'temporarily unavailable' in exc_mess.lower(): if exc_mess and 'temporarily unavailable' in exc_mess.lower():
return True return True
def make_request_and_skipIf(condition, reason):
# If we skip the test, we have to make a request because the
# the server created in setUp blocks expecting one to come in.
if not condition:
return lambda func: func
def decorator(func):
def make_request_and_skip(self):
try:
xmlrpclib.ServerProxy(URL).my_function()
except (xmlrpclib.ProtocolError, socket.error) as e:
if not is_unavailable_exception(e):
raise
raise unittest.SkipTest(reason)
return make_request_and_skip
return decorator
class BaseServerTestCase(unittest.TestCase): class BaseServerTestCase(unittest.TestCase):
requestHandler = None requestHandler = None
request_count = 1 request_count = 1
@ -403,6 +419,7 @@ class BaseServerTestCase(unittest.TestCase):
def tearDown(self): def tearDown(self):
# wait on the server thread to terminate # wait on the server thread to terminate
self.evt.wait(4.0) self.evt.wait(4.0)
# XXX this code does not work, and in fact stop_serving doesn't exist.
if not self.evt.is_set(): if not self.evt.is_set():
self.evt.set() self.evt.set()
stop_serving() stop_serving()
@ -474,6 +491,8 @@ class SimpleServerTestCase(BaseServerTestCase):
# protocol error; provide additional information in test output # protocol error; provide additional information in test output
self.fail("%s\n%s" % (e, getattr(e, "headers", ""))) self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
@make_request_and_skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
def test_introspection3(self): def test_introspection3(self):
try: try:
# test native doc # test native doc

View File

@ -763,6 +763,7 @@ Christian Tismer
Frank J. Tobin Frank J. Tobin
R Lindsay Todd R Lindsay Todd
Bennett Todd Bennett Todd
Matias Torchinsky
Richard Townsend Richard Townsend
Laurence Tratt Laurence Tratt
John Tromp John Tromp

View File

@ -12,7 +12,6 @@ What's New in Python 3.2 Alpha 1?
Core and Builtins Core and Builtins
----------------- -----------------
=======
- Issue #6902: Fix problem with built-in types format incorrectly with - Issue #6902: Fix problem with built-in types format incorrectly with
0 padding. 0 padding.
@ -782,6 +781,9 @@ Documentation
Tests Tests
----- -----
- Issue #6292: for the moment at least, the test suite runs cleanly if python
is run with the -OO flag. Tests requiring docstrings are skipped.
- Issue #7712: test.support gained a new `temp_cwd` context manager which is - Issue #7712: test.support gained a new `temp_cwd` context manager which is
now also used by regrtest to run all the tests in a temporary directory. now also used by regrtest to run all the tests in a temporary directory.
The original CWD is saved in `support.SAVEDCWD`. The original CWD is saved in `support.SAVEDCWD`.