Skip to content

Add unit tests for ngspiceSimulation math_utils module - #622

Open
caveman210 wants to merge 1 commit into
FOSSEE:masterfrom
caveman210:unit_tests
Open

Add unit tests for ngspiceSimulation math_utils module#622
caveman210 wants to merge 1 commit into
FOSSEE:masterfrom
caveman210:unit_tests

Conversation

@caveman210

Copy link
Copy Markdown

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

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
Copilot AI lite review requested due to automatic review settings August 8, 2026 15:20
@caveman210 caveman210 closed this Aug 8, 2026
@caveman210 caveman210 reopened this Aug 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"))
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