mirror of
https://github.com/micropython/micropython.git
synced 2025-08-07 19:21:50 +02:00
tests/basics/fun_code_lnotab: Test removal of co_lnotab from v2.
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
This commit is contained in:
@@ -6,12 +6,6 @@ except AttributeError:
|
|||||||
print("SKIP")
|
print("SKIP")
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
|
||||||
try:
|
|
||||||
import warnings
|
|
||||||
warnings.simplefilter("ignore") # ignore deprecation warning about co_lnotab
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def f(x, y):
|
def f(x, y):
|
||||||
a = x + y
|
a = x + y
|
||||||
b = x - y
|
b = x - y
|
||||||
@@ -25,7 +19,6 @@ print(code.co_filename.rsplit('/')[-1]) # same terminal filename but might be di
|
|||||||
print(type(code.co_firstlineno)) # both ints (but mpy points to first line inside, cpy points to declaration)
|
print(type(code.co_firstlineno)) # both ints (but mpy points to first line inside, cpy points to declaration)
|
||||||
print(code.co_name)
|
print(code.co_name)
|
||||||
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)
|
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)
|
||||||
print(type(code.co_lnotab)) # both bytes
|
|
||||||
|
|
||||||
co_lines = code.co_lines()
|
co_lines = code.co_lines()
|
||||||
|
|
||||||
|
34
tests/basics/fun_code_lnotab.py
Normal file
34
tests/basics/fun_code_lnotab.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
# Test deprecation of co_lnotab
|
||||||
|
|
||||||
|
try:
|
||||||
|
(lambda: 0).__code__.co_code
|
||||||
|
except AttributeError:
|
||||||
|
print("SKIP")
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
mpy_is_v2 = getattr(sys.implementation, '_v2', False)
|
||||||
|
|
||||||
|
|
||||||
|
def f():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Test(unittest.TestCase):
|
||||||
|
|
||||||
|
@unittest.skipIf(mpy_is_v2, "Removed in MicroPython v2 and later.")
|
||||||
|
def test_co_lnotab_exists(self):
|
||||||
|
self.assertIsInstance(f.__code__.co_lnotab, bytes)
|
||||||
|
|
||||||
|
@unittest.skipUnless(mpy_is_v2, "Not removed before MicroPython v2.")
|
||||||
|
def test_co_lnotab_removed(self):
|
||||||
|
with self.assertRaises(AttributeError):
|
||||||
|
f.__code__.co_lnotab
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
Reference in New Issue
Block a user