Add unit tests for ngspiceSimulation math_utils module - #622
Open
caveman210 wants to merge 1 commit into
Open
Conversation
Cover _format_measurement, _format_frequency, _canonical_expr, _safe_eval and _detect_frequency with 35 passing tests. Modules are loaded directly via importlib to bypass the heavy Qt/matplotlib package __init__ imports, keeping the test dependency to numpy only. Added unit tests for ngspiceSimulation
There was a problem hiding this comment.
Pull request overview
Adds a focused unittest suite for src/ngspiceSimulation/math_utils.py (formatting, expression canonicalization, safe evaluation, and frequency detection) while avoiding heavy GUI-related imports by loading the module directly from its file path.
Changes:
- Adds 35 unit tests covering
_format_measurement,_format_frequency,_canonical_expr,_safe_eval, and_detect_frequency. - Adds a separate “known issues” test module intended to characterize current buggy behavior.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| unit_tests/test_math_utils.py | New primary unit test suite for math_utils helpers. |
| unit_tests/known_issues/test_math_utils.py | Adds characterization tests for current buggy behaviors (but currently named/placed like regular tests). |
| unit_tests/init.py | Makes unit_tests a package (affects discovery/import behavior). |
Suppressed comments (3)
unit_tests/known_issues/test_math_utils.py:55
- Same concern as above: this class will be collected by default test discovery, but it is intended to pin current buggy behavior. Consider skipping unless explicitly enabled to avoid future fixes turning into CI failures.
class KnownIssueFormatFrequency(unittest.TestCase):
unit_tests/known_issues/test_math_utils.py:64
- Same concern as above: since this is a known-issue characterization test, it’s safer to skip it by default so that fixing the underlying behavior doesn’t unexpectedly break CI.
class KnownIssueCanonicalExpr(unittest.TestCase):
unit_tests/known_issues/test_math_utils.py:71
- Same concern as above: this known-issue suite is likely to be collected by default; skipping unless explicitly enabled avoids turning bug fixes into failing tests.
class KnownIssueSafeEval(unittest.TestCase):
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+15
to
+18
| spec = importlib.util.spec_from_file_location(module_name, path) | ||
| module = importlib.util.module_from_spec(spec) | ||
| spec.loader.exec_module(module) | ||
| return module |
Comment on lines
+127
to
+128
| result = _safe_eval("2*3", {}) | ||
| np.testing.assert_array_equal(result, [6.0]) |
| import unittest | ||
| import importlib.util | ||
|
|
||
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src")) |
Comment on lines
+15
to
+18
| spec = importlib.util.spec_from_file_location(module_name, path) | ||
| module = importlib.util.module_from_spec(spec) | ||
| spec.loader.exec_module(module) | ||
| return module |
| _safe_eval = _math_utils._safe_eval | ||
|
|
||
|
|
||
| class KnownIssueFormatMeasurement(unittest.TestCase): |
| import unittest | ||
| import importlib.util | ||
|
|
||
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "src")) |
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.
Cover _format_measurement, _format_frequency, _canonical_expr, _safe_eval and _detect_frequency with 35 passing tests. Modules are loaded directly via importlib to bypass the heavy Qt/matplotlib package init imports, keeping the test dependency to numpy only.
Added unit tests for ngspiceSimulation
Related Issues
Purpose
Approach