diff options
| author | Zev Benjamin <zev@dropbox.com> | 2015-09-24 15:08:48 -0700 |
|---|---|---|
| committer | Zev Benjamin <zev@dropbox.com> | 2015-09-24 15:30:07 -0700 |
| commit | cf1a9ac320717f5db042130eb995e42f1e3d3a6c (patch) | |
| tree | 0345a4f754d595c229650591da8b0294c58e1c1e /src/tests | |
| parent | e13cf0704b7c28f1de1e71cb7c59b47a84daa9ca (diff) | |
| download | python-decorator-git-cf1a9ac320717f5db042130eb995e42f1e3d3a6c.tar.gz | |
Ensure each generated function has a unique filename
Some profilers (such as cProfile) depend on the tuple of (<filename>,
<definition line>, <function name>) being unique. If the filenames of generated
functions are all the same, such profilers can produce incorrect profiles.
Diffstat (limited to 'src/tests')
| -rw-r--r-- | src/tests/test.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/tests/test.py b/src/tests/test.py index 45a9b9b..ab65dfa 100644 --- a/src/tests/test.py +++ b/src/tests/test.py @@ -6,7 +6,7 @@ import decimal import inspect import functools import collections -from decorator import dispatch_on, contextmanager +from decorator import dispatch_on, contextmanager, decorator try: from . import documentation as doc except (SystemError, ValueError): @@ -52,6 +52,33 @@ class ExtraTestCase(unittest.TestCase): sig = inspect.signature(doc.f1) self.assertEqual(str(sig), '(x)') + def test_unique_filenames(self): + @decorator + def d1(f, *args, **kwargs): + return f(*args, **kwargs) + + @decorator + def d2(f, *args, **kwargs): + return f(*args, **kwargs) + + @d1 + def f1(x, y, z): + pass + + @d2 + def f2(x, y, z): + pass + + f1_orig = f1 + + @d1 + def f1(x, y, z): + pass + + self.assertNotEqual(d1.__code__.co_filename, d2.__code__.co_filename) + self.assertNotEqual(f1.__code__.co_filename, f2.__code__.co_filename) + self.assertNotEqual(f1_orig.__code__.co_filename, f1.__code__.co_filename) + # ################### test dispatch_on ############################# # # adapted from test_functools in Python 3.5 singledispatch = dispatch_on('obj') |
