Skip to content

Commit

Permalink
Merge pull request #188 from ttngu207/main
Browse files Browse the repository at this point in the history
Add pytest
  • Loading branch information
kushalbakshi authored Mar 22, 2024
2 parents 35ca3e2 + 9dc3b92 commit 3b420a7
Show file tree
Hide file tree
Showing 12 changed files with 297 additions and 174 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ on:
jobs:
make_github_release:
uses: datajoint/.github/.github/workflows/make_github_release.yaml@main
pypi_release:
needs: make_github_release
uses: datajoint/.github/.github/workflows/pypi_release.yaml@main
secrets:
TWINE_USERNAME: ${{secrets.TWINE_USERNAME}}
TWINE_PASSWORD: ${{secrets.TWINE_PASSWORD}}
with:
UPLOAD_URL: ${{needs.make_github_release.outputs.release_upload_url}}
mkdocs_release:
uses: datajoint/.github/.github/workflows/mkdocs_release.yaml@main
permissions:
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and
[Keep a Changelog](https://keepachangelog.com/en/1.0.0/) convention.

## [0.9.5] - 2024-03-22

+ Add - pytest
+ Fix - minor bugfix in tests
+ Update - clean up notebook
+ Update - Elements installed directly from GitHub instead of PyPI
+ Update - Black formatting `tests`

## [0.9.4] - 2024-02-05

+ Fix - bugfix ingesting field xyz for mesoscan (multiROI) from ScanImage
Expand Down
17 changes: 0 additions & 17 deletions element_calcium_imaging/__init__.py
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", "")
2 changes: 1 addition & 1 deletion element_calcium_imaging/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Package metadata."""

__version__ = "0.9.4"
__version__ = "0.9.5"
2 changes: 1 addition & 1 deletion notebooks/demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
}
],
"source": [
"from tutorial_pipeline import *"
"from tests.tutorial_pipeline import *"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion notebooks/quality_metrics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"import datetime\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from tutorial_pipeline import scan, imaging"
"from tests.tutorial_pipeline import scan, imaging"
]
},
{
Expand Down
70 changes: 5 additions & 65 deletions notebooks/tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
}
],
"source": [
"from tutorial_pipeline import (\n",
"from tests.tutorial_pipeline import (\n",
" lab,\n",
" subject,\n",
" session,\n",
Expand Down Expand Up @@ -780,7 +780,7 @@
"source": [
"Equipment.insert1(\n",
" dict(\n",
" device=\"Mesoscope1\",\n",
" device=\"Scanner1\",\n",
" modality=\"Calcium imaging\",\n",
" description=\"Example microscope\",\n",
" )\n",
Expand Down Expand Up @@ -897,7 +897,7 @@
" dict(\n",
" **session_key,\n",
" scan_id=0,\n",
" device=\"Mesoscope1\",\n",
" device=\"Scanner1\",\n",
" acq_software=\"ScanImage\",\n",
" scan_notes=\"\",\n",
" )\n",
Expand Down Expand Up @@ -1468,69 +1468,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### **Curate the results (Optional)**\n",
"### **Populate the results**\n",
"\n",
"While image processing is complete in the step above, you can optionally curate the\n",
"output of image processing using the `Curation` table. For this demo, we will simply use\n",
"the results of image processing output from the `Processing` task."
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"# Curation(s) results\n",
"subject : varchar(8) # \n",
"session_datetime : datetime # \n",
"scan_id : int # \n",
"paramset_idx : smallint # Unique parameter set ID.\n",
"curation_id : int # \n",
"---\n",
"curation_time : datetime # Time of generation of this set of curated results\n",
"curation_output_dir : varchar(255) # Output directory of the curated results, relative to root data directory\n",
"manual_curation : tinyint # Has manual curation been performed on this result?\n",
"curation_note : varchar(2000) # "
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"imaging.Curation.heading"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"imaging.Curation.insert1(\n",
" dict(\n",
" **session_key,\n",
" scan_id=0,\n",
" paramset_idx=0,\n",
" curation_id=0,\n",
" curation_time=\"2021-04-30 12:22:15.032\",\n",
" curation_output_dir=\"subject1/session1/suite2p\",\n",
" manual_curation=False,\n",
" curation_note=\"\",\n",
" )\n",
")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Once the `Curation` table receives an entry, we can populate the remaining tables in the\n",
"Once the `Processing` table finishes, we can populate the remaining tables in the\n",
"workflow including `MotionCorrection`, `Segmentation`, and `Fluorescence`."
]
},
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
with open(path.join(here, "README.md"), "r") as f:
long_description = f.read()


with open(path.join(here, pkg_name, "version.py")) as f:
exec(f.read())

Expand Down
78 changes: 0 additions & 78 deletions tests/__init__.py
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)
Loading

0 comments on commit 3b420a7

Please sign in to comment.