Python: Make isSequence() and isMapping() tests version specific · sniten/codeql@48b2d2c · GitHub
Skip to content

Commit 48b2d2c

Browse files
committed
Python: Make isSequence() and isMapping() tests version specific
Since unicode/bytes difference, output can't match between Python 2 and Python 3.
1 parent bacd491 commit 48b2d2c

8 files changed

Lines changed: 89 additions & 3 deletions

File tree

Lines changed: 12 additions & 0 deletions

python/ql/test/library-tests/PointsTo/class_properties/ClassValues.ql renamed to python/ql/test/2/library-tests/PointsTo/class_properties/ClassValues.ql

File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle-extractor-options: --lang=2 --max-import-depth=2

python/ql/test/library-tests/PointsTo/class_properties/test.py renamed to python/ql/test/2/library-tests/PointsTo/class_properties/test.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
from collections import OrderedDict, defaultdict
2-
import collections.abc
2+
3+
# Python 2 specific
4+
from collections import Sequence, Mapping
35

46
def test(*args):
57
pass
68

7-
class MySequenceABC(collections.abc.Sequence):
9+
class MySequenceABC(Sequence):
810
pass
911

10-
class MyMappingABC(collections.abc.Mapping):
12+
class MyMappingABC(Mapping):
1113
pass
1214

1315
class MySequenceImpl(object):
@@ -24,6 +26,7 @@ class MyDictSubclass(dict):
2426
list,
2527
tuple,
2628
str,
29+
unicode,
2730
bytes,
2831
MySequenceABC,
2932
MySequenceImpl,

python/ql/test/library-tests/PointsTo/class_properties/ClassValues.expected renamed to python/ql/test/3/library-tests/PointsTo/class_properties/ClassValues.expected

File renamed without changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import python
2+
3+
from ClassValue cls, string res
4+
where
5+
exists(CallNode call |
6+
call.getFunction().(NameNode).getId() = "test" and
7+
call.getAnArg().pointsTo(cls)
8+
) and
9+
(
10+
cls.isSequence() and
11+
cls.isMapping() and
12+
res = "IS BOTH. SHOULD NOT HAPPEN. THEY ARE MUTUALLY EXCLUSIVE."
13+
or
14+
cls.isSequence() and not cls.isMapping() and res = "sequence"
15+
or
16+
not cls.isSequence() and cls.isMapping() and res = "mapping"
17+
or
18+
not cls.isSequence() and not cls.isMapping() and res = "neither sequence nor mapping"
19+
)
20+
select res, cls.toString()

python/ql/test/library-tests/PointsTo/class_properties/options renamed to python/ql/test/3/library-tests/PointsTo/class_properties/options

File renamed without changes.
Lines changed: 50 additions & 0 deletions

0 commit comments

Comments
 (0)