Skip to content

Commit

Permalink
Merge pull request #225 from BradyAJohnston/dev-tests
Browse files Browse the repository at this point in the history
Dev: Add Initial testing suite

Now that a [recent version of bpy](https://pypi.org/project/bpy/) is built and available on PyPi, this enables testing of the addon through `pytest` like other python-based projects. 

I have set up the workflows for running automatic testing on Windows and Linux machines, but there is a `segfault` error on macOS machines when running on GitHub actions. The tests run fine on my own 2017 MacBook pro, but I haven't looked into it much what the error might be.

In previously having discussion with the Blender devs, applying the modifiers and then comparing vertices might be the best strategy for doing snapshot tests. I have a couple of tests so far, which do exactly that for the regular import, cartoon and ribbon methods. There is also a method which tests importing via `.pdb` / `.cif` and downloading from the PDB and ensures their verts are the same. 

Currently these tests are just positionally based, though the other attributes will also be testable. Best to get some initial tests added and put into the workflow so that potentially others can contribute also. 

There are errors with importing `pyopenvdb` when using the `bpy` addon. It seems that the library isn't installed into the local python, and instead is called from within the addon itself to load volume files. This currently limits the ability to write any tests involving the volumetric import, but something to work on in the future.
  • Loading branch information
BradyAJohnston committed May 17, 2023
2 parents ce3c1f4 + a11af56 commit 3f1f292
Show file tree
Hide file tree
Showing 17 changed files with 5,525 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Documentation
name: docs-build-deploy

on:
workflow_dispatch:
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: test-addon

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
max-parallel: 4
fail-fast: false
matrix:
blender-version: ["3.5.0"]
os: [ubuntu-latest, windows-latest]
# os: [ubuntu-latest]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.10'
cache: 'pip'
- run: pip install bpy==${{ matrix.blender-version }}
- run: pip install -r requirements.txt

- name: Install MolecularNodes
run: pip install .

- name: Run Tests
run: pytest --verbose --cov=MolecularNodes --cov-report=xml:coverage.xml

- name: Expose coverage as a CI download # Related to test_addon_blender_advanced.py
uses: actions/upload-artifact@v1
with:
name: coverage.xml
path: coverage.xml
# setup ssh to check on file system state
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ logs/side-packages-install.log
*.pyc
.Rproj.user
/.quarto/
*egg*/*
build/*
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include MolecularNodes/assets/*
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
docs-build:
cd docs && quartodoc build
quarto render docs

test:
pip3 install .
pytest -vv
8 changes: 6 additions & 2 deletions MolecularNodes/density.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import bpy
import pyopenvdb as vdb
# import pyopenvdb as vdb
import numpy as np
import os

def map_to_grid(file: str, invert: bool = False) -> vdb.FloatGrid:
def map_to_grid(file: str, invert: bool = False):
"""Reads an MRC file and converts it into a pyopenvdb FloatGrid object.
This function reads a file in MRC format, and converts it into a pyopenvdb FloatGrid object,
Expand All @@ -18,6 +18,8 @@ def map_to_grid(file: str, invert: bool = False) -> vdb.FloatGrid:
pyopenvdb.FloatGrid: A pyopenvdb FloatGrid object containing the density data.
"""
import mrcfile
import pyopenvdb as vdb

volume = mrcfile.read(file)

dataType = volume.dtype
Expand Down Expand Up @@ -68,6 +70,8 @@ def map_to_vdb(file: str, invert: bool = False, world_scale=0.01, overwrite=Fals
str: The path to the converted .vdb file.
"""
import mrcfile
import pyopenvdb as vdb

file_path = path_to_vdb(file)

# If the map has already been converted to a .vdb and overwrite is False, return that instead
Expand Down
2 changes: 1 addition & 1 deletion MolecularNodes/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def create_molecule(mol_array,
# remove the solvent from the structure if requested
if del_solvent:
try:
mol_array = mol_array[np.invert(struc.filter_solvent(mol_array))]
mol_array = mol_array[0][np.invert(struc.filter_solvent(mol_array))]
except TypeError:
pass

Expand Down
5 changes: 4 additions & 1 deletion docs/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/.quarto/
/.quarto/
reference/*
_build/*
objects.json
25 changes: 25 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[build-system]
requires = ["setuptools>=45", "wheel", "setuptools_scm>=6.2"]
build-backend = "setuptools.build_meta"

[tool.pytest.ini_options]
markers = [
]
testpaths = [
"tests"
]

[project]
name = "MolecularNodes"
version = "2.6.2"

[tool.setuptools.packages.find]
where = ["."]

[tool.setuptools]
# ...
# By default, include-package-data is true in pyproject.toml, so you do
# NOT have to specify this line.
include-package-data = true

[tool.setuptools_scm]
8 changes: 8 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pytest
pytest-snapshot
pytest-cov
biotite==0.37.0 # General parsing of structural files.
MDAnalysis==2.2.0 # Reading of molecular dynamics trajectories.
mrcfile==1.4.3 # Importing EM density files.
starfile==0.4.11 # Importing star files.
eulerangles==1.0.1 # Handling euler angle in starfiles.
Loading

0 comments on commit 3f1f292

Please sign in to comment.