-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow API functions to be used without loading hoc/mod #minor (#124)
* replace in with == * load hoc and mod when required to allow API functions to be used without them
- Loading branch information
Showing
10 changed files
with
80 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,4 @@ nrnivmodl.log | |
.ruff_cache | ||
.pytest_cache | ||
*.btr | ||
*.whl |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"""Utility functions.""" | ||
|
||
|
||
def run_once(func): | ||
"""A decorator to ensure a function is only called once.""" | ||
def wrapper(*args, **kwargs): | ||
if not wrapper.has_run: | ||
wrapper.has_run = True | ||
return func(*args, **kwargs) | ||
wrapper.has_run = False | ||
return wrapper |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from bluecellulab.utils import run_once | ||
|
||
|
||
# Decorated function for testing | ||
@run_once | ||
def increment_counter(counter): | ||
counter[0] += 1 | ||
return "Executed" | ||
|
||
|
||
def test_run_once_execution(): | ||
"""Test that the decorated function runs only once.""" | ||
counter = [0] # Using a list for mutability | ||
|
||
assert increment_counter(counter) == "Executed" | ||
increment_counter(counter) | ||
assert counter[0] == 1 | ||
|
||
# Called 3 times but increased once | ||
increment_counter(counter) | ||
increment_counter(counter) | ||
increment_counter(counter) | ||
|
||
assert counter[0] == 1 | ||
|
||
assert increment_counter(counter) is None |