Skip to content

Commit 48d6429

Browse files
committed
Fixed sonar qube cloud issues
1 parent a8f4d07 commit 48d6429

16 files changed

Lines changed: 385 additions & 439 deletions

decoimpact/business/entities/rule_processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def _expand_dimensions_of_variable(
384384
# Let the user know which variables will be broadcast to all dimensions
385385
dims_orig = var_orig.dims
386386
dims_result = ref_var.dims
387-
dims_diff = list(str(x) for x in dims_result if x not in dims_orig)
387+
dims_diff = [str(x) for x in dims_result if x not in dims_orig]
388388
str_dims_broadcasted = ",".join(dims_diff)
389389
logger.log_info(
390390
f"""Variable {var_orig.name} will be expanded to the following \

decoimpact/business/entities/rules/formula_rule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def validate(self, logger: ILogger) -> bool:
4848
filename="<inline code>",
4949
mode="exec",
5050
)
51-
local_variables = {name: 1.0 for name in self.input_variable_names}
51+
local_variables = dict.fromkeys(self.input_variable_names, 1.0)
5252
exec(byte_code, self._global_variables, local_variables)
5353

5454
except (SyntaxError, NameError) as exception:

decoimpact/business/entities/rules/time_operation_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(
2828
raise ValueError("The time_scale_mapping does not contain any values")
2929

3030
self._time_scale_mapping = time_scale_mapping
31-
self._time_scale = next(i for i in time_scale_mapping.keys())
31+
self._time_scale = next(iter(time_scale_mapping.keys()))
3232
self._operation_type = TimeOperationType.AVERAGE
3333
self._percentile_value = 0.0
3434

tests/business/utils/test_dataset_utils.py

Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ def test_remove_variable_and_keeps_others(self):
5959
variable2 = "variable2"
6060
variable3 = "variable3"
6161
dataset = _xr.Dataset(
62-
data_vars=dict(
63-
variable1=variable1, variable2=variable2, variable3=variable3
64-
)
62+
data_vars={
63+
"variable1": variable1,
64+
"variable2": variable2,
65+
"variable3": variable3,
66+
}
6567
)
6668
variable_to_be_removed = [variable2]
6769

@@ -83,12 +85,12 @@ def test_leave_only_one_variable(self):
8385
variable3 = "variable3"
8486
variable4 = "variable4"
8587
dataset = _xr.Dataset(
86-
data_vars=dict(
87-
variable1=variable1,
88-
variable2=variable2,
89-
variable3=variable3,
90-
variable4=variable4,
91-
)
88+
data_vars={
89+
"variable1": variable1,
90+
"variable2": variable2,
91+
"variable3": variable3,
92+
"variable4": variable4,
93+
}
9294
)
9395
dataset["variable2"].attrs = {"cf_role": "mesh_topology"}
9496
variable_to_keep = [variable2]
@@ -112,12 +114,12 @@ def test_reduce_for_writing_throws_exception_for_non_existing_variable(self):
112114
variable3 = "variable3"
113115
variable4 = "variable4"
114116
dataset = _xr.Dataset(
115-
data_vars=dict(
116-
variable1=variable1,
117-
variable2=variable2,
118-
variable3=variable3,
119-
variable4=variable4,
120-
)
117+
data_vars={
118+
"variable1": variable1,
119+
"variable2": variable2,
120+
"variable3": variable3,
121+
"variable4": variable4,
122+
}
121123
)
122124
dataset["variable2"].attrs = {"cf_role": "mesh_topology"}
123125
logger = Mock(ILogger)
@@ -143,12 +145,12 @@ def test_leave_multiple_variables(self):
143145
variable3 = "variable3"
144146
variable4 = "variable4"
145147
dataset = _xr.Dataset(
146-
data_vars=dict(
147-
variable1=variable1,
148-
variable2=variable2,
149-
variable3=variable3,
150-
variable4=variable4,
151-
)
148+
data_vars={
149+
"variable1": variable1,
150+
"variable2": variable2,
151+
"variable3": variable3,
152+
"variable4": variable4,
153+
}
152154
)
153155
dataset["variable2"].attrs = {"cf_role": "mesh_topology"}
154156
variables_to_keep = [variable2, variable4]
@@ -192,7 +194,11 @@ def test_list_variables_in_dataset():
192194
variable2 = "variable2"
193195
variable3 = "variable3"
194196
dataset = _xr.Dataset(
195-
data_vars=dict(variable1=variable1, variable2=variable2, variable3=variable3)
197+
data_vars={
198+
"variable1": variable1,
199+
"variable2": variable2,
200+
"variable3": variable3,
201+
}
196202
)
197203

198204
# Act
@@ -227,7 +233,11 @@ def test_rename_variable_returns_dataset_without_old_variable_and_with_new_varia
227233
variable3 = "variable3"
228234
new_name = "new_name"
229235
dataset1 = _xr.Dataset(
230-
data_vars=dict(variable1=variable1, variable2=variable2, variable3=variable3)
236+
data_vars={
237+
"variable1": variable1,
238+
"variable2": variable2,
239+
"variable3": variable3,
240+
}
231241
)
232242
# Act
233243
dataset2 = utilities.rename_variable(dataset1, "variable1", new_name)
@@ -245,11 +255,15 @@ def test_merged_dataset_is_xarray_dataset_and_contains_all_variables(self):
245255
# Arrange
246256
variable1 = "variable1"
247257
variable2 = "variable2"
248-
dataset1 = _xr.Dataset(data_vars=dict(variable1=variable1, variable2=variable2))
258+
dataset1 = _xr.Dataset(
259+
data_vars={"variable1": variable1, "variable2": variable2}
260+
)
249261

250262
variable3 = "variable3"
251263
variable4 = "variable4"
252-
dataset2 = _xr.Dataset(data_vars=dict(variable3=variable3, variable4=variable4))
264+
dataset2 = _xr.Dataset(
265+
data_vars={"variable3": variable3, "variable4": variable4}
266+
)
253267

254268
# Act
255269
merged_dataset = utilities.merge_datasets(dataset1, dataset2)
@@ -267,15 +281,21 @@ def test_merged_list_of_datasets_is_xarray_dataset_and_contains_all_variables(se
267281
# Arrange
268282
variable1 = "variable1"
269283
variable2 = "variable2"
270-
dataset1 = _xr.Dataset(data_vars=dict(variable1=variable1, variable2=variable2))
284+
dataset1 = _xr.Dataset(
285+
data_vars={"variable1": variable1, "variable2": variable2}
286+
)
271287

272288
variable3 = "variable3"
273289
variable4 = "variable4"
274-
dataset2 = _xr.Dataset(data_vars=dict(variable3=variable3, variable4=variable4))
290+
dataset2 = _xr.Dataset(
291+
data_vars={"variable3": variable3, "variable4": variable4}
292+
)
275293

276294
variable5 = "variable5"
277295
variable6 = "variable6"
278-
dataset3 = _xr.Dataset(data_vars=dict(variable5=variable5, variable6=variable6))
296+
dataset3 = _xr.Dataset(
297+
data_vars={"variable5": variable5, "variable6": variable6}
298+
)
279299

280300
list_datasets = [dataset1, dataset2, dataset3]
281301
# Act
@@ -297,7 +317,7 @@ def test_get_dummy_variable(self):
297317
# Arrange
298318
variable1 = "variable1"
299319
variable2 = "variable2"
300-
ds = _xr.Dataset(data_vars=dict(variable1=variable1, variable2=variable2))
320+
ds = _xr.Dataset(data_vars={"variable1": variable1, "variable2": variable2})
301321
ds["variable1"].attrs = {"cf_role": "mesh_topology"}
302322

303323
# Act
@@ -311,7 +331,7 @@ def test_get_dummy_variable_fails(self):
311331
# Arrange
312332
variable1 = "variable1"
313333
variable2 = "variable2"
314-
ds = _xr.Dataset(data_vars=dict(variable1=variable1, variable2=variable2))
334+
ds = _xr.Dataset(data_vars={"variable1": variable1, "variable2": variable2})
315335

316336
# Act
317337
with pytest.raises(ValueError) as error:
@@ -329,7 +349,7 @@ def test_get_dummy_and_dependent_var_list(self):
329349
in a ugrid dataset"""
330350
# Arrange
331351
var_list = ["mesh2d", "var2", "var3", "var4", "var5"]
332-
ds = _xr.Dataset(data_vars=dict.fromkeys(var_list))
352+
ds = _xr.Dataset(data_vars={k: None for k in var_list})
333353
ds["mesh2d"].attrs = {
334354
"cf_role": "mesh_topology",
335355
"test_coordinates": "var2 var3",
@@ -351,7 +371,7 @@ def test_get_dummy_variable(self):
351371
"""Test if you receive the name of the dummy variable in a ugrid dataset"""
352372
# Arrange
353373
var_list = ["var1", "var2", "var3", "var4", "var5"]
354-
ds = _xr.Dataset(data_vars=dict.fromkeys(var_list))
374+
ds = _xr.Dataset(data_vars={k: None for k in var_list})
355375
ds["var1"].attrs = {
356376
"cf_role": "mesh_topology",
357377
"test_coordinates": "var2 var3",
@@ -369,7 +389,7 @@ def test_get_dummy_variable_if_none(self):
369389
"""Test if you receive nothing if there is no dependent variables in a ugrid dataset"""
370390
# Arrange
371391
var_list = ["var1", "var2", "var3", "var4", "var5"]
372-
ds = _xr.Dataset(data_vars=dict.fromkeys(var_list))
392+
ds = _xr.Dataset(data_vars={k: None for k in var_list})
373393

374394
# Act
375395
dummy_variable = utilities.get_dependent_vars_by_var_name(ds, "var1")

tests/data/entities/test_data_access_layer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def test_retrieve_file_names_gives_dict_with_single_empty_key_if_single_file_fou
298298

299299
def test_retrieve_file_names_gives_dict_with_multiple_keys_if_path_contains_asterisk():
300300
"""When calling retrieve_file_names with a path name
301-
including an asterisk, the result should be a dictionary
301+
including an asterisk, the result should be a dictionary
302302
with multiple entries, each key being the distinctive part
303303
of the file name, and the respective value the entire file name."""
304304

tests/data/entities/test_model_data_builder.py

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,36 @@
1717
from decoimpact.data.api.i_model_data import IModelData
1818
from decoimpact.data.entities.model_data_builder import ModelDataBuilder
1919

20-
contents: dict[str, Any] = dict(
21-
{
22-
"input-data": [
23-
{"dataset": {"filename": "test", "variable_mapping": {"foo": "bar"}}}
24-
],
25-
"rules": [
26-
{
27-
"multiply_rule": {
28-
"name": "testrule",
29-
"description": "test_mr_description",
30-
"multipliers": [1, 2.0],
31-
"input_variable": "testin",
32-
"output_variable": "testout",
33-
}
34-
},
35-
{
36-
"step_function_rule": {
37-
"name": "test_name_step_function_rule",
38-
"description": "test_sfr_description",
39-
"limit_response_table": [
40-
["limit", "response"],
41-
[1, 10],
42-
[2.0, 20],
43-
],
44-
"input_variable": "test_in_sfr",
45-
"output_variable": "test_out_sfr",
46-
}
47-
},
48-
],
49-
"output-data": {"filename": "test"},
50-
}
51-
)
20+
contents: dict[str, Any] = {
21+
"input-data": [
22+
{"dataset": {"filename": "test", "variable_mapping": {"foo": "bar"}}}
23+
],
24+
"rules": [
25+
{
26+
"multiply_rule": {
27+
"name": "testrule",
28+
"description": "test_mr_description",
29+
"multipliers": [1, 2.0],
30+
"input_variable": "testin",
31+
"output_variable": "testout",
32+
}
33+
},
34+
{
35+
"step_function_rule": {
36+
"name": "test_name_step_function_rule",
37+
"description": "test_sfr_description",
38+
"limit_response_table": [
39+
["limit", "response"],
40+
[1, 10],
41+
[2.0, 20],
42+
],
43+
"input_variable": "test_in_sfr",
44+
"output_variable": "test_out_sfr",
45+
}
46+
},
47+
],
48+
"output-data": {"filename": "test"},
49+
}
5250

5351

5452
def test_model_data_builder_parse_dict_to_model_data():

tests/data/parsers/test_parser_axis_filter_rule.py

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,14 @@ def test_parser_axis_filter_rule_creation_logic():
3333
def test_parse_dict_to__axis_rule_data_logic():
3434
"""Test if a correct dictionary is parsed into a RuleData object"""
3535
# Arrange
36-
contents = dict(
37-
{
38-
"name": "testname",
39-
"description": "description",
40-
"input_variable": "input",
41-
"layer_number": 3,
42-
"axis_name": "axis_name",
43-
"output_variable": "output",
44-
}
45-
)
36+
contents = {
37+
"name": "testname",
38+
"description": "description",
39+
"input_variable": "input",
40+
"layer_number": 3,
41+
"axis_name": "axis_name",
42+
"output_variable": "output",
43+
}
4644
logger = Mock(ILogger)
4745

4846
# Act
@@ -56,15 +54,13 @@ def test_parse_dict_to__axis_rule_data_logic():
5654
def test_parse_wrong_dict_to_axis_rule_data_logic():
5755
"""Test if an incorrect dictionary is not parsed"""
5856
# Arrange
59-
contents = dict(
60-
{
61-
"name": "testname",
62-
"description": "description",
63-
"layer_number": 3,
64-
"input_variable": "input",
65-
"output_variable": "output",
66-
}
67-
)
57+
contents = {
58+
"name": "testname",
59+
"description": "description",
60+
"layer_number": 3,
61+
"input_variable": "input",
62+
"output_variable": "output",
63+
}
6864
logger = Mock(ILogger)
6965

7066
# Act
@@ -83,16 +79,14 @@ def test_parse_wrong_dict_to_axis_rule_data_logic():
8379
def test_parse_axis_name_type():
8480
"""Test if an incorrect dictionary is not parsed"""
8581
# Arrange
86-
contents = dict(
87-
{
88-
"name": "testname",
89-
"description": "description",
90-
"input_variable": "input",
91-
"layer_number": 3,
92-
"axis_name": 3,
93-
"output_variable": "output",
94-
}
95-
)
82+
contents = {
83+
"name": "testname",
84+
"description": "description",
85+
"input_variable": "input",
86+
"layer_number": 3,
87+
"axis_name": 3,
88+
"output_variable": "output",
89+
}
9690
logger = Mock(ILogger)
9791

9892
# Act

0 commit comments

Comments
 (0)