File size: 3,465 Bytes
622387b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
set -uxo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd /workspace
git config --global --add safe.directory /workspace
mkdir -p /logs/verifier
git checkout 96ce8cdb55614c2d62c9a9abb561c9a338698643 -- tests/test_cams_units.py tests/test_helpers.py || true
git apply --verbose --reject - <<'EOF_R2E_TEST_PATCH'
diff --git a/tests/test_cams_units.py b/tests/test_cams_units.py
index c6aa892..b9c1fe9 100644
--- a/tests/test_cams_units.py
+++ b/tests/test_cams_units.py
@@ -236,6 +236,24 @@ class TestContinuationMerge:
         txns = _txns(parse_lines(rows))
         assert txns[0].description == "Purchase - BSE -"
 
+    def test_reclassified_type_stays_enum_and_serializes_clean(self, parse_lines):
+        # Post-construction `txn.type` assignment bypasses pydantic
+        # validation; assigning `.name` (a str) into the enum-typed field
+        # trips PydanticSerializationUnexpectedValue on every JSON export
+        # (issue #118 follow-up). The merge path must assign the enum.
+        import warnings as _warnings
+
+        from casparser.enums import TransactionType as TT
+
+        rows = [PURCHASE_ROW, L(672.5, (75, "Instalment 5/18")), REDEMPTION_ROW]
+        data = parse_lines(rows)
+        for t in _txns(data):
+            assert isinstance(t.type, TT), f"{t.description!r}: {type(t.type)}"
+        with _warnings.catch_warnings(record=True) as caught:
+            _warnings.simplefilter("always")
+            data.model_dump_json()
+        assert [str(w.message) for w in caught] == []
+
     def test_balances_still_reconcile(self, parse_lines):
         rows = [PURCHASE_ROW, L(672.5, (75, "Instalment 5/18")), REDEMPTION_ROW]
         data = parse_lines(rows)
diff --git a/tests/test_helpers.py b/tests/test_helpers.py
index 15a02bf..2ea2265 100644
--- a/tests/test_helpers.py
+++ b/tests/test_helpers.py
@@ -386,6 +386,10 @@ class TestBalanceSignFix:
         # units + a non-SIP/non-switch/non-segregat description maps
         # to PURCHASE in the classifier's positive branch.
         assert t.type == TransactionType.PURCHASE
+        # ... and as the enum itself, not its `.name` str — attribute
+        # assignment bypasses pydantic validation, and a raw str trips
+        # serializer warnings on JSON export.
+        assert isinstance(t.type, TransactionType)
         # close_calculated reflects the corrected sum.
         assert scheme.close_calculated == Decimal("729.903")
 

EOF_R2E_TEST_PATCH
R2E_APPLY_RC=$?
if [ "$R2E_APPLY_RC" -ne 0 ]; then
  echo "0.000000" > /logs/verifier/reward.txt
  printf '%s' '{"reward": 0.0, "resolved": false, "parse_status": "test_patch_apply_failed"}' > /logs/verifier/reward-details.json
  echo "R2E: test_patch failed to apply (rc=$R2E_APPLY_RC) — failing closed" >&2
  exit 0
fi
( python -m pytest -v tests/test_cams_units.py tests/test_helpers.py ) > /logs/verifier/test_output.log 2>&1
TEST_EXIT_CODE=$?
cat /logs/verifier/test_output.log
python3 "$SCRIPT_DIR/verifier.py" --log /logs/verifier/test_output.log --f2p "$SCRIPT_DIR/f2p.json" --p2p "$SCRIPT_DIR/p2p.json" --test-cmds 'python -m pytest -v tests/test_cams_units.py tests/test_helpers.py' --exit-code "$TEST_EXIT_CODE" --out-dir /logs/verifier || { [ "$TEST_EXIT_CODE" -eq 0 ] && echo "1.0" > /logs/verifier/reward.txt || echo "0.0" > /logs/verifier/reward.txt; }
git checkout 96ce8cdb55614c2d62c9a9abb561c9a338698643 -- tests/test_cams_units.py tests/test_helpers.py || true
exit 0