diff options
author | Benjamin Peterson <benjamin@python.org> | 2011-05-27 14:08:01 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2011-05-27 14:08:01 (GMT) |
commit | 43b068648e81d951f78d9f1cf1cd8f42731e164e (patch) | |
tree | 0273084c3e9fb5d29656265d0c59ccbccb73a99d /Lib | |
parent | d408503b2c74b53f734adab6cd35866be460ce5e (diff) | |
download | cpython-43b068648e81d951f78d9f1cf1cd8f42731e164e.zip cpython-43b068648e81d951f78d9f1cf1cd8f42731e164e.tar.gz cpython-43b068648e81d951f78d9f1cf1cd8f42731e164e.tar.bz2 |
try to use the same str object for all code filenames when compiling or unmarshalling (#12190)
This should reduce memory usage.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_compile.py | 9 | ||||
-rw-r--r-- | Lib/test/test_marshal.py | 17 |
2 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index 58ef297..c5f9189 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -1,6 +1,7 @@ import unittest import sys import _ast +import types from test import support class TestSpecifics(unittest.TestCase): @@ -433,6 +434,14 @@ if 1: ast.body = [_ast.BoolOp()] self.assertRaises(TypeError, compile, ast, '<ast>', 'exec') + @support.cpython_only + def test_same_filename_used(self): + s = """def f(): pass\ndef g(): pass""" + c = compile(s, "myfile", "exec") + for obj in c.co_consts: + if isinstance(obj, types.CodeType): + self.assertIs(obj.co_filename, c.co_filename) + def test_main(): support.run_unittest(TestSpecifics) diff --git a/Lib/test/test_marshal.py b/Lib/test/test_marshal.py index 81cf598..8a5590a 100644 --- a/Lib/test/test_marshal.py +++ b/Lib/test/test_marshal.py @@ -5,6 +5,7 @@ import marshal import sys import unittest import os +import types class HelperMixin: def helper(self, sample, *extra): @@ -113,6 +114,22 @@ class CodeTestCase(unittest.TestCase): codes = (ExceptionTestCase.test_exceptions.__code__,) * count marshal.loads(marshal.dumps(codes)) + def test_different_filenames(self): + co1 = compile("x", "f1", "exec") + co2 = compile("y", "f2", "exec") + co1, co2 = marshal.loads(marshal.dumps((co1, co2))) + self.assertEqual(co1.co_filename, "f1") + self.assertEqual(co2.co_filename, "f2") + + @support.cpython_only + def test_same_filename_used(self): + s = """def f(): pass\ndef g(): pass""" + co = compile(s, "myfile", "exec") + co = marshal.loads(marshal.dumps(co)) + for obj in co.co_consts: + if isinstance(obj, types.CodeType): + self.assertIs(co.co_filename, obj.co_filename) + class ContainerTestCase(unittest.TestCase, HelperMixin): d = {'astring': 'foo@bar.baz.spam', 'afloat': 7283.43, |