Skip to content

Commit 7b38fa4

Browse files
committed
tests/basics/fun_code_lnotab: Test removal of co_lnotab from v2.
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
1 parent 17fbc5a commit 7b38fa4

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

tests/basics/fun_code_full.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
print("SKIP")
77
raise SystemExit
88

9-
try:
10-
import warnings
11-
warnings.simplefilter("ignore") # ignore deprecation warning about co_lnotab
12-
except ImportError:
13-
pass
14-
159
def f(x, y):
1610
a = x + y
1711
b = x - y
@@ -25,7 +19,6 @@ def f(x, y):
2519
print(type(code.co_firstlineno)) # both ints (but mpy points to first line inside, cpy points to declaration)
2620
print(code.co_name)
2721
print(iter(code.co_names) is not None) # both iterable (but mpy returns dict with names as keys, cpy only the names; and not necessarily the same set)
28-
print(type(code.co_lnotab)) # both bytes
2922

3023
co_lines = code.co_lines()
3124

tests/basics/fun_code_lnotab.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Test deprecation of co_lnotab
2+
3+
try:
4+
(lambda: 0).__code__.co_code
5+
except AttributeError:
6+
print("SKIP")
7+
raise SystemExit
8+
9+
10+
import unittest
11+
import sys
12+
13+
14+
mpy_is_v2 = getattr(sys.implementation, '_v2', False)
15+
16+
17+
def f():
18+
pass
19+
20+
21+
class Test(unittest.TestCase):
22+
23+
@unittest.skipIf(mpy_is_v2, "Removed in MicroPython v2 and later.")
24+
def test_co_lnotab_exists(self):
25+
self.assertIsInstance(f.__code__.co_lnotab, bytes)
26+
27+
@unittest.skipUnless(mpy_is_v2, "Not removed before MicroPython v2.")
28+
def test_co_lnotab_removed(self):
29+
with self.assertRaises(AttributeError):
30+
f.__code__.co_lnotab
31+
32+
33+
if __name__ == "__main__":
34+
unittest.main()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy