-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #188 from ttngu207/main
Add pytest
- Loading branch information
Showing
12 changed files
with
297 additions
and
174 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
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 |
---|---|---|
@@ -1,17 +0,0 @@ | ||
import os | ||
import datajoint as dj | ||
|
||
if "custom" not in dj.config: | ||
dj.config["custom"] = {} | ||
|
||
# overwrite dj.config['custom'] values with environment variables if available | ||
|
||
dj.config["custom"]["database.prefix"] = os.getenv( | ||
"DATABASE_PREFIX", dj.config["custom"].get("database.prefix", "") | ||
) | ||
|
||
dj.config["custom"]["imaging_root_data_dir"] = os.getenv( | ||
"IMAGING_ROOT_DATA_DIR", dj.config["custom"].get("imaging_root_data_dir", "") | ||
) | ||
|
||
db_prefix = dj.config["custom"].get("database.prefix", "") | ||
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
"""Package metadata.""" | ||
|
||
__version__ = "0.9.4" | ||
__version__ = "0.9.5" |
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 |
---|---|---|
|
@@ -49,7 +49,7 @@ | |
} | ||
], | ||
"source": [ | ||
"from tutorial_pipeline import *" | ||
"from tests.tutorial_pipeline import *" | ||
] | ||
}, | ||
{ | ||
|
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 |
---|---|---|
@@ -1,78 +0,0 @@ | ||
""" | ||
run all: python -m pytest -sv --cov-report term-missing --cov=element_calcium_imaging --sw -p no:warnings tests/ | ||
run one: python -m pytest -sv --cov-report term-missing --cov=element_calcium_imaging --sw -p no:warnings --pdb tests/module_name.py -k function_name | ||
""" | ||
|
||
import os | ||
import pathlib | ||
import sys | ||
from contextlib import nullcontext | ||
|
||
import datajoint as dj | ||
import numpy as np | ||
import pandas as pd | ||
import pytest | ||
from element_interface.utils import find_full_path, find_root_directory | ||
|
||
# ------------------- SOME CONSTANTS ------------------- | ||
|
||
_tear_down = False | ||
|
||
sessions_dirs = [ | ||
"subject1/session1", | ||
] | ||
|
||
verbose = False | ||
|
||
logger = dj.logger | ||
|
||
# ------------------ GENERAL FUCNTION ------------------ | ||
|
||
|
||
class QuietStdOut: | ||
"""If verbose set to false, used to quiet tear_down table.delete prints""" | ||
|
||
def __enter__(self): | ||
logger.setLevel("ERROR") | ||
self._original_stdout = sys.stdout | ||
sys.stdout = open(os.devnull, "w") | ||
|
||
def __exit__(self, exc_type, exc_val, exc_tb): | ||
logger.setLevel("INFO") | ||
sys.stdout.close() | ||
sys.stdout = self._original_stdout | ||
|
||
|
||
verbose_context = nullcontext() if verbose else QuietStdOut() | ||
|
||
# ------------------- FIXTURES ------------------- | ||
|
||
|
||
@pytest.fixture | ||
def pipeline(): | ||
with verbose_context: | ||
print("\n") | ||
from notebooks import tutorial_pipeline | ||
|
||
yield { | ||
"subject": tutorial_pipeline.subject, | ||
"lab": tutorial_pipeline.lab, | ||
"imaging": tutorial_pipeline.imaging, | ||
"scan": tutorial_pipeline.scan, | ||
"session": tutorial_pipeline.session, | ||
"Equipment": tutorial_pipeline.Equipment, | ||
"get_imaging_root_data_dir": tutorial_pipeline.get_imaging_root_data_dir, | ||
} | ||
|
||
if _tear_down: | ||
with verbose_context: | ||
pipeline.subject.Subject.delete() | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def test_data(pipeline): | ||
root_dirs = pipeline["get_imaging_root_data_dir"] | ||
try: | ||
_ = [find_full_path(root_dirs(), p) for p in sessions_dirs] | ||
except FileNotFoundError as e: | ||
print(e) | ||
Oops, something went wrong.