[Python-checkins] bpo-41055: Remove outdated tests for the tp_print slot. (GH-21006)

Serhiy Storchaka webhook-mailer at python.org
Sun Jun 21 04:11:22 EDT 2020


https://github.com/python/cpython/commit/f9bab74d5b34c64cf061e1629ff5f3092a4ca9b3
commit: f9bab74d5b34c64cf061e1629ff5f3092a4ca9b3
branch: master
author: Serhiy Storchaka <storchaka at gmail.com>
committer: GitHub <noreply at github.com>
date: 2020-06-21T11:11:17+03:00
summary:

bpo-41055: Remove outdated tests for the tp_print slot. (GH-21006)

files:
M Lib/test/list_tests.py
M Lib/test/test_bool.py
M Lib/test/test_complex.py
M Lib/test/test_defaultdict.py
M Lib/test/test_deque.py
M Lib/test/test_descr.py
M Lib/test/test_set.py
M Lib/test/test_unicode.py

diff --git a/Lib/test/list_tests.py b/Lib/test/list_tests.py
index 44bc2ae6573c1..f7eea88c54a6a 100644
--- a/Lib/test/list_tests.py
+++ b/Lib/test/list_tests.py
@@ -66,20 +66,6 @@ def test_repr_deep(self):
             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 909a59a9d2af6..4c6fba42c0c57 100644
--- a/Lib/test/test_bool.py
+++ b/Lib/test/test_bool.py
@@ -18,20 +18,11 @@ class C(bool):
 
         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 dee5c7fa308bd..d1f241f7a60c9 100644
--- a/Lib/test/test_complex.py
+++ b/Lib/test/test_complex.py
@@ -500,22 +500,6 @@ def test(v, expected, test_fn=self.assertEqual):
     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 b48c649fce6ba..68fc449780a3d 100644
--- a/Lib/test/test_defaultdict.py
+++ b/Lib/test/test_defaultdict.py
@@ -72,27 +72,6 @@ def foo(): return 43
         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 @@ def _factory(self):
             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 c0f7138254f3f..93cc6ca4f44ec 100644
--- a/Lib/test/test_deque.py
+++ b/Lib/test/test_deque.py
@@ -66,28 +66,9 @@ def test_maxlen(self):
         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 @@ def test_repr(self):
         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 96cc8de2d98fb..7bb6f2bb4b30b 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -3552,13 +3552,6 @@ def __repr__(self):
         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 e4766ab190be0..9851a998983f8 100644
--- a/Lib/test/test_set.py
+++ b/Lib/test/test_set.py
@@ -317,20 +317,6 @@ def test_cyclical_repr(self):
             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 @@ def check_repr_against_values(self):
         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 2ee4e64d63530..6e397161fd98d 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -2215,22 +2215,6 @@ def test_concatenation(self):
         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")



More information about the Python-checkins mailing list