summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2020-06-21 08:11:17 (GMT)
committerGitHub <noreply@github.com>2020-06-21 08:11:17 (GMT)
commitf9bab74d5b34c64cf061e1629ff5f3092a4ca9b3 (patch)
tree6300c872eefba9992cebe7ec5efccaa8ea0d8347 /Lib/test
parent19fcffa92773e008e4f5efb80047420a0cfafeec (diff)
downloadcpython-f9bab74d5b34c64cf061e1629ff5f3092a4ca9b3.zip
cpython-f9bab74d5b34c64cf061e1629ff5f3092a4ca9b3.tar.gz
cpython-f9bab74d5b34c64cf061e1629ff5f3092a4ca9b3.tar.bz2
bpo-41055: Remove outdated tests for the tp_print slot. (GH-21006)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/list_tests.py14
-rw-r--r--Lib/test/test_bool.py13
-rw-r--r--Lib/test/test_complex.py16
-rw-r--r--Lib/test/test_defaultdict.py33
-rw-r--r--Lib/test/test_deque.py37
-rw-r--r--Lib/test/test_descr.py7
-rw-r--r--Lib/test/test_set.py25
-rw-r--r--Lib/test/test_unicode.py16
8 files changed, 4 insertions, 157 deletions
diff --git a/Lib/test/list_tests.py b/Lib/test/list_tests.py
index 44bc2ae..f7eea88 100644
--- a/Lib/test/list_tests.py
+++ b/Lib/test/list_tests.py
@@ -66,20 +66,6 @@ class CommonTest(seq_tests.CommonTest):
a = self.type2test([a])
self.assertRaises(RecursionError, repr, a)
- def test_print(self):
- d = self.type2test(range(200))
- d.append(d)
- d.extend(range(200,400))
- d.append(d)
- d.append(400)
- try:
- with open(support.TESTFN, "w") as fo:
- fo.write(str(d))
- with open(support.TESTFN, "r") as fo:
- self.assertEqual(fo.read(), repr(d))
- finally:
- os.remove(support.TESTFN)
-
def test_set_subscript(self):
a = self.type2test(range(20))
self.assertRaises(ValueError, a.__setitem__, slice(0, 10, 0), [1,2,3])
diff --git a/Lib/test/test_bool.py b/Lib/test/test_bool.py
index 909a59a..4c6fba4 100644
--- a/Lib/test/test_bool.py
+++ b/Lib/test/test_bool.py
@@ -18,20 +18,11 @@ class BoolTest(unittest.TestCase):
self.assertRaises(TypeError, int.__new__, bool, 0)
- def test_print(self):
- try:
- with open(support.TESTFN, "w") as fo:
- print(False, True, file=fo)
- with open(support.TESTFN, "r") as fi:
- self.assertEqual(fi.read(), 'False True\n')
- finally:
- os.remove(support.TESTFN)
-
def test_repr(self):
self.assertEqual(repr(False), 'False')
self.assertEqual(repr(True), 'True')
- self.assertEqual(eval(repr(False)), False)
- self.assertEqual(eval(repr(True)), True)
+ self.assertIs(eval(repr(False)), False)
+ self.assertIs(eval(repr(True)), True)
def test_str(self):
self.assertEqual(str(False), 'False')
diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py
index dee5c7f..d1f241f 100644
--- a/Lib/test/test_complex.py
+++ b/Lib/test/test_complex.py
@@ -500,22 +500,6 @@ class ComplexTest(unittest.TestCase):
def test_neg(self):
self.assertEqual(-(1+6j), -1-6j)
- def test_file(self):
- a = 3.33+4.43j
- b = 5.1+2.3j
-
- fo = None
- try:
- fo = open(support.TESTFN, "w")
- print(a, b, file=fo)
- fo.close()
- fo = open(support.TESTFN, "r")
- self.assertEqual(fo.read(), ("%s %s\n" % (a, b)))
- finally:
- if (fo is not None) and (not fo.closed):
- fo.close()
- support.unlink(support.TESTFN)
-
def test_getnewargs(self):
self.assertEqual((1+2j).__getnewargs__(), (1.0, 2.0))
self.assertEqual((1-2j).__getnewargs__(), (1.0, -2.0))
diff --git a/Lib/test/test_defaultdict.py b/Lib/test/test_defaultdict.py
index b48c649..68fc449 100644
--- a/Lib/test/test_defaultdict.py
+++ b/Lib/test/test_defaultdict.py
@@ -72,27 +72,6 @@ class TestDefaultDict(unittest.TestCase):
d3[13]
self.assertEqual(repr(d3), "defaultdict(%s, {13: 43})" % repr(foo))
- def test_print(self):
- d1 = defaultdict()
- def foo(): return 42
- d2 = defaultdict(foo, {1: 2})
- # NOTE: We can't use tempfile.[Named]TemporaryFile since this
- # code must exercise the tp_print C code, which only gets
- # invoked for *real* files.
- tfn = tempfile.mktemp()
- try:
- f = open(tfn, "w+")
- try:
- print(d1, file=f)
- print(d2, file=f)
- f.seek(0)
- self.assertEqual(f.readline(), repr(d1) + "\n")
- self.assertEqual(f.readline(), repr(d2) + "\n")
- finally:
- f.close()
- finally:
- os.remove(tfn)
-
def test_copy(self):
d1 = defaultdict()
d2 = d1.copy()
@@ -160,18 +139,6 @@ class TestDefaultDict(unittest.TestCase):
r"sub\(<bound method .*sub\._factory "
r"of sub\(\.\.\., \{\}\)>, \{\}\)")
- # NOTE: printing a subclass of a builtin type does not call its
- # tp_print slot. So this part is essentially the same test as above.
- tfn = tempfile.mktemp()
- try:
- f = open(tfn, "w+")
- try:
- print(d, file=f)
- finally:
- f.close()
- finally:
- os.remove(tfn)
-
def test_callable_arg(self):
self.assertRaises(TypeError, defaultdict, {})
diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py
index c0f7138..93cc6ca 100644
--- a/Lib/test/test_deque.py
+++ b/Lib/test/test_deque.py
@@ -66,28 +66,9 @@ class TestBasic(unittest.TestCase):
self.assertEqual(list(d), [7, 8, 9])
d = deque(range(200), maxlen=10)
d.append(d)
- support.unlink(support.TESTFN)
- fo = open(support.TESTFN, "w")
- try:
- fo.write(str(d))
- fo.close()
- fo = open(support.TESTFN, "r")
- self.assertEqual(fo.read(), repr(d))
- finally:
- fo.close()
- support.unlink(support.TESTFN)
-
+ self.assertEqual(repr(d)[-30:], ', 198, 199, [...]], maxlen=10)')
d = deque(range(10), maxlen=None)
self.assertEqual(repr(d), 'deque([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])')
- fo = open(support.TESTFN, "w")
- try:
- fo.write(str(d))
- fo.close()
- fo = open(support.TESTFN, "r")
- self.assertEqual(fo.read(), repr(d))
- finally:
- fo.close()
- support.unlink(support.TESTFN)
def test_maxlen_zero(self):
it = iter(range(100))
@@ -545,21 +526,7 @@ class TestBasic(unittest.TestCase):
e = eval(repr(d))
self.assertEqual(list(d), list(e))
d.append(d)
- self.assertIn('...', repr(d))
-
- def test_print(self):
- d = deque(range(200))
- d.append(d)
- try:
- support.unlink(support.TESTFN)
- fo = open(support.TESTFN, "w")
- print(d, file=fo, end='')
- fo.close()
- fo = open(support.TESTFN, "r")
- self.assertEqual(fo.read(), repr(d))
- finally:
- fo.close()
- support.unlink(support.TESTFN)
+ self.assertEqual(repr(d)[-20:], '7, 198, 199, [...]])')
def test_init(self):
self.assertRaises(TypeError, deque, 'abc', 2, 3);
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 96cc8de2..7bb6f2b 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -3552,13 +3552,6 @@ order (MRO) for bases """
self.assertEqual(o.__str__(), '41')
self.assertEqual(o.__repr__(), 'A repr')
- capture = io.StringIO()
- # Calling str() or not exercises different internal paths.
- print(o, file=capture)
- print(str(o), file=capture)
- self.assertEqual(capture.getvalue(), '41\n41\n')
- capture.close()
-
def test_keyword_arguments(self):
# Testing keyword arguments to __init__, __call__...
def f(a): return a
diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py
index e4766ab..9851a99 100644
--- a/Lib/test/test_set.py
+++ b/Lib/test/test_set.py
@@ -317,20 +317,6 @@ class TestJointOps:
name = repr(s).partition('(')[0] # strip class name
self.assertEqual(repr(s), '%s({%s(...)})' % (name, name))
- def test_cyclical_print(self):
- w = ReprWrapper()
- s = self.thetype([w])
- w.value = s
- fo = open(support.TESTFN, "w")
- try:
- fo.write(str(s))
- fo.close()
- fo = open(support.TESTFN, "r")
- self.assertEqual(fo.read(), repr(s))
- finally:
- fo.close()
- support.unlink(support.TESTFN)
-
def test_do_not_rehash_dict_keys(self):
n = 10
d = dict.fromkeys(map(HashCountingInt, range(n)))
@@ -803,17 +789,6 @@ class TestBasicOps:
sorted_repr_values.sort()
self.assertEqual(result, sorted_repr_values)
- def test_print(self):
- try:
- fo = open(support.TESTFN, "w")
- fo.write(str(self.set))
- fo.close()
- fo = open(support.TESTFN, "r")
- self.assertEqual(fo.read(), repr(self.set))
- finally:
- fo.close()
- support.unlink(support.TESTFN)
-
def test_length(self):
self.assertEqual(len(self.set), self.length)
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 2ee4e64..6e39716 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -2215,22 +2215,6 @@ class UnicodeTest(string_tests.CommonTest,
self.assertEqual(("abc" "def" "ghi"), "abcdefghi")
self.assertEqual(("abc" "def" "ghi"), "abcdefghi")
- def test_printing(self):
- class BitBucket:
- def write(self, text):
- pass
-
- out = BitBucket()
- print('abc', file=out)
- print('abc', 'def', file=out)
- print('abc', 'def', file=out)
- print('abc', 'def', file=out)
- print('abc\n', file=out)
- print('abc\n', end=' ', file=out)
- print('abc\n', end=' ', file=out)
- print('def\n', file=out)
- print('def\n', file=out)
-
def test_ucs4(self):
x = '\U00100000'
y = x.encode("raw-unicode-escape").decode("raw-unicode-escape")