diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2024-04-02 23:16:50 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-02 23:16:50 (GMT) |
commit | 857d3151c9efa029268e8249e91d26eb1b31c2fd (patch) | |
tree | f2a6b3d675c1141dee34711334e483fac6b96aeb /Lib/test/test_interpreters/utils.py | |
parent | f341d6017dd4e80509b69b5a9e2625b71b70f205 (diff) | |
download | cpython-857d3151c9efa029268e8249e91d26eb1b31c2fd.zip cpython-857d3151c9efa029268e8249e91d26eb1b31c2fd.tar.gz cpython-857d3151c9efa029268e8249e91d26eb1b31c2fd.tar.bz2 |
gh-76785: Consolidate Some Interpreter-related Testing Helpers (gh-117485)
This eliminates the duplication of functionally identical helpers in the _testinternalcapi and _xxsubinterpreters modules.
Diffstat (limited to 'Lib/test/test_interpreters/utils.py')
-rw-r--r-- | Lib/test/test_interpreters/utils.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/Lib/test/test_interpreters/utils.py b/Lib/test/test_interpreters/utils.py index 973d05d..5ade676 100644 --- a/Lib/test/test_interpreters/utils.py +++ b/Lib/test/test_interpreters/utils.py @@ -68,6 +68,9 @@ def _running(interp): class TestBase(unittest.TestCase): + def tearDown(self): + clean_up_interpreters() + def pipe(self): def ensure_closed(fd): try: @@ -156,5 +159,19 @@ class TestBase(unittest.TestCase): self.assertNotEqual(exitcode, 0) return stdout, stderr - def tearDown(self): - clean_up_interpreters() + def assert_ns_equal(self, ns1, ns2, msg=None): + # This is mostly copied from TestCase.assertDictEqual. + self.assertEqual(type(ns1), type(ns2)) + if ns1 == ns2: + return + + import difflib + import pprint + from unittest.util import _common_shorten_repr + standardMsg = '%s != %s' % _common_shorten_repr(ns1, ns2) + diff = ('\n' + '\n'.join(difflib.ndiff( + pprint.pformat(vars(ns1)).splitlines(), + pprint.pformat(vars(ns2)).splitlines()))) + diff = f'namespace({diff})' + standardMsg = self._truncateMessage(standardMsg, diff) + self.fail(self._formatMessage(msg, standardMsg)) |