SIENTIAPDE-1973: Refactor unit tests for improved readability, primarily by splitting chained assertions into individual statements and minor fixture import adjustments.
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
from unittest.mock import AsyncMock, MagicMock
|
||||
|
||||
from pytest import fixture
|
||||
import pytest
|
||||
|
||||
|
||||
@fixture
|
||||
@pytest.fixture
|
||||
def reader_double():
|
||||
"""Factory of OPC reader doubles holding subscriptions for the given slots.
|
||||
|
||||
Like the real readers (ServerReader, OpcManager), `subscriptions` is keyed by slot
|
||||
Like the real ServerReader, `subscriptions` is keyed by slot
|
||||
and `unsubscribe` drops the slot from it.
|
||||
"""
|
||||
|
||||
|
||||
@@ -46,7 +46,8 @@ async def test_local_files_keep_the_object_extension(tmp_path):
|
||||
|
||||
cert, key = await provider.fetch(certificate(ext='der'))
|
||||
|
||||
assert cert.endswith('cert.der') and key.endswith('key.der')
|
||||
assert cert.endswith('cert.der')
|
||||
assert key.endswith('key.der')
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -61,9 +62,10 @@ async def test_local_files_keep_the_object_extension(tmp_path):
|
||||
)
|
||||
async def test_fetch_of_an_incomplete_certificate_raises_clear_error(tmp_path, broken):
|
||||
provider, minio = _provider(tmp_path)
|
||||
incomplete = {**certificate(), **broken}
|
||||
|
||||
with pytest.raises(CertificateNotConfiguredError, match='opc_certificates|certificate_id'):
|
||||
await provider.fetch({**certificate(), **broken})
|
||||
await provider.fetch(incomplete)
|
||||
minio.download_file.assert_not_awaited()
|
||||
|
||||
|
||||
|
||||
@@ -5,4 +5,6 @@ def test_elapsed_is_non_negative_and_monotonic():
|
||||
clk = MonotonicClock()
|
||||
a = clk.elapsed()
|
||||
b = clk.elapsed()
|
||||
assert a >= 0 and b >= a # never negative even if wall clock jumps back
|
||||
# never negative even if wall clock jumps back
|
||||
assert a >= 0
|
||||
assert b >= a
|
||||
|
||||
@@ -346,8 +346,10 @@ async def test_write_error_logs_the_reason_and_sets_the_model_status():
|
||||
await eng.write(base_cmd())
|
||||
|
||||
logged = eng.logger.error.call_args.args[0]
|
||||
assert 'RuntimeError' in logged and 'BadWriteNotSupported' in logged
|
||||
assert 'addr=ns=2;i=5' in logged and 'model_id=m1' in logged
|
||||
assert 'RuntimeError' in logged
|
||||
assert 'BadWriteNotSupported' in logged
|
||||
assert 'addr=ns=2;i=5' in logged
|
||||
assert 'model_id=m1' in logged
|
||||
status_call = next(
|
||||
c
|
||||
for c in eng.emit_metric.await_args_list
|
||||
|
||||
@@ -58,7 +58,8 @@ async def test_update_write_status_targets_model_row_with_precedence():
|
||||
assert sql.startswith('UPDATE sientia_data.pred_m1 SET write_status=')
|
||||
assert 'CASE sientia_data.pred_m1.write_status WHEN' in sql
|
||||
# values must be bound params, never interpolated into the SQL text itself
|
||||
assert '2026-07-13T00:00:00Z' not in sql and "'ok'" not in sql
|
||||
assert '2026-07-13T00:00:00Z' not in sql
|
||||
assert "'ok'" not in sql
|
||||
assert compiled.params['write_status'] == 'ok'
|
||||
assert '2026-07-13T00:00:00Z' in compiled.params.values()
|
||||
assert _outcome_metric(sink) == 'updated'
|
||||
|
||||
Reference in New Issue
Block a user