Skip to content

Commit 2634c79

Browse files
committed
Run "black" code formatter on tests
1 parent f0937fd commit 2634c79

17 files changed

+446
-288
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ virtualenv-dev: setup-virtualenv
3232
lint: virtualenv-dev
3333
$(flakehell) lint data_generator query_timer
3434
$(flakehell) lint batch_size_automator float_simulator tictrack
35-
#$(flakehell) lint tests
35+
$(flakehell) lint tests
3636

3737
format: virtualenv-dev
3838
$(black) data_generator query_timer
3939
$(black) batch_size_automator float_simulator tictrack
40+
$(black) tests
4041

4142
test: virtualenv-dev
4243
$(pytest) -vvv tests

tests/test_crate_db_writer.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from tests.test_models import test_model, test_model2
55

66

7-
@mock.patch.object(client, 'connect', autospec=True)
7+
@mock.patch.object(client, "connect", autospec=True)
88
def test_close_connection(mock_connect):
99
"""
1010
This function tests if the .close() functions of the self.conn and self.cursor objects is called
@@ -25,14 +25,16 @@ def test_close_connection(mock_connect):
2525
mock_connect.return_value = conn
2626
conn.cursor.return_value = cursor
2727
db_writer = CrateDbWriter("localhost:4200", "crate", "password", test_model)
28-
mock_connect.assert_called_with("localhost:4200", username="crate", password="password")
28+
mock_connect.assert_called_with(
29+
"localhost:4200", username="crate", password="password"
30+
)
2931
# Test Case 1:
3032
db_writer.close_connection()
3133
conn.close.assert_called()
3234
cursor.close.assert_called()
3335

3436

35-
@mock.patch.object(client, 'connect', autospec=True)
37+
@mock.patch.object(client, "connect", autospec=True)
3638
def test_prepare_database1(mock_connect):
3739
"""
3840
This function tests if the .prepare_database() functions of the db_writer uses the correct values when
@@ -58,7 +60,9 @@ def test_prepare_database1(mock_connect):
5860
mock_connect.return_value = conn
5961
conn.cursor.return_value = cursor
6062
db_writer = CrateDbWriter("localhost:4200", "crate2", "password2", test_model)
61-
mock_connect.assert_called_with("localhost:4200", username="crate2", password="password2")
63+
mock_connect.assert_called_with(
64+
"localhost:4200", username="crate2", password="password2"
65+
)
6266
# Test Case 1:
6367
db_writer.prepare_database()
6468
stmt = cursor.execute.call_args.args[0]
@@ -72,7 +76,7 @@ def test_prepare_database1(mock_connect):
7276
assert "number_of_replicas = 1" in stmt
7377

7478

75-
@mock.patch.object(client, 'connect', autospec=True)
79+
@mock.patch.object(client, "connect", autospec=True)
7680
def test_prepare_database2(mock_connect):
7781
"""
7882
This function tests if the .prepare_database() functions of the db_writer uses the correct values when
@@ -97,7 +101,9 @@ def test_prepare_database2(mock_connect):
97101
cursor = mock.Mock()
98102
mock_connect.return_value = conn
99103
conn.cursor.return_value = cursor
100-
db_writer = CrateDbWriter("localhost:4200", "crate3", "password3", test_model2, "table_name", 3, 0, "day")
104+
db_writer = CrateDbWriter(
105+
"localhost:4200", "crate3", "password3", test_model2, "table_name", 3, 0, "day"
106+
)
101107
db_writer.prepare_database()
102108
# Test Case 1:
103109
stmt = cursor.execute.call_args.args[0]
@@ -111,7 +117,7 @@ def test_prepare_database2(mock_connect):
111117
assert "number_of_replicas = 0" in stmt
112118

113119

114-
@mock.patch.object(client, 'connect', autospec=True)
120+
@mock.patch.object(client, "connect", autospec=True)
115121
def test_insert_stmt(mock_connect):
116122
"""
117123
This function tests if the .insert_stmt() functions of CrateDbWriter uses the correct table name and arguments
@@ -134,15 +140,24 @@ def test_insert_stmt(mock_connect):
134140
conn.cursor.return_value = cursor
135141
db_writer = CrateDbWriter("localhost:4200", "crate2", "password2", test_model)
136142
# Test Case 1:
137-
db_writer.insert_stmt([1586327807000], [{"plant": 1, "line": 1, "sensor_id": 1, "value": 6.7, "button_press": False}])
143+
db_writer.insert_stmt(
144+
[1586327807000],
145+
[{"plant": 1, "line": 1, "sensor_id": 1, "value": 6.7, "button_press": False}],
146+
)
138147
call_arguments = cursor.execute.call_args.args
139148
stmt = call_arguments[0]
140149
values = call_arguments[1]
141-
assert stmt == "INSERT INTO temperature (ts, payload) (SELECT col1, col2 FROM UNNEST(?,?))"
142-
assert values == ([1586327807000], [{"plant": 1, "line": 1, "sensor_id": 1, "value": 6.7, "button_press": False}])
150+
assert (
151+
stmt
152+
== "INSERT INTO temperature (ts, payload) (SELECT col1, col2 FROM UNNEST(?,?))"
153+
)
154+
assert values == (
155+
[1586327807000],
156+
[{"plant": 1, "line": 1, "sensor_id": 1, "value": 6.7, "button_press": False}],
157+
)
143158

144159

145-
@mock.patch.object(client, 'connect', autospec=True)
160+
@mock.patch.object(client, "connect", autospec=True)
146161
def test_execute_query(mock_connect):
147162
"""
148163
This function tests if the .execute_query() functions of CrateDbWriter uses the correct query

tests/test_dg_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def test_config_constructor_no_env_set():
2020
assert config.stat_delta == 30
2121

2222
assert config.host == "localhost"
23-
assert config.username == None
24-
assert config.password == None
23+
assert config.username is None
24+
assert config.password is None
2525
assert config.db_name == ""
2626
assert config.table_name == ""
2727
assert config.partition == "week"

tests/test_dg_main.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@
1111
@mock.patch("data_generator.__main__.MsSQLDbWriter", autospec=True)
1212
@mock.patch("data_generator.__main__.PostgresDbWriter", autospec=True)
1313
@mock.patch("data_generator.__main__.TimeStreamWriter", autospec=True)
14-
def test_get_db_writer(mock_timestream, mock_postgres, mock_mssql, mock_mongo, mock_influx, mock_timescale, mock_crate):
14+
def test_get_db_writer(
15+
mock_timestream,
16+
mock_postgres,
17+
mock_mssql,
18+
mock_mongo,
19+
mock_influx,
20+
mock_timescale,
21+
mock_crate,
22+
):
1523
dg.config.database = 0
1624
dg.get_db_writer()
1725
mock_crate.assert_called_once()
@@ -242,4 +250,3 @@ def test_stop_process():
242250
dg.stop_queue.put(1)
243251
assert dg.stop_process()
244252
dg.stop_queue.get() # resetting the stop queue
245-

tests/test_edge.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import pytest
22
import numpy
33
from data_generator.edge import Edge, BoolSensor
4-
from tests.test_models import metrics_model_float1_bool1, metrics_model_string, \
5-
tag_model_plant100_line5_sensorId, bool_model, tag_model_list
4+
from tests.test_models import (
5+
metrics_model_float1_bool1,
6+
metrics_model_string,
7+
tag_model_plant100_line5_sensorId,
8+
bool_model,
9+
tag_model_list,
10+
)
611

712

813
def test_init_sensors():

tests/test_influx_db_writer.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ def test_prepare_database_bucket_exists(mock_client):
5656
db_writer = InfluxDbWriter("localhost", "token1", "org1", test_model)
5757
mock_client.assert_called_with("localhost", token="token1")
5858
bucket_list = DotMap()
59-
bucket_list.buckets = [Bucket(name="", retention_rules=[]), Bucket(name="temperature", retention_rules=[])]
59+
bucket_list.buckets = [
60+
Bucket(name="", retention_rules=[]),
61+
Bucket(name="temperature", retention_rules=[]),
62+
]
6063
buckets_api.find_buckets.return_value = bucket_list
6164
# Test Case 1:
6265
db_writer.prepare_database()
@@ -88,7 +91,10 @@ def test_prepare_database_bucket_not_exists(mock_client):
8891
db_writer = InfluxDbWriter("localhost", "token2", "org2", test_model)
8992
mock_client.assert_called_with("localhost", token="token2")
9093
bucket_list = DotMap()
91-
bucket_list.buckets = [Bucket(name="x", retention_rules=[]), Bucket(name="y", retention_rules=[])]
94+
bucket_list.buckets = [
95+
Bucket(name="x", retention_rules=[]),
96+
Bucket(name="y", retention_rules=[]),
97+
]
9298
buckets_api.find_buckets.return_value = bucket_list
9399
# Test Case 1:
94100
db_writer.prepare_database()
@@ -120,8 +126,10 @@ def test_insert_stmt(mock_client):
120126
client.write_api.return_value = write_api
121127
db_writer = InfluxDbWriter("localhost", "token", "org", test_model)
122128
# Test Case 1:
123-
db_writer.insert_stmt([1586327807000],
124-
[{"plant": 2, "line": 2, "sensor_id": 2, "value": 6.7, "button_press": False}])
129+
db_writer.insert_stmt(
130+
[1586327807000],
131+
[{"plant": 2, "line": 2, "sensor_id": 2, "value": 6.7, "button_press": False}],
132+
)
125133
call_arguments = write_api.write.call_args[1]
126134
org = call_arguments["org"]
127135
data = call_arguments["record"]

0 commit comments

Comments
 (0)