diff options
author | Steve Dower <steve.dower@microsoft.com> | 2017-02-04 15:39:38 -0800 |
---|---|---|
committer | Steve Dower <steve.dower@microsoft.com> | 2017-02-04 15:39:38 -0800 |
commit | 1a5780aabb550cae175ad8711e2f33ba644d0ddb (patch) | |
tree | 68e47eaafb4ccc17bbdb7668c6058984945b332d /Lib/test/test_opcodes.py | |
parent | 956c7cfa7111ab5458e2f69868a05b7b84fc6843 (diff) | |
parent | d1d8706cdb77e2adbbb4110338dcda0e1811f892 (diff) | |
download | cpython-1a5780aabb550cae175ad8711e2f33ba644d0ddb.tar.gz |
Issue #29319: Prevent RunMainFromImporter overwriting sys.path[0].
Diffstat (limited to 'Lib/test/test_opcodes.py')
-rw-r--r-- | Lib/test/test_opcodes.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_opcodes.py b/Lib/test/test_opcodes.py index 6ef93d9500..6806c616cb 100644 --- a/Lib/test/test_opcodes.py +++ b/Lib/test/test_opcodes.py @@ -1,6 +1,7 @@ # Python test set -- part 2, opcodes import unittest +from test import ann_module class OpcodeTest(unittest.TestCase): @@ -20,6 +21,32 @@ class OpcodeTest(unittest.TestCase): if n != 90: self.fail('try inside for') + def test_setup_annotations_line(self): + # check that SETUP_ANNOTATIONS does not create spurious line numbers + try: + with open(ann_module.__file__) as f: + txt = f.read() + co = compile(txt, ann_module.__file__, 'exec') + self.assertEqual(co.co_firstlineno, 6) + except OSError: + pass + + def test_no_annotations_if_not_needed(self): + class C: pass + with self.assertRaises(AttributeError): + C.__annotations__ + + def test_use_existing_annotations(self): + ns = {'__annotations__': {1: 2}} + exec('x: int', ns) + self.assertEqual(ns['__annotations__'], {'x': int, 1: 2}) + + def test_do_not_recreate_annotations(self): + class C: + del __annotations__ + with self.assertRaises(NameError): + x: int + def test_raise_class_exceptions(self): class AClass(Exception): pass |