summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_code.py
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@gmail.com>2022-08-01 18:02:56 (GMT)
committerGitHub <noreply@github.com>2022-08-01 18:02:56 (GMT)
commitc7e5bbaee88a71dc6e633e3cd451ed1798436382 (patch)
treebc1fd93fbb18b2745ebc1956ea5448a19f5bbdf1 /Lib/test/test_code.py
parenta95e60db748ec6f2c19b5710c11f62e1e4d669f4 (diff)
downloadcpython-c7e5bbaee88a71dc6e633e3cd451ed1798436382.zip
cpython-c7e5bbaee88a71dc6e633e3cd451ed1798436382.tar.gz
cpython-c7e5bbaee88a71dc6e633e3cd451ed1798436382.tar.bz2
GH-95150: Use position and exception tables for code hashing and equality (GH-95509)
Diffstat (limited to 'Lib/test/test_code.py')
-rw-r--r--Lib/test/test_code.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_code.py b/Lib/test/test_code.py
index fd68f6d..2386cf6 100644
--- a/Lib/test/test_code.py
+++ b/Lib/test/test_code.py
@@ -428,6 +428,27 @@ class CodeTest(unittest.TestCase):
self.assertIsNone(line)
self.assertEqual(end_line, new_code.co_firstlineno + 1)
+ def test_code_equality(self):
+ def f():
+ try:
+ a()
+ except:
+ b()
+ else:
+ c()
+ finally:
+ d()
+ code_a = f.__code__
+ code_b = code_a.replace(co_linetable=b"")
+ code_c = code_a.replace(co_exceptiontable=b"")
+ code_d = code_b.replace(co_exceptiontable=b"")
+ self.assertNotEqual(code_a, code_b)
+ self.assertNotEqual(code_a, code_c)
+ self.assertNotEqual(code_a, code_d)
+ self.assertNotEqual(code_b, code_c)
+ self.assertNotEqual(code_b, code_d)
+ self.assertNotEqual(code_c, code_d)
+
def isinterned(s):
return s is sys.intern(('_' + s + '_')[1:-1])