Skip to content

Commit 5ff7989

Browse files
committed
Chore: Format code
1 parent d13dc94 commit 5ff7989

38 files changed

+192
-409
lines changed

pyproject.toml

+43-33
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,3 @@
1-
[tool.pytest.ini_options]
2-
minversion = "2.0"
3-
addopts = """
4-
-rfsEX -p pytester --strict-markers --verbosity=3
5-
--cov --cov-report=term-missing --cov-report=xml
6-
--capture=no
7-
"""
8-
log_level = "DEBUG"
9-
log_cli_level = "DEBUG"
10-
testpaths = ["tests"]
11-
xfail_strict = true
12-
markers = [
13-
]
14-
15-
[tool.coverage.run]
16-
branch = false
17-
source = ["tsdg", "tsperf", "tsqt"]
18-
omit = [
19-
"tests/*",
20-
"tsperf/write/cli.py",
21-
"tsperf/read/cli.py",
22-
]
23-
24-
[tool.coverage.report]
25-
fail_under = 0
26-
show_missing = true
27-
omit = [
28-
"tests/*",
29-
"tsperf/write/cli.py",
30-
"tsperf/read/cli.py",
31-
]
32-
331
[tool.ruff]
342
line-length = 120
353

@@ -70,15 +38,57 @@ lint.extend-ignore = [
7038

7139
[tool.ruff.lint.per-file-ignores]
7240
"tests/*" = [
73-
# Use of `assert` detected.
41+
# Use of `assert` detected
7442
"S101",
43+
# Possible hardcoded password assigned to: "password"
44+
"S105",
45+
# Possible hardcoded password assigned to argument: "password"
46+
"S106",
47+
# Standard pseudo-random generators are not suitable for cryptographic purposes
48+
"S311",
49+
]
50+
"tsperf/util/float_simulator/__init__.py" = [
51+
# Standard pseudo-random generators are not suitable for cryptographic purposes
52+
"S311",
7553
]
7654

7755

7856
# ===================
7957
# Tasks configuration
8058
# ===================
8159

60+
[tool.pytest.ini_options]
61+
minversion = "2.0"
62+
addopts = """
63+
-rfsEX -p pytester --strict-markers --verbosity=3
64+
--cov --cov-report=term-missing --cov-report=xml
65+
--capture=no
66+
"""
67+
log_level = "DEBUG"
68+
log_cli_level = "DEBUG"
69+
testpaths = ["tests"]
70+
xfail_strict = true
71+
markers = [
72+
]
73+
74+
[tool.coverage.run]
75+
branch = false
76+
source = ["tsdg", "tsperf", "tsqt"]
77+
omit = [
78+
"tests/*",
79+
"tsperf/write/cli.py",
80+
"tsperf/read/cli.py",
81+
]
82+
83+
[tool.coverage.report]
84+
fail_under = 0
85+
show_missing = true
86+
omit = [
87+
"tests/*",
88+
"tsperf/write/cli.py",
89+
"tsperf/read/cli.py",
90+
]
91+
8292
[tool.poe.tasks]
8393

8494
check = [

setup.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@
1818
"dnspython<3",
1919
"numpy<1.27",
2020
"pgcopy<1.7",
21-
#"pyodbc<5",
21+
# "pyodbc<5",
2222
"tqdm<5",
2323
"cloup<1",
2424
]
2525

2626
develop_requires = [
27-
"mypy<1.10",
28-
"poethepoet<0.26",
29-
"pyproject-fmt<1.8",
30-
"ruff<0.5",
31-
"validate-pyproject<0.17",
27+
"mypy<1.10",
28+
"poethepoet<0.26",
29+
"pyproject-fmt<1.8",
30+
"ruff<0.5",
31+
"validate-pyproject<0.17",
3232
]
3333

3434
release_requires = [
35-
"build<2",
36-
"twine<6",
35+
"build<2",
36+
"twine<6",
3737
]
3838

3939
test_requires = [
@@ -76,7 +76,7 @@
7676
"Topic :: Utilities",
7777
"Operating System :: POSIX",
7878
"Operating System :: Unix",
79-
"Operating System :: MacOS"
79+
"Operating System :: MacOS",
8080
],
8181
entry_points={
8282
"console_scripts": [

tests/adapter/test_cratedb.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ def test_close_connection(mock_connect):
4545
password="password",
4646
)
4747
db_writer = CrateDbAdapter(config=config, schema=test_schema1)
48-
mock_connect.assert_called_with(
49-
"localhost:4200", username="crate", password="password"
50-
)
48+
mock_connect.assert_called_with("localhost:4200", username="crate", password="password")
5149
# Test Case 1:
5250
db_writer.close_connection()
5351
conn.close.assert_called()
@@ -88,9 +86,7 @@ def test_prepare_database1(mock_connect):
8886
)
8987
db_writer = CrateDbAdapter(config=config, schema=test_schema1)
9088

91-
mock_connect.assert_called_with(
92-
"localhost:8200", username="crate2", password="password2"
93-
)
89+
mock_connect.assert_called_with("localhost:8200", username="crate2", password="password2")
9490
# Test Case 1:
9591
db_writer.prepare_database()
9692
stmt = cursor.execute.call_args.args[0]
@@ -181,10 +177,7 @@ def test_insert_stmt(mock_connect, config):
181177
call_arguments = cursor.execute.call_args.args
182178
stmt = call_arguments[0]
183179
values = call_arguments[1]
184-
assert (
185-
stmt
186-
== "INSERT INTO temperature (ts, payload) (SELECT col1, col2 FROM UNNEST(?,?))"
187-
)
180+
assert stmt == "INSERT INTO temperature (ts, payload) (SELECT col1, col2 FROM UNNEST(?,?))"
188181
assert values == (
189182
[1586327807000],
190183
[{"plant": 1, "line": 1, "sensor_id": 1, "value": 6.7, "button_press": False}],

tests/adapter/test_cratedbpg.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,7 @@ def test_insert_stmt(mock_connect, config):
192192
call_arguments = cursor.execute.call_args.args
193193
stmt = call_arguments[0]
194194
values = call_arguments[1]
195-
assert (
196-
stmt
197-
== "INSERT INTO temperature (ts, payload) (SELECT col1, col2 FROM UNNEST(?,?))"
198-
)
195+
assert stmt == "INSERT INTO temperature (ts, payload) (SELECT col1, col2 FROM UNNEST(?,?))"
199196
assert values == (
200197
[1586327807000],
201198
[{"plant": 1, "line": 1, "sensor_id": 1, "value": 6.7, "button_press": False}],

tests/adapter/test_timestream.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
def config():
1313
config = DatabaseConnectionConfiguration(
1414
adapter=DatabaseInterfaceType.Timestream,
15-
# address="ingest-cell1.timestream.us-west-2.amazonaws.com",
15+
# TODO: address="ingest-cell1.timestream.us-west-2.amazonaws.com",
1616
)
1717
return config
1818

@@ -33,16 +33,14 @@ def test_close_connection(mock_boto, config):
3333

3434
config = DatabaseConnectionConfiguration(
3535
adapter=DatabaseInterfaceType.Timestream,
36-
# address="ingest-cell1.timestream.us-west-2.amazonaws.com",
36+
# TODO: address="ingest-cell1.timestream.us-west-2.amazonaws.com",
3737
aws_access_key_id="foobar",
3838
aws_secret_access_key="bazqux",
3939
aws_region_name="us-west-2",
4040
)
4141
_ = AmazonTimestreamAdapter(config=config, schema=test_schema1)
4242

43-
mock_boto.session.Session.assert_called_with(
44-
"foobar", aws_secret_access_key="bazqux", region_name="us-west-2"
45-
)
43+
mock_boto.session.Session.assert_called_with("foobar", aws_secret_access_key="bazqux", region_name="us-west-2")
4644

4745

4846
@mock.patch("tsperf.adapter.timestream.boto3", autospec=True)

tests/read/test_tsqt_cli.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_read_cli():
1717
catch_exceptions=False,
1818
)
1919
assert result.exit_code == 0
20-
# assert result.output == 'Hello Peter!\n'
20+
assert result.output == "Hello Peter!\n"
2121

2222

2323
def test_read_cli_dryrun():

tests/read/test_tsqt_core.py

-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def config() -> QueryTimerConfig:
1717
@pytest.mark.parametrize("adapter", list(DatabaseInterfaceType))
1818
@mock.patch("tsperf.adapter.AdapterManager.create", autospec=True)
1919
def test_get_database_adapter(factory_mock, adapter, config):
20-
2120
config.adapter = adapter
2221
engine = TsPerfEngine(config=config)
2322
engine.bootstrap()
@@ -52,7 +51,6 @@ def test_percentage_to_rgb():
5251

5352
@mock.patch("tsperf.read.core.engine", autospec=True)
5453
def test_start_query_run(mock_engine, config):
55-
5654
mock_db_writer = mock.MagicMock()
5755
mock_db_writer.execute_query.side_effect = [[1, 2, 3], Exception("mocked failure")]
5856
mock_engine.create_adapter.return_value = mock_db_writer

tests/test_cli.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
def test_schema_list():
99
runner = CliRunner()
1010
result = runner.invoke(
11-
tsperf.cli.schema_list,
11+
tsperf.cli.schema,
1212
[
1313
"--list",
1414
],

tests/util/test_batch_size_automator.py

+16-51
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,10 @@ def test_insert_batch_time_normal():
115115
batch_size_automator.insert_batch_time(duration)
116116

117117
assert batch_size_automator.batch_times["best"]["avg_time"] == duration
118-
assert (
119-
batch_size_automator.batch_times["best"]["batch_per_second"]
120-
== initial_batch_size / duration
121-
)
118+
assert batch_size_automator.batch_times["best"]["batch_per_second"] == initial_batch_size / duration
122119
# because for the next iteration batch_size is increased by 500
123120
initial_step_size = 500
124-
assert (
125-
batch_size_automator.get_next_batch_size()
126-
== initial_batch_size + initial_step_size
127-
)
121+
assert batch_size_automator.get_next_batch_size() == initial_batch_size + initial_step_size
128122

129123
# Test Case 2:
130124
# five will be the first best time making 3000 the best batchsize
@@ -135,10 +129,7 @@ def test_insert_batch_time_normal():
135129
current_batch_per_second = current_batch_size / duration
136130

137131
assert batch_size_automator.batch_times["best"]["avg_time"] == duration
138-
assert (
139-
batch_size_automator.batch_times["best"]["batch_per_second"]
140-
== current_batch_per_second
141-
)
132+
assert batch_size_automator.batch_times["best"]["batch_per_second"] == current_batch_per_second
142133
batch_size = 3000 + batch_size_automator.step_size * batch_size_automator.alpha
143134
assert batch_size_automator.get_next_batch_size() == batch_size
144135

@@ -149,14 +140,10 @@ def test_insert_batch_time_normal():
149140
batch_size_automator.insert_batch_time(duration)
150141

151142
assert batch_size_automator.batch_times["best"]["avg_time"] == 5 # last duration
152-
assert (
153-
batch_size_automator.batch_times["best"]["batch_per_second"]
154-
== current_batch_per_second
155-
)
143+
assert batch_size_automator.batch_times["best"]["batch_per_second"] == current_batch_per_second
156144
# batch_size is decreased this time because no better value was found and calculated based on best_size
157145
batch_size = (
158-
batch_size_automator.batch_times["best"]["size"]
159-
- batch_size_automator.step_size * batch_size_automator.alpha
146+
batch_size_automator.batch_times["best"]["size"] - batch_size_automator.step_size * batch_size_automator.alpha
160147
)
161148
assert batch_size_automator.get_next_batch_size() == batch_size
162149

@@ -172,9 +159,7 @@ def test_insert_batch_time_normal():
172159
== batch_size_automator.batch_times["best"]["size"] / duration
173160
)
174161
# batch_size is further decreased
175-
batch_size = (
176-
batch_size - batch_size_automator.step_size * batch_size_automator.alpha
177-
)
162+
batch_size = batch_size - batch_size_automator.step_size * batch_size_automator.alpha
178163
assert batch_size_automator.get_next_batch_size() == batch_size
179164

180165
# Test Case 5:
@@ -233,16 +218,12 @@ def test_insert_batch_time_smallest_batch():
233218
batch_size_automator.insert_batch_time(worse_duration)
234219

235220
# now we get better each time until we reach batch_size 1
236-
duration = (
237-
batch_size_automator.batch_size
238-
/ batch_size_automator.batch_times["best"]["batch_per_second"]
239-
) - 10
221+
duration = (batch_size_automator.batch_size / batch_size_automator.batch_times["best"]["batch_per_second"]) - 10
240222
batch_size = batch_size_automator.batch_size
241223
while batch_size_automator.batch_size != 1:
242224
if batch_size != batch_size_automator.batch_size:
243225
duration = (
244-
batch_size_automator.batch_size
245-
/ batch_size_automator.batch_times["best"]["batch_per_second"]
226+
batch_size_automator.batch_size / batch_size_automator.batch_times["best"]["batch_per_second"]
246227
) - 10
247228
batch_size = batch_size_automator.batch_size
248229
batch_size_automator.insert_batch_time(duration)
@@ -283,55 +264,39 @@ def test_step_size_is_default():
283264
def test_step_size_is_data_batch_size():
284265
default_step_size = 500
285266
data_batch_size = 1000
286-
batch_size_automator = BatchSizeAutomator(
287-
0, data_batch_size=data_batch_size, step_size=default_step_size
288-
)
267+
batch_size_automator = BatchSizeAutomator(0, data_batch_size=data_batch_size, step_size=default_step_size)
289268

290269
assert batch_size_automator.step_size == data_batch_size
291270

292271

293272
def test_batch_size_is_multitude_of_data_batch_size():
294273
data_batch_size = 500
295274
batch_size = 700
296-
batch_size_automator = BatchSizeAutomator(
297-
batch_size, data_batch_size=data_batch_size
298-
)
275+
batch_size_automator = BatchSizeAutomator(batch_size, data_batch_size=data_batch_size)
299276

300277
assert batch_size_automator.batch_size == 500
301278

302279
data_batch_size = 500
303280
batch_size = 800
304-
batch_size_automator = BatchSizeAutomator(
305-
batch_size, data_batch_size=data_batch_size
306-
)
281+
batch_size_automator = BatchSizeAutomator(batch_size, data_batch_size=data_batch_size)
307282

308283
assert batch_size_automator.batch_size == 1000
309284

310285
data_batch_size = 500
311286
batch_size = 400
312-
batch_size_automator = BatchSizeAutomator(
313-
batch_size, data_batch_size=data_batch_size
314-
)
287+
batch_size_automator = BatchSizeAutomator(batch_size, data_batch_size=data_batch_size)
315288

316289
assert batch_size_automator.batch_size == 500
317290

318291

319292
def test_batch_size_change_is_at_least_data_batch_size():
320293
data_batch_size = 500
321294
test_size = 1
322-
batch_size_automator = BatchSizeAutomator(
323-
0, data_batch_size=data_batch_size, test_size=test_size
324-
)
295+
batch_size_automator = BatchSizeAutomator(0, data_batch_size=data_batch_size, test_size=test_size)
325296

326297
# initial test cycle:
327298
batch_size_automator.insert_batch_time(1)
328-
assert (
329-
batch_size_automator.get_next_batch_size() == 3000
330-
) # initially bath_size will go up
299+
assert batch_size_automator.get_next_batch_size() == 3000 # initially bath_size will go up
331300
# second test cycle:
332-
batch_size_automator.insert_batch_time(
333-
2
334-
) # worse batch performance reduces alpha and leads to smaller step_size
335-
assert (
336-
batch_size_automator.get_next_batch_size() == 2000
337-
) # batch_size is changed by at least data_batch_size
301+
batch_size_automator.insert_batch_time(2) # worse batch performance reduces alpha and leads to smaller step_size
302+
assert batch_size_automator.get_next_batch_size() == 2000 # batch_size is changed by at least data_batch_size

0 commit comments

Comments
 (0)