Draft
Add comprehensive tests for DEMS.py to improve code coverage#12
Conversation
Co-authored-by: mifm <37401366+mifm@users.noreply.github.com>
Co-authored-by: mifm <37401366+mifm@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] write tests to get coverage on lines: 57, 61, 103-106, 119-120, 154-167, 273, 286, 313-320, 374-615, 676-940, 982-1081, 1134-1357, 1374-1395 of the file hydesign\HiFiEMS\DEMS.py
Add comprehensive tests for DEMS.py to improve code coverage
Aug 28, 2025
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.
This PR adds comprehensive unit tests for the
hydesign/HiFiEMS/DEMS.pymodule to achieve coverage on previously untested lines, specifically targeting lines 57, 61, 103-106, 119-120, 154-167, 273, 286, 313-320, 374-615, 676-940, 982-1081, 1134-1357, and 1374-1395.Changes Made
New Test File:
hydesign/tests/test_dems.pyThe new test suite includes:
ReadData Function Coverage
Utility Function Coverage
f_xmin_to_ymin()function with different time resolution conversions (lines 154-167)get_var_value_from_sol()function for extracting optimization variable values (lines 172-179)revenue_process()function for processing revenue calculation results (lines 1374-1395)Pandas Compatibility
pandas.DataFrame.append()method used in legacy codeCoverage Results
Successfully achieved coverage on the following target lines:
Note on Optimization Functions: Lines 273, 286, 313-320 (SMOpt), 374-615 (BMOpt), 676-940 (RDOpt), 982-1081 (RTSim), and 1134-1357 (RBOpt) require the CPLEX optimization solver which is not available in the CI environment. These functions are complex mathematical optimization routines that would need integration tests with proper CPLEX licensing to achieve meaningful coverage.
Testing Infrastructure
The tests follow existing repository patterns and include:
Total coverage increased from ~17% to 21% for the DEMS.py module, successfully covering all feasible target lines given the CPLEX dependency constraints.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.