Add unit tests for Function API, declare_types, and code renderers#1835
Open
nishantraghuvanshi wants to merge 1 commit into
Open
Add unit tests for Function API, declare_types, and code renderers#1835nishantraghuvanshi wants to merge 1 commit into
nishantraghuvanshi wants to merge 1 commit into
Conversation
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.
Starting on #1645
Summary
This is a first step towards addressing the issue of replacing integration tests with proper unit tests. Rather than running the full simulation machinery, these tests call the relevant functions directly.
24 tests are added to a new file
brian2/tests/test_functions_unit.py.All are marked
@pytest.mark.codegen_independentand the full file completes in ~2 seconds.What was converted and how
Several behaviours that were only tested by building a
NeuronGroupand callingrun(0*ms)are now tested directly:Pure extraction (no mocking needed): the logic was already decoupled from the simulation:
pi,e,inf) have correct float valuesCPPNodeRenderercorrectly mapsinf→INFINITY, booleans,**→_brian_pow,%→_brian_modNumpyNodeRenderercorrectly rewritesand→&andnot→logical_not@declare_typessets_arg_types/_return_typeand validates type strings at decoration timeFunction()constructor validates missing units and raises immediatelyMocking-based: the logic was coupled to heavy infrastructure, so I use
MagicMockto isolate it:check_expression_for_multiple_stateful_functions(detectsrand() - rand()) is called directly with a minimalFunctionobject instead of going throughNeuronGroup + run()check_for_order_independenceis tested with aMagicMockstanding in forArrayVariable— the function only callsisinstance(var, Function)andisinstance(var, Constant), so a plain mock correctly represents a regular array variable without needing a device, owner, or sizeQuestions
test_functions_unit.pyor alongside the original test files (e.g. directly intest_functions.pywith appropriate markers)?Happy to iterate on this based on feedback before expanding to other parts of the test suite.