File tree Expand file tree Collapse file tree 2 files changed +34
-7
lines changed Expand file tree Collapse file tree 2 files changed +34
-7
lines changed Original file line number Diff line number Diff line change 6
6
print ("SKIP" )
7
7
raise SystemExit
8
8
9
- try :
10
- import warnings
11
- warnings .simplefilter ("ignore" ) # ignore deprecation warning about co_lnotab
12
- except ImportError :
13
- pass
14
-
15
9
def f (x , y ):
16
10
a = x + y
17
11
b = x - y
@@ -25,7 +19,6 @@ def f(x, y):
25
19
print (type (code .co_firstlineno )) # both ints (but mpy points to first line inside, cpy points to declaration)
26
20
print (code .co_name )
27
21
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
29
22
30
23
co_lines = code .co_lines ()
31
24
Original file line number Diff line number Diff line change
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 ()
You can’t perform that action at this time.
0 commit comments