Skip to content

test: add error-path and asymmetry characterisation tests#109

Open
leftygbalogh wants to merge 1 commit intodavidhewitt:mainfrom
leftygbalogh:lefty/tests-error-paths-and-asymmetry
Open

test: add error-path and asymmetry characterisation tests#109
leftygbalogh wants to merge 1 commit intodavidhewitt:mainfrom
leftygbalogh:lefty/tests-error-paths-and-asymmetry

Conversation

@leftygbalogh
Copy link
Copy Markdown
Contributor

Summary

Adds characterisation and error-path tests covering type-mismatch cases and asymmetric round-trip behaviours.

Files added

tests/test_error_paths.rs (8 tests)

  • HashMap<i64, V> serialized by pythonize -> Ok (unexpected: DictKeyNotString lives in the deserializer only; see note below)
  • HashMap<bool, V> -> same root cause
  • Python str -> depythonize::<i64> -> Err
  • Python bytes -> depythonize::<String> -- characterised
  • Python None / list -> depythonize::<i64> -> Err

tests/test_asymmetry.rs (16 tests)

  • BTreeMap content equality after round-trip
  • f32 precision: MIN_POSITIVE, PI, subnormal -- all survive; // BASELINE: comments note the f64 widening
  • char length guard: "ab" and "hello" -> Err (correct rejection)
  • bool -> i64/i32: Ok(1)/Ok(0) -- Python bool subclasses int
  • i64(300) -> i8/u8 overflow -> Err (no silent truncation)
  • f64::NAN -> Python -> f32: Ok(NaN) -- NaN survives narrowing
  • Unit () round-trip: Ok

Notable findings

Non-string map keys serialize without error (HashMap<i64, V>, HashMap<bool, V>): pythonize produces a Python dict with non-string keys -- the DictKeyNotString check exists only in the deserializer. The round-trip breaks silently on the deserialization side. Tests assert the observed Ok and are flagged // BASELINE: UNEXPECTED.

Test approach

Plain #[test] functions using Python::attach. No new dev-dependencies. Characterisation tests use // BASELINE: comments; surprising cases are additionally flagged // BASELINE: UNEXPECTED.

tests/test_error_paths.rs (8 tests): non-string map key characterisation,
type mismatch error paths, Python bytes/None/list depythonize behaviour

tests/test_asymmetry.rs (16 tests): f32 precision, bool coercion, char
length guard, int overflow, f64 NaN+Inf, BTreeMap ordering, unit round-trip

Baseline-unexpected findings are flagged with BASELINE: UNEXPECTED comments.
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.49%. Comparing base (0085a18) to head (e3830df).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #109      +/-   ##
==========================================
+ Coverage   84.48%   85.49%   +1.01%     
==========================================
  Files           3        3              
  Lines        1186     1186              
  Branches     1186     1186              
==========================================
+ Hits         1002     1014      +12     
+ Misses        118      107      -11     
+ Partials       66       65       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@davidhewitt
Copy link
Copy Markdown
Owner

What are these AC-1, AC-2 notes all over the files?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants