summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2016-07-14 04:13:29 (GMT)
committerBenjamin Peterson <benjamin@python.org>2016-07-14 04:13:29 (GMT)
commitab078e9ed1a5d1b693d6ee843f1a34e8993e9dee (patch)
tree55e6e21b81315f126e76357af7e545cfe498d778 /Lib/test
parentfb4f8257bfa4471764e10c1d8525a5bb7b0145e5 (diff)
downloadcpython-ab078e9ed1a5d1b693d6ee843f1a34e8993e9dee.zip
cpython-ab078e9ed1a5d1b693d6ee843f1a34e8993e9dee.tar.gz
cpython-ab078e9ed1a5d1b693d6ee843f1a34e8993e9dee.tar.bz2
Backed out changeset af29d89083b3 (closes #25548) (closes #27498)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_class.py10
-rw-r--r--Lib/test/test_cmd_line_script.py9
-rw-r--r--Lib/test/test_defaultdict.py2
-rw-r--r--Lib/test/test_descr.py4
-rw-r--r--Lib/test/test_descrtut.py31
-rw-r--r--Lib/test/test_doctest.py2
-rw-r--r--Lib/test/test_doctest3.txt2
-rw-r--r--Lib/test/test_functools.py33
-rw-r--r--Lib/test/test_generators.py37
-rw-r--r--Lib/test/test_genexps.py5
-rw-r--r--Lib/test/test_metaclass.py9
-rw-r--r--Lib/test/test_pprint.py9
-rw-r--r--Lib/test/test_reprlib.py6
-rw-r--r--Lib/test/test_statistics.py2
-rw-r--r--Lib/test/test_wsgiref.py6
-rw-r--r--Lib/test/test_xmlrpc.py4
16 files changed, 80 insertions, 91 deletions
diff --git a/Lib/test/test_class.py b/Lib/test/test_class.py
index e02a3cb..4d554a3 100644
--- a/Lib/test/test_class.py
+++ b/Lib/test/test_class.py
@@ -568,15 +568,5 @@ class ClassTests(unittest.TestCase):
a = A(hash(A.f)^(-1))
hash(a.f)
- def test_class_repr(self):
- # We should get the address of the object
- class A:
- pass
-
- result = repr(A)
- self.assertRegex(result,
- "<class 'test.test_class.ClassTests.test_class_repr.<locals>.A'"
- " at 0x.+>")
-
if __name__ == '__main__':
unittest.main()
diff --git a/Lib/test/test_cmd_line_script.py b/Lib/test/test_cmd_line_script.py
index e7c6351..01fb7dc 100644
--- a/Lib/test/test_cmd_line_script.py
+++ b/Lib/test/test_cmd_line_script.py
@@ -127,10 +127,7 @@ class CmdLineTest(unittest.TestCase):
print(printed_package)
print(printed_argv0)
print(printed_cwd)
- expected = printed_loader.encode('utf-8')
- idx = expected.find(b"at 0x")
- expected = expected[:idx]
- self.assertIn(expected, data)
+ self.assertIn(printed_loader.encode('utf-8'), data)
self.assertIn(printed_file.encode('utf-8'), data)
self.assertIn(printed_package.encode('utf-8'), data)
self.assertIn(printed_argv0.encode('utf-8'), data)
@@ -161,8 +158,6 @@ class CmdLineTest(unittest.TestCase):
def test_dash_c_loader(self):
rc, out, err = assert_python_ok("-c", "print(__loader__)")
expected = repr(importlib.machinery.BuiltinImporter).encode("utf-8")
- idx = expected.find(b"at 0x")
- expected = expected[:idx]
self.assertIn(expected, out)
def test_stdin_loader(self):
@@ -176,8 +171,6 @@ class CmdLineTest(unittest.TestCase):
finally:
out = kill_python(p)
expected = repr(importlib.machinery.BuiltinImporter).encode("utf-8")
- idx = expected.find(b"at 0x")
- expected = expected[:idx]
self.assertIn(expected, out)
@contextlib.contextmanager
diff --git a/Lib/test/test_defaultdict.py b/Lib/test/test_defaultdict.py
index 5bb4e12..a90bc2b 100644
--- a/Lib/test/test_defaultdict.py
+++ b/Lib/test/test_defaultdict.py
@@ -65,7 +65,7 @@ class TestDefaultDict(unittest.TestCase):
d2 = defaultdict(int)
self.assertEqual(d2.default_factory, int)
d2[12] = 42
- self.assertRegex(repr(d2), r"defaultdict\(<class 'int' at 0x.+>, {12: 42}\)")
+ self.assertEqual(repr(d2), "defaultdict(<class 'int'>, {12: 42})")
def foo(): return 43
d3 = defaultdict(foo)
self.assertTrue(d3.default_factory is foo)
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 954ef2d..0a5ecd5 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -4544,9 +4544,9 @@ order (MRO) for bases """
pass
foo = Foo()
self.assertRegex(repr(foo.method), # access via instance
- r"<bound method .*Foo\.method of <class '.*Foo' at 0x.+>>")
+ r"<bound method .*Foo\.method of <class '.*Foo'>>")
self.assertRegex(repr(Foo.method), # access via the class
- r"<bound method .*Foo\.method of <class '.*Foo' at 0x.+>>")
+ r"<bound method .*Foo\.method of <class '.*Foo'>>")
class MyCallable:
diff --git a/Lib/test/test_descrtut.py b/Lib/test/test_descrtut.py
index 80cfa41..506d1ab 100644
--- a/Lib/test/test_descrtut.py
+++ b/Lib/test/test_descrtut.py
@@ -37,16 +37,16 @@ test_1 = """
Here's the new type at work:
>>> print(defaultdict) # show our type
- <class 'test.test_descrtut.defaultdict' ...>
+ <class 'test.test_descrtut.defaultdict'>
>>> print(type(defaultdict)) # its metatype
- <class 'type' ...>
+ <class 'type'>
>>> a = defaultdict(default=0.0) # create an instance
>>> print(a) # show the instance
{}
>>> print(type(a)) # show its type
- <class 'test.test_descrtut.defaultdict' ...>
+ <class 'test.test_descrtut.defaultdict'>
>>> print(a.__class__) # show its class
- <class 'test.test_descrtut.defaultdict' ...>
+ <class 'test.test_descrtut.defaultdict'>
>>> print(type(a) is a.__class__) # its type is its class
True
>>> a[1] = 3.25 # modify the instance
@@ -149,11 +149,11 @@ Introspecting instances of built-in types
For instance of built-in types, x.__class__ is now the same as type(x):
>>> type([])
- <class 'list' ...>
+ <class 'list'>
>>> [].__class__
- <class 'list' ...>
+ <class 'list'>
>>> list
- <class 'list' ...>
+ <class 'list'>
>>> isinstance([], list)
True
>>> isinstance([], dict)
@@ -258,19 +258,19 @@ implicit first argument that is the *class* for which they are invoked.
... print("classmethod", cls, y)
>>> C.foo(1)
- classmethod <class 'test.test_descrtut.C' ...> 1
+ classmethod <class 'test.test_descrtut.C'> 1
>>> c = C()
>>> c.foo(1)
- classmethod <class 'test.test_descrtut.C' ...> 1
+ classmethod <class 'test.test_descrtut.C'> 1
>>> class D(C):
... pass
>>> D.foo(1)
- classmethod <class 'test.test_descrtut.D' ...> 1
+ classmethod <class 'test.test_descrtut.D'> 1
>>> d = D()
>>> d.foo(1)
- classmethod <class 'test.test_descrtut.D' ...> 1
+ classmethod <class 'test.test_descrtut.D'> 1
This prints "classmethod __main__.D 1" both times; in other words, the
class passed as the first argument of foo() is the class involved in the
@@ -286,11 +286,11 @@ But notice this:
>>> E.foo(1)
E.foo() called
- classmethod <class 'test.test_descrtut.C' ...> 1
+ classmethod <class 'test.test_descrtut.C'> 1
>>> e = E()
>>> e.foo(1)
E.foo() called
- classmethod <class 'test.test_descrtut.C' ...> 1
+ classmethod <class 'test.test_descrtut.C'> 1
In this example, the call to C.foo() from E.foo() will see class C as its
first argument, not class E. This is to be expected, since the call
@@ -350,7 +350,7 @@ Hmm -- property is builtin now, so let's try it that way too.
>>> del property # unmask the builtin
>>> property
- <class 'property' ...>
+ <class 'property'>
>>> class C(object):
... def __init__(self):
@@ -478,8 +478,7 @@ def test_main(verbose=None):
# business is used the name can change depending on how the test is
# invoked.
from test import support, test_descrtut
- import doctest
- support.run_doctest(test_descrtut, verbose, optionflags=doctest.ELLIPSIS)
+ support.run_doctest(test_descrtut, verbose)
# This part isn't needed for regrtest, but for running the test directly.
if __name__ == "__main__":
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py
index b416cbb..a9520a5 100644
--- a/Lib/test/test_doctest.py
+++ b/Lib/test/test_doctest.py
@@ -2338,7 +2338,7 @@ def test_DocFileSuite():
`__file__` global, which is set to the name of the file
containing the tests:
- >>> suite = doctest.DocFileSuite('test_doctest3.txt', optionflags=doctest.ELLIPSIS)
+ >>> suite = doctest.DocFileSuite('test_doctest3.txt')
>>> suite.run(unittest.TestResult())
<unittest.result.TestResult run=1 errors=0 failures=0>
diff --git a/Lib/test/test_doctest3.txt b/Lib/test/test_doctest3.txt
index 380ea76..dd8557e 100644
--- a/Lib/test/test_doctest3.txt
+++ b/Lib/test/test_doctest3.txt
@@ -2,4 +2,4 @@
Here we check that `__file__` is provided:
>>> type(__file__)
- <class 'str' ...>
+ <class 'str'>
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
index e2ab654..06eacfb 100644
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -1758,10 +1758,13 @@ class TestSingleDispatch(unittest.TestCase):
c.Container.register(P)
with self.assertRaises(RuntimeError) as re_one:
g(p)
- self.assertIn("Ambiguous dispatch:", str(re_one.exception))
- self.assertIn("<class 'collections.abc.Container'", str(re_one.exception))
- self.assertIn("<class 'collections.abc.Iterable'", str(re_one.exception))
-
+ self.assertIn(
+ str(re_one.exception),
+ (("Ambiguous dispatch: <class 'collections.abc.Container'> "
+ "or <class 'collections.abc.Iterable'>"),
+ ("Ambiguous dispatch: <class 'collections.abc.Iterable'> "
+ "or <class 'collections.abc.Container'>")),
+ )
class Q(c.Sized):
def __len__(self):
return 0
@@ -1787,10 +1790,13 @@ class TestSingleDispatch(unittest.TestCase):
# perspective.
with self.assertRaises(RuntimeError) as re_two:
h(c.defaultdict(lambda: 0))
- self.assertIn("Ambiguous dispatch:", str(re_two.exception))
- self.assertIn("<class 'collections.abc.Container'", str(re_two.exception))
- self.assertIn("<class 'collections.abc.Sized'", str(re_two.exception))
-
+ self.assertIn(
+ str(re_two.exception),
+ (("Ambiguous dispatch: <class 'collections.abc.Container'> "
+ "or <class 'collections.abc.Sized'>"),
+ ("Ambiguous dispatch: <class 'collections.abc.Sized'> "
+ "or <class 'collections.abc.Container'>")),
+ )
class R(c.defaultdict):
pass
c.MutableSequence.register(R)
@@ -1824,10 +1830,13 @@ class TestSingleDispatch(unittest.TestCase):
# There is no preference for registered versus inferred ABCs.
with self.assertRaises(RuntimeError) as re_three:
h(u)
- self.assertIn("Ambiguous dispatch:", str(re_three.exception))
- self.assertIn("<class 'collections.abc.Container'", str(re_three.exception))
- self.assertIn("<class 'collections.abc.Sized'", str(re_three.exception))
-
+ self.assertIn(
+ str(re_three.exception),
+ (("Ambiguous dispatch: <class 'collections.abc.Container'> "
+ "or <class 'collections.abc.Sized'>"),
+ ("Ambiguous dispatch: <class 'collections.abc.Sized'> "
+ "or <class 'collections.abc.Container'>")),
+ )
class V(c.Sized, S):
def __len__(self):
return 0
diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py
index c193301..f4b33af 100644
--- a/Lib/test/test_generators.py
+++ b/Lib/test/test_generators.py
@@ -671,10 +671,10 @@ From the Iterators list, about the types of these things.
... yield 1
...
>>> type(g)
-<class 'function' ...>
+<class 'function'>
>>> i = g()
>>> type(i)
-<class 'generator' ...>
+<class 'generator'>
>>> [s for s in dir(i) if not s.startswith('_')]
['close', 'gi_code', 'gi_frame', 'gi_running', 'gi_yieldfrom', 'send', 'throw']
>>> from test.support import HAVE_DOCSTRINGS
@@ -691,7 +691,7 @@ And more, added later.
>>> i.gi_running
0
>>> type(i.gi_frame)
-<class 'frame' ...>
+<class 'frame'>
>>> i.gi_running = 42
Traceback (most recent call last):
...
@@ -1066,27 +1066,27 @@ These are fine:
>>> def f():
... yield
>>> type(f())
-<class 'generator' ...>
+<class 'generator'>
>>> def f():
... if 0:
... yield
>>> type(f())
-<class 'generator' ...>
+<class 'generator'>
>>> def f():
... if 0:
... yield 1
>>> type(f())
-<class 'generator' ...>
+<class 'generator'>
>>> def f():
... if "":
... yield None
>>> type(f())
-<class 'generator' ...>
+<class 'generator'>
>>> def f():
... return
@@ -1110,7 +1110,7 @@ These are fine:
... x = 1
... return
>>> type(f())
-<class 'generator' ...>
+<class 'generator'>
>>> def f():
... if 0:
@@ -1118,7 +1118,7 @@ These are fine:
... yield 1
...
>>> type(f())
-<class 'NoneType' ...>
+<class 'NoneType'>
>>> def f():
... if 0:
@@ -1128,7 +1128,7 @@ These are fine:
... def f(self):
... yield 2
>>> type(f())
-<class 'NoneType' ...>
+<class 'NoneType'>
>>> def f():
... if 0:
@@ -1136,7 +1136,7 @@ These are fine:
... if 0:
... yield 2
>>> type(f())
-<class 'generator' ...>
+<class 'generator'>
This one caused a crash (see SF bug 567538):
@@ -1791,7 +1791,7 @@ And a more sane, but still weird usage:
>>> def f(): list(i for i in [(yield 26)])
>>> type(f())
-<class 'generator' ...>
+<class 'generator'>
A yield expression with augmented assignment.
@@ -2047,25 +2047,25 @@ enclosing function a generator:
>>> def f(): x += yield
>>> type(f())
-<class 'generator' ...>
+<class 'generator'>
>>> def f(): x = yield
>>> type(f())
-<class 'generator' ...>
+<class 'generator'>
>>> def f(): lambda x=(yield): 1
>>> type(f())
-<class 'generator' ...>
+<class 'generator'>
>>> def f(): x=(i for i in (yield) if (yield))
>>> type(f())
-<class 'generator' ...>
+<class 'generator'>
>>> def f(d): d[(yield "a")] = d[(yield "b")] = 27
>>> data = [1,2]
>>> g = f(data)
>>> type(g)
-<class 'generator' ...>
+<class 'generator'>
>>> g.send(None)
'a'
>>> data
@@ -2174,9 +2174,8 @@ __test__ = {"tut": tutorial_tests,
# so this works as expected in both ways of running regrtest.
def test_main(verbose=None):
from test import support, test_generators
- import doctest
support.run_unittest(__name__)
- support.run_doctest(test_generators, verbose, optionflags=doctest.ELLIPSIS)
+ support.run_doctest(test_generators, verbose)
# This part isn't needed for regrtest, but for running the test directly.
if __name__ == "__main__":
diff --git a/Lib/test/test_genexps.py b/Lib/test/test_genexps.py
index c5e10dd..fb531d6 100644
--- a/Lib/test/test_genexps.py
+++ b/Lib/test/test_genexps.py
@@ -27,7 +27,7 @@ Test first class
>>> g = (i*i for i in range(4))
>>> type(g)
- <class 'generator' ...>
+ <class 'generator'>
>>> list(g)
[0, 1, 4, 9]
@@ -269,8 +269,7 @@ else:
def test_main(verbose=None):
from test import support
from test import test_genexps
- import doctest
- support.run_doctest(test_genexps, verbose, optionflags=doctest.ELLIPSIS)
+ support.run_doctest(test_genexps, verbose)
# verify reference counting
if verbose and hasattr(sys, "gettotalrefcount"):
diff --git a/Lib/test/test_metaclass.py b/Lib/test/test_metaclass.py
index be683dd..e6fe20a 100644
--- a/Lib/test/test_metaclass.py
+++ b/Lib/test/test_metaclass.py
@@ -78,7 +78,7 @@ Also pass another keyword.
>>> class C(object, metaclass=M, other="haha"):
... pass
...
- Prepare called: ('C', (<class 'object' ...>,)) {'other': 'haha'}
+ Prepare called: ('C', (<class 'object'>,)) {'other': 'haha'}
New called: {'other': 'haha'}
>>> C.__class__ is M
True
@@ -104,7 +104,7 @@ Use various combinations of explicit keywords and **kwds.
>>> kwds = {'metaclass': M, 'other': 'haha'}
>>> class C(*bases, **kwds): pass
...
- Prepare called: ('C', (<class 'object' ...>,)) {'other': 'haha'}
+ Prepare called: ('C', (<class 'object'>,)) {'other': 'haha'}
New called: {'other': 'haha'}
>>> C.__class__ is M
True
@@ -114,7 +114,7 @@ Use various combinations of explicit keywords and **kwds.
>>> kwds = {'other': 'haha'}
>>> class C(B, metaclass=M, *bases, **kwds): pass
...
- Prepare called: ('C', (<class 'test.test_metaclass.B' ...>, <class 'object' ...>)) {'other': 'haha'}
+ Prepare called: ('C', (<class 'test.test_metaclass.B'>, <class 'object'>)) {'other': 'haha'}
New called: {'other': 'haha'}
>>> C.__class__ is M
True
@@ -259,8 +259,7 @@ else:
def test_main(verbose=False):
from test import support
from test import test_metaclass
- import doctest
- support.run_doctest(test_metaclass, verbose, optionflags=doctest.ELLIPSIS)
+ support.run_doctest(test_metaclass, verbose)
if __name__ == "__main__":
test_main(verbose=True)
diff --git a/Lib/test/test_pprint.py b/Lib/test/test_pprint.py
index 2283923..7ebc298 100644
--- a/Lib/test/test_pprint.py
+++ b/Lib/test/test_pprint.py
@@ -848,11 +848,12 @@ bytearray(b'\\x00\\x01\\x02\\x03'
def test_default_dict(self):
d = collections.defaultdict(int)
- self.assertRegex(pprint.pformat(d, width=1), r"defaultdict\(<class 'int' at 0x.+>, {}\)")
+ self.assertEqual(pprint.pformat(d, width=1), "defaultdict(<class 'int'>, {})")
words = 'the quick brown fox jumped over a lazy dog'.split()
d = collections.defaultdict(int, zip(words, itertools.count()))
- self.assertRegex(pprint.pformat(d),
-r"""defaultdict\(<class 'int' at 0x.+>,
+ self.assertEqual(pprint.pformat(d),
+"""\
+defaultdict(<class 'int'>,
{'a': 6,
'brown': 2,
'dog': 8,
@@ -861,7 +862,7 @@ r"""defaultdict\(<class 'int' at 0x.+>,
'lazy': 7,
'over': 5,
'quick': 1,
- 'the': 0}\)""")
+ 'the': 0})""")
def test_counter(self):
d = collections.Counter()
diff --git a/Lib/test/test_reprlib.py b/Lib/test/test_reprlib.py
index 2ecea02..4bf9194 100644
--- a/Lib/test/test_reprlib.py
+++ b/Lib/test/test_reprlib.py
@@ -292,8 +292,8 @@ class foo(object):
''')
importlib.invalidate_caches()
from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import foo
- self.assertRegex(repr(foo.foo),
- r"<class '%s.foo' at 0x.+>" % foo.__name__)
+ eq(repr(foo.foo),
+ "<class '%s.foo'>" % foo.__name__)
@unittest.skip('need a suitable object')
def test_object(self):
@@ -310,7 +310,7 @@ class bar:
importlib.invalidate_caches()
from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import bar
# Module name may be prefixed with "test.", depending on how run.
- self.assertRegex(repr(bar.bar), r"<class '%s.bar' at 0x.+>" % bar.__name__)
+ self.assertEqual(repr(bar.bar), "<class '%s.bar'>" % bar.__name__)
def test_instance(self):
self._check_path_limitations('baz')
diff --git a/Lib/test/test_statistics.py b/Lib/test/test_statistics.py
index 4e03d98..cccc1b9 100644
--- a/Lib/test/test_statistics.py
+++ b/Lib/test/test_statistics.py
@@ -659,7 +659,7 @@ class DocTests(unittest.TestCase):
@unittest.skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -OO and above")
def test_doc_tests(self):
- failed, tried = doctest.testmod(statistics, optionflags=doctest.ELLIPSIS)
+ failed, tried = doctest.testmod(statistics)
self.assertGreater(tried, 0)
self.assertEqual(failed, 0)
diff --git a/Lib/test/test_wsgiref.py b/Lib/test/test_wsgiref.py
index 3c5a27a..61a750c 100644
--- a/Lib/test/test_wsgiref.py
+++ b/Lib/test/test_wsgiref.py
@@ -165,10 +165,10 @@ class IntegrationTests(TestCase):
self.assertTrue(out.endswith(
b"A server error occurred. Please contact the administrator."
))
- self.assertRegex(
+ self.assertEqual(
err.splitlines()[-2],
- r"AssertionError: Headers \(\('Content-Type', 'text/plain'\)\) must"
- r" be of type list: <class 'tuple' at 0x.+>"
+ "AssertionError: Headers (('Content-Type', 'text/plain')) must"
+ " be of type list: <class 'tuple'>"
)
def test_status_validation_errors(self):
diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py
index f2fdc44..0773a86 100644
--- a/Lib/test/test_xmlrpc.py
+++ b/Lib/test/test_xmlrpc.py
@@ -775,8 +775,8 @@ class SimpleServerTestCase(BaseServerTestCase):
# 'method "this_is_not_exists" is not supported'>}]
self.assertEqual(result.results[0]['faultCode'], 1)
- self.assertRegex(result.results[0]['faultString'],
- '<class \'Exception\' at 0x.+>:method "this_is_not_exists" '
+ self.assertEqual(result.results[0]['faultString'],
+ '<class \'Exception\'>:method "this_is_not_exists" '
'is not supported')
except (xmlrpclib.ProtocolError, OSError) as e:
# ignore failures due to non-blocking socket 'unavailable' errors