Skip to content

Commit e6b0047

Browse files
echoixcyliang368
authored andcommitted
style: Fixes unnecessary-collection-call (C408) for testsuite (OSGeo#3947)
* style: Fixes unnecessary-collection-call (C408) for testsuite Only applies fixes to non-empty collections by `ruff check --select "C408" --unsafe-fixes --output-format=concise --fix --config 'include = ["*/testsuite/**.py"]'` in order to limit the review scope. * style: Apply black formatting Separated in another commit for easier review of only the original changes without formatting
1 parent 256c5fc commit e6b0047

File tree

33 files changed

+426
-376
lines changed

33 files changed

+426
-376
lines changed

python/grass/benchmark/testsuite/test_benchmark.py

+23-17
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,18 @@ class TestBenchmarksRun(TestCase):
3838
def test_resolutions(self):
3939
"""Test that resolution tests runs without nprocs and plots to file"""
4040
benchmarks = [
41-
dict(
42-
module=Module("r.univar", map="elevation", stdout_=DEVNULL, run_=False),
43-
label="Standard output",
44-
),
45-
dict(
46-
module=Module(
41+
{
42+
"module": Module(
43+
"r.univar", map="elevation", stdout_=DEVNULL, run_=False
44+
),
45+
"label": "Standard output",
46+
},
47+
{
48+
"module": Module(
4749
"r.univar", map="elevation", flags="g", stdout_=DEVNULL, run_=False
4850
),
49-
label="Standard output",
50-
),
51+
"label": "Standard output",
52+
},
5153
]
5254
resolutions = [300, 200, 100]
5355
results = []
@@ -67,10 +69,12 @@ def test_single(self):
6769
label = "Standard output"
6870
repeat = 4
6971
benchmarks = [
70-
dict(
71-
module=Module("r.univar", map="elevation", stdout_=DEVNULL, run_=False),
72-
label=label,
73-
)
72+
{
73+
"module": Module(
74+
"r.univar", map="elevation", stdout_=DEVNULL, run_=False
75+
),
76+
"label": label,
77+
}
7478
]
7579
results = []
7680
for benchmark in benchmarks:
@@ -88,11 +92,13 @@ def test_nprocs(self):
8892
label = "Standard output"
8993
repeat = 4
9094
benchmarks = [
91-
dict(
92-
module=Module("r.univar", map="elevation", stdout_=DEVNULL, run_=False),
93-
label=label,
94-
max_nprocs=4,
95-
)
95+
{
96+
"module": Module(
97+
"r.univar", map="elevation", stdout_=DEVNULL, run_=False
98+
),
99+
"label": label,
100+
"max_nprocs": 4,
101+
}
96102
]
97103
results = []
98104
for benchmark in benchmarks:

python/grass/gunittest/testsuite/test_assertions.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ def test_pygrass_module(self):
132132
"""Test syntax with Module and required parameters as module"""
133133
module = Module("r.info", map="elevation", flags="gr", run_=False, finish_=True)
134134
self.assertModuleKeyValue(
135-
module, reference=dict(min=55.58, max=156.33), precision=0.01, sep="="
135+
module, reference={"min": 55.58, "max": 156.33}, precision=0.01, sep="="
136136
)
137137

138138
def test_pygrass_simple_module(self):
139139
"""Test syntax with SimpleModule as module"""
140140
module = SimpleModule("r.info", map="elevation", flags="gr")
141141
self.assertModuleKeyValue(
142-
module, reference=dict(min=55.58, max=156.33), precision=0.01, sep="="
142+
module, reference={"min": 55.58, "max": 156.33}, precision=0.01, sep="="
143143
)
144144

145145
def test_direct_parameters(self):
@@ -148,7 +148,7 @@ def test_direct_parameters(self):
148148
"r.info",
149149
map="elevation",
150150
flags="gr",
151-
reference=dict(min=55.58, max=156.33),
151+
reference={"min": 55.58, "max": 156.33},
152152
precision=0.01,
153153
sep="=",
154154
)
@@ -157,8 +157,8 @@ def test_parameters_parameter(self):
157157
"""Test syntax with module parameters in one parameters dictionary"""
158158
self.assertModuleKeyValue(
159159
module="r.info",
160-
parameters=dict(map="elevation", flags="gr"),
161-
reference=dict(min=55.58, max=156.33),
160+
parameters={"map": "elevation", "flags": "gr"},
161+
reference={"min": 55.58, "max": 156.33},
162162
precision=0.01,
163163
sep="=",
164164
)
@@ -237,7 +237,7 @@ def test_assertRastersNoDifference_mean(self):
237237
actual="elevation",
238238
reference="elevation",
239239
precision=0, # this might need to be increased
240-
statistics=dict(mean=0),
240+
statistics={"mean": 0},
241241
msg="The difference of same maps should have small mean",
242242
)
243243
self.assertRaises(
@@ -246,7 +246,7 @@ def test_assertRastersNoDifference_mean(self):
246246
actual="elevation",
247247
reference="geology",
248248
precision=1,
249-
statistics=dict(mean=0),
249+
statistics={"mean": 0},
250250
msg="The difference of different maps should have huge mean",
251251
)
252252

