Fix bugs in core classes + add test suite and CI pipeline#9
Fix bugs in core classes + add test suite and CI pipeline#9kartikeyg0104 wants to merge 1 commit intoEAPD-DRB:mainfrom
Conversation
…mThread.join timeout, add pytest suite + CI - Fix 'e''t' string concatenation bug in PARAMETERS_C['EmissionActivityRatio'] that silently produced ['r','et','y','m'] instead of ['r','e','t','y','m'] - Refactor FileClass to use context managers (with statement) for all file I/O to prevent file handle leaks on exceptions - Fix CustomThread.join() to accept optional timeout parameter matching Thread.join() signature - Add pytest test suite with 25 tests covering FileClass, Config, and CustomThread - Add GitHub Actions CI workflow running lint + tests on Python 3.10-3.12 across Ubuntu, macOS, and Windows - Add pytest.ini configuration - Add __pycache__/ to .gitignore
|
Thank you. Please keep this as a draft fo now until we examine the issue and weather it should be upstream or here. |
|
I like the testing infrastructure. Can you open that as a separate issue? |
Hi @SeaCelo, thanks for the feedback! I've opened #14 to track the testing infrastructure separately as you suggested. Happy to keep this PR as a draft, I'll wait for your decision on whether the bug fixes should go upstream or stay here before making any further changes. Let me know if there's anything else you'd like adjusted. |
|
Hey, great catch on the EmissionActivityRatio dimension typo! Since we are laying the groundwork for the OG-CLEWS integration, I had a quick architectural thought regarding the data pipelines when you port this: 1. Dimension Extensibility (test_config.py):In 2. Large Dataset Memory Handling (FileClass.py):Love the move to context managers! One quick optimization for the model runs: using Really clean refactor overall! The file handle leak fix is definitely going to save us some debugging headaches during parallel runs. |
Closes #10
Bug fixes
EmissionActivityRatiotypo inConfig.py— Fixed'e''t'(Python string concatenation →'et') to'e','t'inPARAMETERS_C. This was silently corrupting parameter validation dimensions.File handle leaks in
FileClass.py— Refactored all four static methods (readFile,writeFile,writeFileUJson,readParamFile) from manualopen()/close()towith open(...) as f:context managers. Previous code leaked file handles when exceptions occurred betweenopen()andclose().CustomThread.join()missingtimeout— Addedtimeout=Noneparameter to matchThread.join()signature. Previously,thread.join(timeout=5)would raiseTypeError.Testing infrastructure
Added
pytesttest suite — 25 tests across 3 test files:tests/test_config.py(9 tests) — validatesPARAMETERS_Cdimensions, config paths, group tuples, and mapping key consistencytests/test_file_class.py(10 tests) — JSON read/write round-trips, missing file handling, invalid JSON handling, overwrite behaviortests/test_custom_thread.py(6 tests) — return values, args/kwargs passing, timeout acceptance, timeout behaviorAdded GitHub Actions CI (
.github/workflows/ci.yml):flake8checking for syntax errors (E9, F63, F7, F82)pytestacross matrix of Python 3.10/3.11/3.12 × Ubuntu/macOS/WindowsAdded
pytest.ini— configures test discovery paths and naming conventionsAdded
__pycache__/to.gitignoreValidation
All 25 tests pass locally on macOS with Python 3.12.