From f9bab74d5b34c64cf061e1629ff5f3092a4ca9b3 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 21 Jun 2020 11:11:17 +0300 Subject: [PATCH] bpo-41055: Remove outdated tests for the tp_print slot. (GH-21006) --- Lib/test/list_tests.py | 14 -------------- Lib/test/test_bool.py | 13 ++----------- Lib/test/test_complex.py | 16 ---------------- Lib/test/test_defaultdict.py | 33 -------------------------------- Lib/test/test_deque.py | 37 ++---------------------------------- Lib/test/test_descr.py | 7 ------- Lib/test/test_set.py | 25 ------------------------ Lib/test/test_unicode.py | 16 ---------------- 8 files changed, 4 insertions(+), 157 deletions(-) diff --git a/Lib/test/list_tests.py b/Lib/test/list_tests.py index 44bc2ae6573..f7eea88c54a 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 909a59a9d2a..4c6fba42c0c 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 dee5c7fa308..d1f241f7a60 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 b48c649fce6..68fc449780a 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\(, \{\}\)") - # 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 c0f7138254f..93cc6ca4f44 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 96cc8de2d98..7bb6f2bb4b3 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 e4766ab190b..9851a998983 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 2ee4e64d635..6e397161fd9 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")