Add unit tests for converter, source mapping, and record classes#117
Open
RSBalchII wants to merge 1 commit into
Open
Add unit tests for converter, source mapping, and record classes#117RSBalchII wants to merge 1 commit into
RSBalchII wants to merge 1 commit into
Conversation
- Adds test_converter.py validating all documented conversion factors from UNIT_CONVERSIONS.md, non-detect marker handling, and graceful failure paths. - Adds test_source_mapping.py to catch drift between PARAMETER_SOURCE_MAP and ANALYTE_OPTIONS in constants.py. - Adds test_record_classes.py verifying SiteRecord defaults, sigfig rounding behavior, and expected key sets for Summary/Parameter records. - Discovered bug: mg/L as CaCO3 conversions (bicarbonate, calcium, carbonate) return factor=None because the code checks 'mg/l caco3' but lowercased input is 'mg/l as caco3'. Tests document this known issue until it's resolved.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Added 45 comprehensive unit tests for the converter module and related components, covering unit conversion logic, configuration consistency, and record schema validation. All tests pass with zero regressions and zero new dependencies.
What's Tested
tests/test_converter.py(248 lines, ~35 assertions)Validates every conversion factor documented in UNIT_CONVERSIONS.md plus edge cases:
<,>,ND, etc. coerce to 0.0 correctlyfactor=Nonewithout crashingtests/test_source_mapping.py(48 lines, 4 tests)Catches configuration drift between two separate config sources:
PARAMETER_OPTIONShas ≥1 source definedPARAMETER_SOURCE_MAPANALYTE_OPTIONSentries matchPARAMETER_SOURCE_MAPkeysSOURCE_KEYStests/test_record_classes.py(119 lines, 7 tests)Validates record schema contracts and behavior:
Test Results
✅ All 45 new tests passing in 1.26s
✅ Full suite: 432 tests passed (0 regressions)
✅ Zero new dependencies (uses only pytest, already in dev requirements)
Bug Discovered & Documented
CaCO₃ String Mismatch in
backend/converter.pyBicarbonate, calcium, and carbonate conversions fail due to a unit string mismatch:
Result: These three chemistry conversions return
factor=Noneinstead of the documented factors (×1.22, ×0.4, ×0.6).Documentation: See
tests/test_converter.pylines 94-124 for detailed documentation:Files Changed
Running Tests
Testing Approach
Checklist