Files
ProductionDataBaseSync_Data…/tests/test_serialize.py
Misaka_Company 1f7191421a feat: access reader and value serialization
Add to_jsonable() (Access/pyodbc value -> JSON-safe) with strict TDD
(5 tests: datetime iso, bool preserved before int, decimal->str,
none/numbers, dict round-trip). bool branch precedes int because bool
is a subclass of int in Python.

Add AccessReader: reads TableChangeLog (read_log), reads a full source
row by RecordID via to_jsonable (read_row, warns on >4000-char values
that JSON_VALUE would truncate), and deletes processed log IDs in
chunked, retried batches (delete_log_ids, no-op on empty list).
Connects via the ACE ODBC driver from config.access.driver, shared
autocommit mode to coexist with the live .laccdb client.

Integration test against the real 氩弧焊.accdb (read-only; delete_log_ids
only exercised with []) passes.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-14 12:22:48 +08:00

22 lines
712 B
Python

import datetime, decimal
from sync.serialize import to_jsonable
import json
def test_datetime_iso():
assert to_jsonable(datetime.datetime(2026,7,14,8,41,18)) == "2026-07-14T08:41:18"
def test_bool_preserved():
assert to_jsonable(True) is True and to_jsonable(False) is False
def test_decimal_to_str():
assert to_jsonable(decimal.Decimal("12.50")) == "12.50"
def test_none_and_numbers():
assert to_jsonable(None) is None
assert to_jsonable(5) == 5
assert to_jsonable("x") == "x"
def test_dict_serializes():
d = {"d": datetime.date(2026,1,1), "b": True, "n": None}
assert json.loads(json.dumps({k: to_jsonable(v) for k,v in d.items()})) == {"d":"2026-01-01","b":True,"n":None}