Skip to content

Commit dcd62e5

Browse files
authored
Merge pull request github#1961 from RasmusWL/python-split-function-tests
Python: split tests for Functions into more files
2 parents 2308767 + 3c33e86 commit dcd62e5

9 files changed

+140
-138
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| functions_test.py:200:5:200:40 | Function __getslice__ | __getslice__ method has been deprecated since Python 2.0 |
2-
| functions_test.py:203:5:203:47 | Function __setslice__ | __setslice__ method has been deprecated since Python 2.0 |
3-
| functions_test.py:206:5:206:40 | Function __delslice__ | __delslice__ method has been deprecated since Python 2.0 |
1+
| functions_test.py:99:5:99:40 | Function __getslice__ | __getslice__ method has been deprecated since Python 2.0 |
2+
| functions_test.py:102:5:102:47 | Function __setslice__ | __setslice__ method has been deprecated since Python 2.0 |
3+
| functions_test.py:105:5:105:40 | Function __delslice__ | __delslice__ method has been deprecated since Python 2.0 |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| functions_test.py:45:9:45:19 | Return | Explicit return in __init__ method. |
1+
| explicit_return_in_init.py:4:9:4:19 | Return | Explicit return in __init__ method. |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| functions_test.py:73:5:73:23 | Function __init__ | __init__ method is a generator. |
1+
| explicit_return_in_init.py:32:5:32:23 | Function __init__ | __init__ method is a generator. |
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
edges
22
| functions_test.py:39:9:39:9 | empty mutable value | functions_test.py:40:5:40:5 | empty mutable value |
3-
| functions_test.py:238:15:238:15 | empty mutable value | functions_test.py:239:5:239:5 | empty mutable value |
4-
| functions_test.py:290:25:290:25 | empty mutable value | functions_test.py:291:5:291:5 | empty mutable value |
5-
| functions_test.py:293:21:293:21 | empty mutable value | functions_test.py:294:5:294:5 | empty mutable value |
6-
| functions_test.py:296:27:296:27 | empty mutable value | functions_test.py:297:25:297:25 | empty mutable value |
7-
| functions_test.py:296:27:296:27 | empty mutable value | functions_test.py:298:21:298:21 | empty mutable value |
8-
| functions_test.py:297:25:297:25 | empty mutable value | functions_test.py:290:25:290:25 | empty mutable value |
9-
| functions_test.py:298:21:298:21 | empty mutable value | functions_test.py:293:21:293:21 | empty mutable value |
3+
| functions_test.py:133:15:133:15 | empty mutable value | functions_test.py:134:5:134:5 | empty mutable value |
4+
| functions_test.py:185:25:185:25 | empty mutable value | functions_test.py:186:5:186:5 | empty mutable value |
5+
| functions_test.py:188:21:188:21 | empty mutable value | functions_test.py:189:5:189:5 | empty mutable value |
6+
| functions_test.py:191:27:191:27 | empty mutable value | functions_test.py:192:25:192:25 | empty mutable value |
7+
| functions_test.py:191:27:191:27 | empty mutable value | functions_test.py:193:21:193:21 | empty mutable value |
8+
| functions_test.py:192:25:192:25 | empty mutable value | functions_test.py:185:25:185:25 | empty mutable value |
9+
| functions_test.py:193:21:193:21 | empty mutable value | functions_test.py:188:21:188:21 | empty mutable value |
1010
#select
1111
| functions_test.py:40:5:40:5 | x | functions_test.py:39:9:39:9 | empty mutable value | functions_test.py:40:5:40:5 | empty mutable value | $@ flows to here and is mutated. | functions_test.py:39:9:39:9 | x | Default value |
12-
| functions_test.py:239:5:239:5 | x | functions_test.py:238:15:238:15 | empty mutable value | functions_test.py:239:5:239:5 | empty mutable value | $@ flows to here and is mutated. | functions_test.py:238:15:238:15 | x | Default value |
13-
| functions_test.py:291:5:291:5 | x | functions_test.py:296:27:296:27 | empty mutable value | functions_test.py:291:5:291:5 | empty mutable value | $@ flows to here and is mutated. | functions_test.py:296:27:296:27 | y | Default value |
14-
| functions_test.py:294:5:294:5 | x | functions_test.py:296:27:296:27 | empty mutable value | functions_test.py:294:5:294:5 | empty mutable value | $@ flows to here and is mutated. | functions_test.py:296:27:296:27 | y | Default value |
12+
| functions_test.py:134:5:134:5 | x | functions_test.py:133:15:133:15 | empty mutable value | functions_test.py:134:5:134:5 | empty mutable value | $@ flows to here and is mutated. | functions_test.py:133:15:133:15 | x | Default value |
13+
| functions_test.py:186:5:186:5 | x | functions_test.py:191:27:191:27 | empty mutable value | functions_test.py:186:5:186:5 | empty mutable value | $@ flows to here and is mutated. | functions_test.py:191:27:191:27 | y | Default value |
14+
| functions_test.py:189:5:189:5 | x | functions_test.py:191:27:191:27 | empty mutable value | functions_test.py:189:5:189:5 | empty mutable value | $@ flows to here and is mutated. | functions_test.py:191:27:191:27 | y | Default value |
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| functions_test.py:100:5:100:24 | Function n_cmethod | Class methods or methods of a type deriving from type should have 'cls', rather than 'self', as their first argument. |
2-
| functions_test.py:114:5:114:20 | Function c_method | Class methods or methods of a type deriving from type should have 'cls', rather than 'y', as their first argument. |
1+
| argument_names.py:17:5:17:24 | Function n_cmethod | Class methods or methods of a type deriving from type should have 'cls', rather than 'self', as their first argument. |
2+
| argument_names.py:32:5:32:20 | Function c_method | Class methods or methods of a type deriving from type should have 'cls', rather than 'y', as their first argument. |
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| functions_test.py:130:5:130:20 | Function __init__ | Normal methods should have 'self', rather than 'x', as their first parameter. |
2-
| functions_test.py:133:5:133:20 | Function s_method | Normal methods should have 'self', rather than 'y', as their first parameter. |
1+
| argument_names.py:45:5:45:20 | Function __init__ | Normal methods should have 'self', rather than 'x', as their first parameter. |
2+
| argument_names.py:48:5:48:20 | Function s_method | Normal methods should have 'self', rather than 'y', as their first parameter. |
33
| om_test.py:71:5:71:19 | Function __repr__ | Normal methods should have at least one parameter (the first of which should be 'self'). |
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Using name other than 'self' for first argument in methods.
2+
# This shouldn't apply to classmethods (first argument should be 'cls' or similar)
3+
# or static methods (first argument can be anything)
4+
5+
6+
class Normal(object):
7+
8+
def n_ok(self):
9+
pass
10+
11+
@staticmethod
12+
def n_smethod(ok):
13+
pass
14+
15+
# not ok
16+
@classmethod
17+
def n_cmethod(self):
18+
pass
19+
20+
# this is allowed because it has a decorator other than @classmethod
21+
@classmethod
22+
@id
23+
def n_suppress(any_name):
24+
pass
25+
26+
27+
class Class(type):
28+
29+
def __init__(cls):
30+
pass
31+
32+
def c_method(y):
33+
pass
34+
35+
def c_ok(cls):
36+
pass
37+
38+
@id
39+
def c_suppress(any_name):
40+
pass
41+
42+
43+
class NonSelf(object):
44+
45+
def __init__(x):
46+
pass
47+
48+
def s_method(y):
49+
pass
50+
51+
def s_ok(self):
52+
pass
53+
54+
@staticmethod
55+
def s_smethod(ok):
56+
pass
57+
58+
@classmethod
59+
def s_cmethod(cls):
60+
pass
61+
62+
def s_smethod2(ok):
63+
pass
64+
s_smethod2 = staticmethod(s_smethod2)
65+
66+
def s_cmethod2(cls):
67+
pass
68+
s_cmethod2 = classmethod(s_cmethod2)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
class ExplicitReturnInInit(object):
2+
3+
def __init__(self):
4+
return self
5+
6+
#These are OK
7+
class ExplicitReturnNoneInInit(object):
8+
9+
def __init__(self):
10+
return None
11+
12+
class PlainReturnInInit(object):
13+
14+
def __init__(self):
15+
return
16+
17+
def error():
18+
raise Exception()
19+
20+
class InitCallsError(object):
21+
22+
def __init__(self):
23+
return error()
24+
25+
class InitCallsInit(InitCallsError):
26+
27+
def __init__(self):
28+
return InitCallsError.__init__(self)
29+
30+
class InitIsGenerator(object):
31+
32+
def __init__(self):
33+
yield self
34+
35+
#OK as it returns result of a call to super().__init__()
36+
class InitCallsInit(InitCallsError):
37+
38+
def __init__(self):
39+
return super(InitCallsInit, self).__init__()

