-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pytest for testing python API (#139)
* add manifest * update manifest * exclude __pycache__ from sdist * add loader path * fix termination of cmake it * fix description type * remove stuff from install_requires * start of tests * add first idx test * add pytest * add pytest to requirements.txt * add python testing stage * move python testing to pip install * rename workflow to be build_and_test * remove cmake.yml and add pytest install * add proper name * change name again * make Python_test lowercase
- Loading branch information
Showing
3 changed files
with
104 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import pytest | ||
import distopia | ||
import numpy as np | ||
from numpy.testing import assert_allclose | ||
|
||
|
||
""" | ||
Majority of detailed testing is done at the C++ level. | ||
This is primarily to make sure that the Python API works as expected. | ||
""" | ||
|
||
|
||
class TestDistances: | ||
|
||
def arange_input(self, N, dtype): | ||
return np.arange(3*N, dtype=dtype).reshape(N,3) | ||
|
||
def idx_input(self, N): | ||
idxs = np.zeros((N, 2), dtype=np.ulonglong) | ||
for i in range(N): | ||
idxs[i,0]=i | ||
idxs[i,1]=i+N | ||
return np.ravel(idxs) | ||
|
||
@pytest.mark.parametrize('box', ([10, 10, 10], [100, 20, 10])) | ||
@pytest.mark.parametrize('N', (0, 10, 1000, 10000)) | ||
def test_calc_bonds_ortho_float_all_zero(self, N, box): | ||
c0 = self.arange_input(N, np.float32) | ||
c1 = self.arange_input(N, np.float32) | ||
result = distopia.calc_bonds_ortho_float( | ||
c0, c1, np.asarray(box, dtype=np.float32)) | ||
assert_allclose(result, np.zeros(N)) | ||
|
||
@pytest.mark.parametrize('box', ([10, 10, 10], [100, 20, 10])) | ||
@pytest.mark.parametrize('N', (0, 10, 1000, 10000)) | ||
def test_calc_bonds_ortho_double_all_zero(self, N, box): | ||
c0 = self.arange_input(N, np.float64) | ||
c1 = self.arange_input(N, np.float64) | ||
result = distopia.calc_bonds_ortho_double( | ||
c0, c1, np.asarray(box, dtype=np.float64)) | ||
assert_allclose(result, np.zeros(N)) | ||
|
||
@pytest.mark.parametrize('N', (0, 10, 1000, 10000)) | ||
def test_calc_bonds_nobox_float_all_zero(self, N): | ||
c0 = self.arange_input(N, np.float32) | ||
c1 = self.arange_input(N, np.float32) | ||
result = distopia.calc_bonds_no_box_float(c0, c1) | ||
assert_allclose(result, np.zeros(N)) | ||
|
||
@pytest.mark.parametrize('N', (0, 10, 1000, 10000)) | ||
def test_calc_bonds_nobox_double_all_zero(self, N): | ||
c0 = self.arange_input(N, np.float64) | ||
c1 = self.arange_input(N, np.float64) | ||
result = distopia.calc_bonds_no_box_double(c0, c1) | ||
assert_allclose(result, np.zeros(N)) | ||
|
||
@pytest.mark.parametrize('box', ([10, 10, 10], [100, 20, 10])) | ||
@pytest.mark.parametrize('N', (0, 10, 1000, 10000)) | ||
def test_calc_bonds_idx_ortho_float_all_zero(self, N, box): | ||
c0 = self.arange_input(N, np.float32) | ||
c1 = self.arange_input(N, np.float32) | ||
idx = self.idx_input(N) | ||
coords = np.vstack((c0, c1)) | ||
result = distopia.calc_bonds_idx_ortho_float(coords, idx, np.asarray(box).astype(np.float32)) | ||
assert_allclose(result, np.zeros(N)) | ||
|
||
@pytest.mark.parametrize('box', ([10, 10, 10], [100, 20, 10])) | ||
@pytest.mark.parametrize('N', (0, 10, 1000, 10000)) | ||
def test_calc_bonds_idx_ortho_double_all_zero(self, N, box): | ||
c0 = self.arange_input(N, np.float64) | ||
c1 = self.arange_input(N, np.float64) | ||
idx = self.idx_input(N) | ||
coords = np.vstack((c0, c1)) | ||
result = distopia.calc_bonds_idx_ortho_double(coords, idx, np.asarray(box).astype(np.float64)) | ||
assert_allclose(result, np.zeros(N)) | ||
|
||
|
||
@pytest.mark.parametrize('N', (0, 10, 1000, 10000)) | ||
def test_calc_bonds_idx_no_box_float_all_zero(self, N): | ||
c0 = self.arange_input(N, np.float32) | ||
c1 = self.arange_input(N, np.float32) | ||
idx = self.idx_input(N) | ||
coords = np.vstack((c0, c1)) | ||
result = distopia.calc_bonds_idx_no_box_float(coords, idx) | ||
assert_allclose(result, np.zeros(N)) | ||
|
||
@pytest.mark.parametrize('N', (0, 10, 1000, 10000)) | ||
def test_calc_bonds_idx_no_box_double_all_zero(self, N): | ||
c0 = self.arange_input(N, np.float64) | ||
c1 = self.arange_input(N, np.float64) | ||
idx = self.idx_input(N) | ||
coords = np.vstack((c0, c1)) | ||
result = distopia.calc_bonds_idx_no_box_double(coords, idx) | ||
assert_allclose(result, np.zeros(N)) |
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 |
---|---|---|
|
@@ -2,4 +2,5 @@ cmake | |
cython>=0.28.0,<3.0.0 | ||
numpy>=1.20.0 | ||
ninja | ||
pytest | ||
scikit-build |