summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_embed.py
diff options
context:
space:
mode:
authorJeremy Kloth <jeremy.kloth@gmail.com>2022-03-22 12:53:51 (GMT)
committerGitHub <noreply@github.com>2022-03-22 12:53:51 (GMT)
commit88872a29f19092d2fde27365af230abd6d301941 (patch)
treec3b3f338395d4f3015cf1e9c37689a30019126b1 /Lib/test/test_embed.py
parent7d810b6a4eab6eba689acc5bb05f85515478d690 (diff)
downloadcpython-88872a29f19092d2fde27365af230abd6d301941.zip
cpython-88872a29f19092d2fde27365af230abd6d301941.tar.gz
cpython-88872a29f19092d2fde27365af230abd6d301941.tar.bz2
bpo-47084: Clear Unicode cached representations on finalization (GH-32032)
Diffstat (limited to 'Lib/test/test_embed.py')
-rw-r--r--Lib/test/test_embed.py41
1 files changed, 23 insertions, 18 deletions
diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py
index 80b9674..f0c88de 100644
--- a/Lib/test/test_embed.py
+++ b/Lib/test/test_embed.py
@@ -1645,24 +1645,29 @@ class MiscTests(EmbeddingTestsMixin, unittest.TestCase):
'-X showrefcount requires a Python debug build')
def test_no_memleak(self):
# bpo-1635741: Python must release all memory at exit
- cmd = [sys.executable, "-I", "-X", "showrefcount", "-c", "pass"]
- proc = subprocess.run(cmd,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT,
- text=True)
- self.assertEqual(proc.returncode, 0)
- out = proc.stdout.rstrip()
- match = re.match(r'^\[(-?\d+) refs, (-?\d+) blocks\]', out)
- if not match:
- self.fail(f"unexpected output: {out!a}")
- refs = int(match.group(1))
- blocks = int(match.group(2))
- self.assertEqual(refs, 0, out)
- if not MS_WINDOWS:
- self.assertEqual(blocks, 0, out)
- else:
- # bpo-46857: on Windows, Python still leaks 1 memory block at exit
- self.assertIn(blocks, (0, 1), out)
+ tests = (
+ ('off', 'pass'),
+ ('on', 'pass'),
+ ('off', 'import __hello__'),
+ ('on', 'import __hello__'),
+ )
+ for flag, stmt in tests:
+ xopt = f"frozen_modules={flag}"
+ cmd = [sys.executable, "-I", "-X", "showrefcount", "-X", xopt, "-c", stmt]
+ proc = subprocess.run(cmd,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
+ text=True)
+ self.assertEqual(proc.returncode, 0)
+ out = proc.stdout.rstrip()
+ match = re.match(r'^\[(-?\d+) refs, (-?\d+) blocks\]', out)
+ if not match:
+ self.fail(f"unexpected output: {out!a}")
+ refs = int(match.group(1))
+ blocks = int(match.group(2))
+ with self.subTest(frozen_modules=flag, stmt=stmt):
+ self.assertEqual(refs, 0, out)
+ self.assertEqual(blocks, 0, out)
class StdPrinterTests(EmbeddingTestsMixin, unittest.TestCase):