Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 97294e1

Browse files
committed
Python: Update tests to account for improved API.
1 parent 3b31b9c commit 97294e1

10 files changed

Lines changed: 72 additions & 72 deletions

File tree

python/ql/src/semmle/python/objects/Classes.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ private import semmle.python.types.Builtins
1111
/** Class representing classes */
1212
abstract class ClassObjectInternal extends ObjectInternal {
1313

14-
string getName() {
14+
override string getName() {
1515
result = this.getClassDeclaration().getName()
1616
}
1717

python/ql/src/semmle/python/pointsto/MRO.qll

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,18 @@ class ClassList extends TClassList {
8080
or
8181
exists(ClassObjectInternal head |
8282
head = this.getHead() |
83-
this.getTail() = Empty() and result = head.getName()
83+
this.getTail() = Empty() and result = className(head)
8484
or
85-
this.getTail() != Empty() and result = head.getName() + ", " + this.getTail().contents()
85+
this.getTail() != Empty() and result = className(head) + ", " + this.getTail().contents()
8686
)
8787
}
8888

89+
private string className(ClassObjectInternal cls) {
90+
result = cls.getName()
91+
or
92+
cls = ObjectInternal::unknownClass() and result = "??"
93+
}
94+
8995
int length() {
9096
this = Empty() and result = 0
9197
or
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
| absent.py:3:8:3:11 | ControlFlowNode for ImportExpr | Missing module xxxx |
2-
| absent.py:4:1:4:4 | ControlFlowNode for xxxx | Missing module xxxx |
3-
| absent.py:6:6:6:9 | ControlFlowNode for ImportExpr | Missing module xxxx |
4-
| absent.py:6:18:6:21 | ControlFlowNode for ImportMember | Missing module attribute xxxx.open |
5-
| absent.py:8:1:8:4 | ControlFlowNode for open | Missing module attribute xxxx.open |
6-
| absent.py:12:8:12:13 | ControlFlowNode for ImportExpr | Module module |
7-
| absent.py:14:1:14:6 | ControlFlowNode for module | Module module |
1+
| absent.py:3:8:3:11 | ControlFlowNode for ImportExpr | file://:0:0:0:0 | Missing module xxxx |
2+
| absent.py:4:1:4:4 | ControlFlowNode for xxxx | file://:0:0:0:0 | Missing module xxxx |
3+
| absent.py:6:6:6:9 | ControlFlowNode for ImportExpr | file://:0:0:0:0 | Missing module xxxx |
4+
| absent.py:6:18:6:21 | ControlFlowNode for ImportMember | file://:0:0:0:0 | Missing module attribute xxxx.open |
5+
| absent.py:8:1:8:4 | ControlFlowNode for open | file://:0:0:0:0 | Missing module attribute xxxx.open |
6+
| absent.py:12:8:12:13 | ControlFlowNode for ImportExpr | module.py:0:0:0:0 | Module module |
7+
| absent.py:14:1:14:6 | ControlFlowNode for module | module.py:0:0:0:0 | Module module |
Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
| 2 | bool True |
2-
| 3 | bool False |
3-
| 6 | bool True |
4-
| 7 | bool True |
5-
| 8 | bool True |
6-
| 9 | bool False |
7-
| 19 | bool False |
8-
| 19 | bool True |
9-
| 20 | bool False |
10-
| 20 | bool True |
11-
| 21 | bool False |
12-
| 21 | bool True |
13-
| 22 | bool False |
14-
| 22 | bool True |
15-
| 25 | bool False |
16-
| 26 | bool False |
17-
| 27 | bool True |
18-
| 28 | bool True |
19-
| 29 | bool False |
20-
| 30 | bool True |
21-
| 33 | bool False |
22-
| 34 | bool True |
23-
| 35 | bool False |
24-
| 36 | bool False |
25-
| 37 | bool True |
26-
| 38 | bool True |
1+
| 2 | file://:0:0:0:0 | bool True |
2+
| 3 | file://:0:0:0:0 | bool False |
3+
| 6 | file://:0:0:0:0 | bool True |
4+
| 7 | file://:0:0:0:0 | bool True |
5+
| 8 | file://:0:0:0:0 | bool True |
6+
| 9 | file://:0:0:0:0 | bool False |
7+
| 19 | file://:0:0:0:0 | bool False |
8+
| 19 | file://:0:0:0:0 | bool True |
9+
| 20 | file://:0:0:0:0 | bool False |
10+
| 20 | file://:0:0:0:0 | bool True |
11+
| 21 | file://:0:0:0:0 | bool False |
12+
| 21 | file://:0:0:0:0 | bool True |
13+
| 22 | file://:0:0:0:0 | bool False |
14+
| 22 | file://:0:0:0:0 | bool True |
15+
| 25 | file://:0:0:0:0 | bool False |
16+
| 26 | file://:0:0:0:0 | bool False |
17+
| 27 | file://:0:0:0:0 | bool True |
18+
| 28 | file://:0:0:0:0 | bool True |
19+
| 29 | file://:0:0:0:0 | bool False |
20+
| 30 | file://:0:0:0:0 | bool True |
21+
| 33 | file://:0:0:0:0 | bool False |
22+
| 34 | file://:0:0:0:0 | bool True |
23+
| 35 | file://:0:0:0:0 | bool False |
24+
| 36 | file://:0:0:0:0 | bool False |
25+
| 37 | file://:0:0:0:0 | bool True |
26+
| 38 | file://:0:0:0:0 | bool True |

python/ql/test/library-tests/PointsTo/inheritance/Mro.expected

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
| class Derived4 | [Derived4, Derived3, Derived2, Derived1, Base, object] |
66
| class Derived5 | [Derived5, Derived1, Base, object] |
77
| class Derived6 | [Derived6, Derived5, Derived2, Derived1, Base, object] |
8-
| class Missing1 | [Missing1, UNKNOWN, object] |
9-
| class Missing2 | [Missing2, Base, UNKNOWN, object] |
10-
| class Missing3 | [Missing3, UNKNOWN, Base, object] |
8+
| class Missing1 | [Missing1, ??, object] |
9+
| class Missing2 | [Missing2, Base, ??, object] |
10+
| class Missing3 | [Missing3, ??, Base, object] |
1111
| class Wrong1 | [Wrong1, Derived5, Derived2, Derived1, Base, object] |
1212
| class Wrong2 | [Wrong2, Derived3, Derived2, Derived1, Base, object] |

python/ql/test/library-tests/PointsTo/inheritance/Mro.ql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ class UnknownType extends UnknownClassInternal {
99

1010
override string toString() { result = "*UNKNOWN TYPE" }
1111

12-
override string getName() { result = "UNKNOWN" }
13-
1412
}
1513

1614
from ClassObjectInternal c

python/ql/test/library-tests/PointsTo/metaclass/Mro.ql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ class UnknownType extends UnknownClassInternal {
99

1010
override string toString() { result = "*UNKNOWN TYPE" }
1111

12-
override string getName() { result = "UNKNOWN" }
13-
1412
}
1513

1614
from PythonClassObjectInternal cls

python/ql/test/library-tests/PointsTo/metaclass/test.ql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ class UnknownType extends UnknownClassInternal {
77

88
override string toString() { result = "*UNKNOWN TYPE" }
99

10-
override string getName() { result = "UNKNOWN" }
11-
1210
}
1311

1412
from ClassObject cls
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
| builtin-class dict | builtin-class dict |
2-
| builtin-class dict | builtin-class list |
3-
| builtin-class int | (builtin-class float, builtin-class dict, ) |
4-
| builtin-class int | (builtin-class list, builtin-class int, ) |
5-
| builtin-class int | (builtin-class list, builtin-class int, ) |
6-
| builtin-class int | builtin-class dict |
7-
| builtin-class int | builtin-class float |
8-
| builtin-class int | builtin-class int |
9-
| builtin-class int | builtin-class list |
10-
| builtin-class int | builtin-class object |
11-
| builtin-class int | builtin-class tuple |
12-
| builtin-class tuple | builtin-class int |
13-
| builtin-class tuple | builtin-class tuple |
1+
| file://:0:0:0:0 | builtin-class dict | file://:0:0:0:0 | builtin-class dict |
2+
| file://:0:0:0:0 | builtin-class dict | file://:0:0:0:0 | builtin-class list |
3+
| file://:0:0:0:0 | builtin-class int | file://:0:0:0:0 | builtin-class dict |
4+
| file://:0:0:0:0 | builtin-class int | file://:0:0:0:0 | builtin-class float |
5+
| file://:0:0:0:0 | builtin-class int | file://:0:0:0:0 | builtin-class int |
6+
| file://:0:0:0:0 | builtin-class int | file://:0:0:0:0 | builtin-class list |
7+
| file://:0:0:0:0 | builtin-class int | file://:0:0:0:0 | builtin-class object |
8+
| file://:0:0:0:0 | builtin-class int | file://:0:0:0:0 | builtin-class tuple |
9+
| file://:0:0:0:0 | builtin-class int | test.py:14:23:14:31 | (builtin-class list, builtin-class int, ) |
10+
| file://:0:0:0:0 | builtin-class int | test.py:15:29:15:37 | (builtin-class list, builtin-class int, ) |
11+
| file://:0:0:0:0 | builtin-class int | test.py:16:25:16:35 | (builtin-class float, builtin-class dict, ) |
12+
| file://:0:0:0:0 | builtin-class tuple | file://:0:0:0:0 | builtin-class int |
13+
| file://:0:0:0:0 | builtin-class tuple | file://:0:0:0:0 | builtin-class tuple |
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
| class A | Missing base 0 |
2-
| class B | Failed inference for base class at position 0 |
3-
| class C | Failed inference for base class at position 0 |
4-
| class D | Duplicate bases classes |
5-
| class E | Duplicate bases classes |
6-
| class G | Failed inference for base class at position 0 |
7-
| class H | Failed inference for base class at position 0 |
8-
| class J | Missing base 0 |
9-
| class L | Failed inference for base class at position 0 |
10-
| class M | Failed inference for base class at position 0 |
11-
| class N | Failed inference for base class at position 0 |
12-
| class R | Failed inference for base class at position 0 |
13-
| class S | Failed inference for base class at position 0 |
14-
| class T | Failed inference for base class at position 0 |
1+
| circular_inheritance.py:33:1:33:11 | class A | Missing base 0 |
2+
| circular_inheritance.py:37:1:37:11 | class B | Failed inference for base class at position 0 |
3+
| circular_inheritance.py:40:1:40:72 | class D | Duplicate bases classes |
4+
| circular_inheritance.py:43:1:43:41 | class E | Duplicate bases classes |
5+
| circular_inheritance.py:47:1:47:19 | class G | Failed inference for base class at position 0 |
6+
| circular_inheritance.py:50:1:50:19 | class J | Missing base 0 |
7+
| circular_inheritance.py:54:1:54:11 | class M | Failed inference for base class at position 0 |
8+
| circular_inheritance.py:57:1:57:11 | class L | Failed inference for base class at position 0 |
9+
| circular_inheritance.py:61:1:61:19 | class S | Failed inference for base class at position 0 |
10+
| circular_inheritance.py:64:1:64:19 | class R | Failed inference for base class at position 0 |
11+
| mutual_inheritance.py:4:1:4:11 | class C | Failed inference for base class at position 0 |
12+
| mutual_inheritance.py:8:1:8:19 | class H | Failed inference for base class at position 0 |
13+
| mutual_inheritance.py:12:1:12:11 | class N | Failed inference for base class at position 0 |
14+
| mutual_inheritance.py:15:1:15:19 | class T | Failed inference for base class at position 0 |

0 commit comments

Comments
 (0)