diff options
author | Max Bernstein <tekknolagi@users.noreply.github.com> | 2019-05-21 17:09:21 (GMT) |
---|---|---|
committer | Dino Viehland <dinoviehland@fb.com> | 2019-05-21 17:09:21 (GMT) |
commit | ccb7ca728e09b307f9e9fd36ec40353137e68a3b (patch) | |
tree | 9e6f4e0a52d338e950c8e6a729c5dffa7197ae2d /Lib/test/test_io.py | |
parent | ad098b6750f4d74387ac21c8e23ae1ee7ff13571 (diff) | |
download | cpython-ccb7ca728e09b307f9e9fd36ec40353137e68a3b.zip cpython-ccb7ca728e09b307f9e9fd36ec40353137e68a3b.tar.gz cpython-ccb7ca728e09b307f9e9fd36ec40353137e68a3b.tar.bz2 |
bpo-36929: Modify io/re tests to allow for missing mod name (#13392)
* bpo-36929: Modify io/re tests to allow for missing mod name
For a vanishingly small number of internal types, CPython sets the
tp_name slot to mod_name.type_name, either in the PyTypeObject or the
PyType_Spec. There are a few minor places where this surfaces:
* Custom repr functions for those types (some of which ignore the
tp_name in favor of using a string literal, such as _io.TextIOWrapper)
* Pickling error messages
The test suite only tests the former. This commit modifies the test
suite to allow Python implementations to omit the module prefix.
https://bugs.python.org/issue36929
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r-- | Lib/test/test_io.py | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 5406a28..dc44e50 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -1119,12 +1119,12 @@ class CommonBufferedTests: def test_repr(self): raw = self.MockRawIO() b = self.tp(raw) - clsname = "%s.%s" % (self.tp.__module__, self.tp.__qualname__) - self.assertEqual(repr(b), "<%s>" % clsname) + clsname = r"(%s\.)?%s" % (self.tp.__module__, self.tp.__qualname__) + self.assertRegex(repr(b), "<%s>" % clsname) raw.name = "dummy" - self.assertEqual(repr(b), "<%s name='dummy'>" % clsname) + self.assertRegex(repr(b), "<%s name='dummy'>" % clsname) raw.name = b"dummy" - self.assertEqual(repr(b), "<%s name=b'dummy'>" % clsname) + self.assertRegex(repr(b), "<%s name=b'dummy'>" % clsname) def test_recursive_repr(self): # Issue #25455 @@ -2598,17 +2598,17 @@ class TextIOWrapperTest(unittest.TestCase): b = self.BufferedReader(raw) t = self.TextIOWrapper(b, encoding="utf-8") modname = self.TextIOWrapper.__module__ - self.assertEqual(repr(t), - "<%s.TextIOWrapper encoding='utf-8'>" % modname) + self.assertRegex(repr(t), + r"<(%s\.)?TextIOWrapper encoding='utf-8'>" % modname) raw.name = "dummy" - self.assertEqual(repr(t), - "<%s.TextIOWrapper name='dummy' encoding='utf-8'>" % modname) + self.assertRegex(repr(t), + r"<(%s\.)?TextIOWrapper name='dummy' encoding='utf-8'>" % modname) t.mode = "r" - self.assertEqual(repr(t), - "<%s.TextIOWrapper name='dummy' mode='r' encoding='utf-8'>" % modname) + self.assertRegex(repr(t), + r"<(%s\.)?TextIOWrapper name='dummy' mode='r' encoding='utf-8'>" % modname) raw.name = b"dummy" - self.assertEqual(repr(t), - "<%s.TextIOWrapper name=b'dummy' mode='r' encoding='utf-8'>" % modname) + self.assertRegex(repr(t), + r"<(%s\.)?TextIOWrapper name=b'dummy' mode='r' encoding='utf-8'>" % modname) t.buffer.detach() repr(t) # Should not raise an exception @@ -4174,11 +4174,11 @@ class CMiscIOTest(MiscIOTest): err = res.err.decode() if res.rc != 0: # Failure: should be a fatal error - self.assertIn("Fatal Python error: could not acquire lock " - "for <_io.BufferedWriter name='<{stream_name}>'> " - "at interpreter shutdown, possibly due to " - "daemon threads".format_map(locals()), - err) + pattern = (r"Fatal Python error: could not acquire lock " + r"for <(_io\.)?BufferedWriter name='<{stream_name}>'> " + r"at interpreter shutdown, possibly due to " + r"daemon threads".format_map(locals())) + self.assertRegex(err, pattern) else: self.assertFalse(err.strip('.!')) |