python/grass/gunittest/testsuite/test_assertions_rast3d.py

+34-34
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@ def tearDownClass(cls):
3535
)
3636

3737
def test_assertRaster3dFitsUnivar(self):
38-
reference = dict(
39-
n=1000000,
40-
null_cells=0,
41-
cells=1000000,
42-
min=155,
43-
max=155,
44-
range=0,
45-
mean=155,
46-
mean_of_abs=155,
47-
stddev=0,
48-
variance=0,
49-
coeff_var=0,
50-
sum=155000000,
51-
)
38+
reference = {
39+
"n": 1000000,
40+
"null_cells": 0,
41+
"cells": 1000000,
42+
"min": 155,
43+
"max": 155,
44+
"range": 0,
45+
"mean": 155,
46+
"mean_of_abs": 155,
47+
"stddev": 0,
48+
"variance": 0,
49+
"coeff_var": 0,
50+
"sum": 155000000,
51+
}
5252
self.assertRaster3dFitsUnivar(
5353
self.constant_map, reference=reference, precision=0.000001
5454
)
@@ -63,30 +63,30 @@ def test_assertRaster3dFitsUnivar(self):
6363
ValueError,
6464
self.assertRaster3dFitsUnivar,
6565
self.constant_map,
66-
reference=dict(a=4, b=5, c=6),
66+
reference={"a": 4, "b": 5, "c": 6},
6767
)
6868
self.assertRaises(
6969
CalledModuleError,
7070
self.assertRaster3dFitsUnivar,
7171
"does_not_exists",
72-
reference=dict(a=4, b=5, c=6),
72+
reference={"a": 4, "b": 5, "c": 6},
7373
)
7474

7575
def test_assertRaster3dFitsInfo(self):
76-
reference = dict(
77-
north=200,
78-
south=100,
79-
east=400,
80-
west=200,
81-
bottom=450,
82-
top=500,
83-
nsres=1,
84-
ewres=1,
85-
tbres=1,
86-
rows=100,
87-
cols=200,
88-
depths=50,
89-
)
76+
reference = {
77+
"north": 200,
78+
"south": 100,
79+
"east": 400,
80+
"west": 200,
81+
"bottom": 450,
82+
"top": 500,
83+
"nsres": 1,
84+
"ewres": 1,
85+
"tbres": 1,
86+
"rows": 100,
87+
"cols": 200,
88+
"depths": 50,
89+
}
9090
self.assertRaster3dFitsInfo(self.constant_map, reference=reference)
9191

9292
reference["north"] = 500
@@ -100,11 +100,11 @@ def test_assertRaster3dFitsInfo(self):
100100
ValueError,
101101
self.assertRaster3dFitsInfo,
102102
self.constant_map,
103-
reference=dict(a=5),
103+
reference={"a": 5},
104104
)
105105