python/ql/test/query-tests/Functions/general/functions_test.py

Lines changed: 14 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def cr2(x):
2424
return 4
2525
else:
2626
return
27-
27+
2828
def ok3(x):
2929
try:
3030
return
@@ -39,39 +39,6 @@ def ok4(x = []):
3939
def mpd(x = []):
4040
x.append("x")
4141

42-
class ExplicitReturnInInit(object):
43-
44-
def __init__(self):
45-
return self
46-
47-
#These are OK
48-
class ExplicitReturnNoneInInit(object):
49-
50-
def __init__(self):
51-
return None
52-
53-
class PlainReturnInInit(object):
54-
55-
def __init__(self):
56-
return
57-
58-
def error():
59-
raise Exception()
60-
61-
class InitCallsError(object):
62-
63-
def __init__(self):
64-
return error()
65-
66-
class InitCallsInit(InitCallsError):
67-
68-
def __init__(self):
69-
return InitCallsError.__init__(self)
70-
71-
class InitIsGenerator(object):
72-
73-
def __init__(self):
74-
yield self
7542

7643
def use_implicit_return_value(arg):
7744
x = do_nothing()
@@ -83,74 +50,6 @@ def use_implicit_return_value(arg):
8350
def do_nothing():
8451
pass
8552

86-
#Using name other than 'cls' for first parameter in methods.
87-
# This shouldn't apply to classmethods (first parameter should be 'cls' or similar)
88-
# or static methods (first parameter can be anything)
89-
90-
class Normal(object):
91-
92-
def n_ok(self):
93-
pass
94-
95-
@staticmethod
96-
def n_smethod(ok):
97-
pass
98-
99-
@classmethod
100-
def n_cmethod(self):
101-
pass
102-
103-
# this is allowed because it has a decorator other than @classmethod
104-
@classmethod
105-
@id
106-
def n_suppress(any_name):
107-
pass
108-
109-
class Class(type):
110-
111-
def __init__(cls):
112-
pass
113-
114-
def c_method(y):
115-
pass
116-
117-
def c_ok(cls):
118-
pass
119-
120-
@id
121-
def c_suppress(any_name):
122-
pass
123-
124-
#Using name other than 'self' for first parameter in methods.
125-
# This shouldn't apply to classmethods (first parameter should be 'cls' or similar)
126-
# or static methods (first parameter can be anything)
127-
128-
class NonSelf(object):
129-
130-
def __init__(x):
131-
pass
132-
133-
def s_method(y):
134-
pass
135-
136-
def s_ok(self):
137-
pass
138-
139-
@staticmethod
140-
def s_smethod(ok):
141-
pass
142-
143-
@classmethod
144-
def s_cmethod(cls):
145-
pass
146-
147-
def s_smethod2(ok):
148-
pass
149-
s_smethod2 = staticmethod(s_smethod2)
150-
151-
def s_cmethod2(cls):
152-
pass
153-
s_cmethod2 = classmethod(s_cmethod2)
15453

