Skip to content

Commit

Permalink
Make test assertions approximate (#154)
Browse files Browse the repository at this point in the history
* make numpy test approx equal

* Make some tests approximate

* update gitignore

* remove .DS_Store

* remove .DS_Store
  • Loading branch information
adamltyson authored Dec 15, 2023
1 parent a673b22 commit dd2dff7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 58 deletions.
72 changes: 16 additions & 56 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
# Custom config files
*.conf.custom

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Cython
*.c
*.cpp

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
Expand All @@ -26,11 +20,9 @@ lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
Expand All @@ -50,9 +42,8 @@ htmlcov/
.cache
nosetests.xml
coverage.xml
*.cover
*,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
Expand All @@ -61,63 +52,32 @@ coverage.xml
# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
# Flask instance folder
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
doc/build/
docs/_build/

# pydocmd
_build/
mkdocs.yml
# MkDocs documentation
/site/

# PyBuilder
target/

# Jupyter Notebook
# Pycharm and VSCode
.idea/
venv/
.vscode/

# IPython Notebook
.ipynb_checkpoints

# pyenv
.python-version

# vscode
.vscode

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

.idea/
# OS
.DS_Store

*.~lock.*
*.zip
# written by setuptools_scm
**/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,33 @@ def test_track_export(
sleep(8)
spline_validate = np.load(validate_tracks_dir / "test_track.npy")
spline_test = np.load(test_tracks_dir / "test_track.npy")
np.testing.assert_equal(spline_validate, spline_test)
np.testing.assert_allclose(spline_validate, spline_test)


def compare_dataframes(df1, df2, threshold=0.9):
"""
Function to check how many entries are the same,
not how similar they are.
Required due to slight differences between operating
systems & architectures
"""
if df1.shape != df2.shape:
raise ValueError("DataFrames are not the same shape.")

total_entries = df1.shape[0] * df1.shape[1]
matching_entries = (df1 == df2).sum().sum()
similarity = matching_entries / total_entries
return similarity >= threshold


def check_analysis(test_tracks_dir, validate_tracks_dir):
regions_validate = pd.read_csv(validate_tracks_dir / "test_track.csv")
regions_test = pd.read_csv(test_tracks_dir / "test_track.csv")
pd.testing.assert_frame_equal(regions_validate, regions_test)
# Threshold of 0.9 is not ideal but sight differences in the analysis
# can have big effects on the final result (e.g. assigning to
# neighbouring anatomical areas
assert compare_dataframes(regions_validate, regions_test)


def check_saving(test_tracks_dir, validate_tracks_dir, rtol):
Expand Down

0 comments on commit dd2dff7

Please sign in to comment.