106106
def test_common_values_info_univar(self):
107-
minmax = dict(min=3, max=350)
107+
minmax = {"min": 3, "max": 350}
108108
self.assertRaster3dFitsUnivar(self.rcd_increasing_map, minmax, precision=0.01)
109109
self.assertRaster3dFitsInfo(self.rcd_increasing_map, minmax, precision=0.01)
110110

@@ -138,7 +138,7 @@ def test_assertRasters3dNoDifference_mean(self):
138138
actual=self.rcd_increasing_map,
139139
reference=self.rcd_increasing_map,
140140
precision=0, # this might need to be increased
141-
statistics=dict(mean=0),
141+
statistics={"mean": 0},
142142
msg="The difference of same maps should have small mean",
143143
)
144144
self.assertRaises(
@@ -147,7 +147,7 @@ def test_assertRasters3dNoDifference_mean(self):
147147
actual=self.constant_map,
148148
reference=self.rcd_increasing_map,
149149
precision=1,
150-
statistics=dict(mean=0),
150+
statistics={"mean": 0},
151151
msg="The difference of different maps should have huge mean",
152152
)
153153

python/grass/gunittest/testsuite/test_assertions_vect.py

+24-24
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,34 @@
2424
"""
2525

2626
# v.info schools -t
27-
V_UNIVAR_SCHOOLS_TOPO = dict(
28-
nodes=0,
29-
points=167,
30-
lines=0,
31-
boundaries=0,
32-
centroids=0,
33-
areas=0,
34-
islands=0,
35-
primitives=167,
36-
map3d=0,
37-
)
27+
V_UNIVAR_SCHOOLS_TOPO = {
28+
"nodes": 0,
29+
"points": 167,
30+
"lines": 0,
31+
"boundaries": 0,
32+
"centroids": 0,
33+
"areas": 0,
34+
"islands": 0,
35+
"primitives": 167,
36+
"map3d": 0,
37+
}
3838

3939
# v.info schools -g and rounded
40-
V_UNIVAR_SCHOOLS_REGION = dict(
41-
north=248160,
42-
south=203560,
43-
east=671715,
44-
west=619215,
45-
top=0,
46-
bottom=0,
47-
)
40+
V_UNIVAR_SCHOOLS_REGION = {
41+
"north": 248160,
42+
"south": 203560,
43+
"east": 671715,
44+
"west": 619215,
45+
"top": 0,
46+
"bottom": 0,
47+
}
4848

4949
# v.info schools -g and reduced to minimum
50-
V_UNIVAR_SCHOOLS_EXTENDED = dict(
51-
name="schools",
52-
level=2,
53-
num_dblinks=1,
54-
)
50+
V_UNIVAR_SCHOOLS_EXTENDED = {
51+
"name": "schools",
52+
"level": 2,
53+
"num_dblinks": 1,
54+
}
5555

5656

5757
class TestVectorInfoAssertions(TestCase):

python/grass/pygrass/modules/interface/testsuite/test_flag.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
class TestFlag(TestCase):
1414
def test_get_bash(self):
1515
"""Test get_bash method"""
16-
flag = Flag(diz=dict(name="a"))
16+
flag = Flag(diz={"name": "a"})
1717
self.assertFalse(flag.value)
1818
self.assertEqual("", flag.get_bash())
1919
flag.special = True
@@ -25,7 +25,7 @@ def test_get_bash(self):
2525

2626
def test_get_python(self):
2727
"""Test get_python method"""
28-
flag = Flag(diz=dict(name="a"))
28+
flag = Flag(diz={"name": "a"})
2929
self.assertFalse(flag.value)
3030
self.assertEqual("", flag.get_python())
3131
flag.special = True
@@ -37,7 +37,7 @@ def test_get_python(self):
3737

3838
def test_bool(self):
3939
"""Test magic __bool__ method"""
40-
flag = Flag(diz=dict(name="a"))
40+
flag = Flag(diz={"name": "a"})
4141
flag.value = True
4242
self.assertTrue(True if flag else False)
4343
flag.value = False

0 commit comments

Comments
 (0)