test_byteflow.py 2.37 KB
Newer Older
dugupeiwen's avatar
dugupeiwen committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""
Test byteflow.py specific issues
"""
import unittest

from numba.tests.support import TestCase
from numba.core.compiler import run_frontend


class TestByteFlowIssues(TestCase):
    def test_issue_5087(self):
        # This is an odd issue. The exact number of print below is
        # necessary to trigger it. Too many or too few will alter the behavior.
        # Also note that the function below will not be executed. The problem
        # occurs at compilation. The definition below is invalid for execution.
        # The problem occurs in the bytecode analysis.
        def udt():
            print
            print
            print

            for i in range:
                print
                print
                print
                print
                print
                print
                print
                print
                print
                print
                print
                print
                print
                print
                print
                print
                print
                print

                for j in range:
                    print
                    print
                    print
                    print
                    print
                    print
                    print
                    for k in range:
                        for l in range:
                            print

                    print
                    print
                    print
                    print
                    print
                    print
                    print
                    print
                    print
                    if print:
                        for n in range:
                            print
                    else:
                        print

        run_frontend(udt)

    def test_issue_5097(self):
        # Inspired by https://github.com/numba/numba/issues/5097
        def udt():
            for i in range(0):
                if i > 0:
                    pass
                a = None # noqa: F841

        run_frontend(udt)

    def test_issue_5680(self):
        # From https://github.com/numba/numba/issues/5680#issuecomment-625351336
        def udt():
            for k in range(0):
                if 1 == 1:
                    ...
                if 'a' == 'a':
                    ...

        run_frontend(udt)


if __name__ == '__main__':
    unittest.main()