Skip to content

Commit cb891a1

Browse files
committed
Python: Clean up six tests
We can't understand the real `six.py` file, so we have some internal plumbing that enables us to handle six anyway. While updating that, I had a hell of a lot of trouble with these tests. What we actually want, is to see that we can understand what the values imported from six are (i.e., their points-to information). I added a few more, that I think would be useful. If we can figure out all of these, I don't actually care if we're doing it by understanding the real `six.py` file, or by some internal trick. I verified that we don't get results with the real `six.py` file by disabling our internal tricks, and putting a copy of six.py just next to test.py. We used to have an other file that would list all the properties we knew and their value, but that turned out to be a fragile and annoying test, since the results differed from which version of python you ran it with (3.5 vs 3.8) and which machine you ran it on (my machien vs jenkins). I don't care about the results in this file, and I can certainly not eyeball it to see if it's correct or not.
1 parent 90f94e2 commit cb891a1

File tree

12 files changed

+37
-578
lines changed

12 files changed

+37
-578
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
semmle-extractor-options: --lang=2 --max-import-depth=3
1+
semmle-extractor-options: --lang=2 --max-import-depth=4
22
optimize: true
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
| six | Module six |
2-
| six.moves | Module six.moves |
1+
| six | Package six |
2+
| six.moves | Package six.moves |
3+
| six.moves.http_client | Module httplib |
4+
| six.moves.http_client.HTTPConnection | class HTTPConnection |
35
| six.moves.range | builtin-class xrange |
6+
| six.moves.urllib | Package six.moves.urllib |
7+
| six.moves.urllib.parse | Module six.moves.urllib_parse |
8+
| six.moves.urllib.parse.urlsplit | Function urlsplit |
9+
| six.moves.zip | builtin-class itertools.izip |
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
21
import python
32

43
string longname(Expr e) {
54
result = e.(Name).getId()
65
or
7-
exists(Attribute a |
8-
a = e |
9-
result = longname(a.getObject()) + "." + a.getName()
10-
)
6+
exists(Attribute a | a = e | result = longname(a.getObject()) + "." + a.getName())
117
}
128

13-
from Expr e, Object o
14-
where e.refersTo(o) and e.getLocation().getFile().getShortName() = "test.py"
15-
select longname(e), o.toString()
9+
from Expr e, Value v
10+
where e.pointsTo(v) and e.getLocation().getFile().getShortName() = "test.py"
11+
select longname(e), v.toString()

python/ql/test/2/library-tests/six/test.expected

Lines changed: 0 additions & 268 deletions
This file was deleted.
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import six
22

3-
#Check that some expected attributes are visible
3+
# Check that some expected attributes are visible -- this is the reason we added stubs in
4+
# the first place! If this works, we're happy!
45
six.moves
56
six.moves.range
7+
six.moves.zip
8+
six.moves.http_client.HTTPConnection
9+
six.moves.urllib.parse.urlsplit

python/ql/test/2/library-tests/six/test.ql

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
semmle-extractor-options: --max-import-depth=3
1+
semmle-extractor-options: --max-import-depth=4
22
optimize: true
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
| six | Module six |
2-
| six.moves | Module six.moves |
1+
| six | Package six |
2+
| six.moves | Package six.moves |
3+
| six.moves.http_client | Module http.client |
4+
| six.moves.http_client.HTTPConnection | class HTTPConnection |
35
| six.moves.range | builtin-class range |
6+
| six.moves.urllib | Package six.moves.urllib |
7+
| six.moves.urllib.parse | Module six.moves.urllib_parse |
8+
| six.moves.urllib.parse.urlsplit | Function urlsplit |
9+
| six.moves.zip | builtin-class zip |
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
21
import python
32

43
string longname(Expr e) {
54
result = e.(Name).getId()
65
or
7-
exists(Attribute a |
8-
a = e |
9-
result = longname(a.getObject()) + "." + a.getName()
10-
)
6+
exists(Attribute a | a = e | result = longname(a.getObject()) + "." + a.getName())
117
}
128

13-
from Expr e, Object o
14-
where e.refersTo(o) and e.getLocation().getFile().getShortName() = "test.py"
15-
select longname(e), o.toString()
16-
9+
from Expr e, Value v
10+
where e.pointsTo(v) and e.getLocation().getFile().getShortName() = "test.py"
11+
select longname(e), v.toString()

0 commit comments

Comments
 (0)