15554
def returns_self(self):
15655
return self
@@ -159,9 +58,9 @@ def return_value_ignored():
15958
ok2()
16059
ok4()
16160
sorted([1,2])
162-
61+
16362
d = {}
164-
63+
16564
def use_return_values():
16665
x = ok2()
16766
x = ok2()
@@ -194,15 +93,15 @@ def ok_to_ignore():
19493
returns_self()
19594
ok3()
19695
y()
197-
96+
19897
class DeprecatedSliceMethods(object):
199-
98+
20099
def __getslice__(self, start, stop):
201100
pass
202-
101+
203102
def __setslice__(self, start, stop, value):
204103
pass
205-
104+
206105
def __delslice__(self, start, stop):
207106
pass
208107

@@ -217,36 +116,32 @@ def nested_call_implicit_return_func_ok(arg):
217116

218117

219118

220-
#OK as it returns result of a call to super().__init__()
221-
class InitCallsInit(InitCallsError):
222119

223-
def __init__(self):
224-
return super(InitCallsInit, self).__init__()
225-
120+
226121
#Harmless, so we allow it.
227122
def use_implicit_return_value_ok(arg):
228123
return do_nothing()
229-
124+
230125
def mutli_return(arg):
231126
if arg:
232127
return do_something()
233128
else:
234129
return do_nothing()
235-
130+
236131
#Modification of parameter with default
237132

238133
def augassign(x = []):
239134
x += ["x"]
240-
241-
135+
136+
242137
#Possible FPs for non-self. ODASA-2439
243138

244139
class C(object):
245140
def _func(f):
246141
return f
247-
142+
248143
_func(x)
249-
144+
250145
#or
251146
@_func
252147
def meth(self):

0 commit comments

Comments
 (0)