Skip to content

Commit 2eeb31b

Browse files
committed
Python: Add tests for lazy from ... import * as well
1 parent 86020d9 commit 2eeb31b

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

python/ql/test/3/extractor-tests/lazy-imports/test.expected

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
| 4 | Import | lazy |
44
| 5 | Import | lazy |
55
| 6 | Import | lazy |
6-
| 9 | Import | normal |
6+
| 7 | from l import * | lazy |
77
| 10 | Import | normal |
8+
| 11 | Import | normal |
9+
| 12 | from w import * | normal |

python/ql/test/3/extractor-tests/lazy-imports/test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
lazy from d import e as f
55
lazy import g.h as i
66
lazy from ..j import k
7+
lazy from l import *
78

89
# Non-lazy imports
910
import x
1011
from y import z
12+
from w import *
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import python
22

3-
string lazy(Import imp) { if imp.isLazy() then result = "lazy" else result = "normal" }
3+
string lazy(Stmt s) {
4+
if s.(Import).isLazy() or s.(ImportStar).isLazy() then result = "lazy" else result = "normal"
5+
}
46

5-
from Import imp
6-
where imp.getLocation().getFile().getShortName() = "test.py"
7-
select imp.getLocation().getStartLine(), imp.toString(), lazy(imp)
7+
from Stmt s
8+
where
9+
s.getLocation().getFile().getShortName() = "test.py" and
10+
(s instanceof Import or s instanceof ImportStar)
11+
select s.getLocation().getStartLine(), s.toString(), lazy(s)

0 commit comments

Comments
 (0)