Skip to content

Commit

Permalink
Merge pull request #45 from pyiron/unittests
Browse files Browse the repository at this point in the history
Switch from pytest to unittest
  • Loading branch information
jan-janssen authored Aug 24, 2020
2 parents 97abbae + 8453112 commit d7c5fdf
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 131 deletions.
5 changes: 5 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# .coveragerc to control coverage.py
[run]
source = pylammpsmpi
omit = pylammpsmpi/_version.py
concurrency = multiprocessing
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7]
python-version: [3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v2
Expand All @@ -28,13 +28,6 @@ jobs:
- run: conda --version
- run: which python
- run: conda config --set always_yes yes --set changeps1 no
- run: conda install -c conda-forge lammps mpi4py openmpi pytest numpy distributed dask-jobqueue
- run: conda install -c conda-forge lammps mpi4py openmpi coveralls codacy-coverage coverage numpy distributed dask-jobqueue
- run: pip install -e .
- run: python -m pytest tests/
- run: python setup.py sdist
- name: publish package on pypi
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
with:
user: ${{ secrets.pypi_username }}
password: ${{ secrets.pypi_password }}
- run: coverage run -m unittest discover tests
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ matrix:
- bash miniconda.sh -b -p $HOME/miniconda
- conda info -a
- conda config --set always_yes yes --set changeps1 no
- conda install -c conda-forge lammps mpi4py openmpi pytest numpy distributed dask-jobqueue
- conda install -c conda-forge lammps mpi4py openmpi coveralls codacy-coverage coverage numpy distributed dask-jobqueue
- conda update -q conda
- pip install -e .
script:
- python -m pytest tests/
- coverage run -m unittest discover tests
- coverage combine
after_success:
- coveralls
- coverage xml
- python-codacy-coverage -r coverage.xml
deploy:
- provider: pypi
user: pyiron
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# `PyLammpsMPI`
[![Build Status](https://travis-ci.org/pyiron/pylammpsmpi.svg?branch=master)](https://travis-ci.org/pyiron/pylammpsmpi)

## Install with pip

Expand Down
146 changes: 78 additions & 68 deletions tests/test_pylammpsmpi_cluster.py
Original file line number Diff line number Diff line change
@@ -1,75 +1,85 @@
import pytest
# coding: utf-8
# Copyright (c) Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department
# Distributed under the terms of "New BSD License", see the LICENSE file.

import unittest
import os
import numpy as np
from pylammpsmpi import LammpsLibrary
from dask.distributed import Client, LocalCluster

cluster = LocalCluster(n_workers=1, threads_per_worker=2)
client = Client(cluster)

lmp = LammpsLibrary(cores=2, mode='dask', client=client)
lmp.file("tests/in.simple")

def test_extract_atom():

f = lmp.extract_atom("f")
assert len(f) == 256
assert np.round(f[0][0], 2) == -0.26

ids = lmp.extract_atom("id")
assert len(ids) == 256

def test_gather_atoms():

f = lmp.gather_atoms("f")
assert len(f) == 256
#this checks if info was gathered from
#all processors
assert np.round(f[-22][0], 2) == 0.31

ids = lmp.extract_atom("id")
assert len(ids) == 256

def test_extract_box():

box = lmp.extract_box()
assert len(box) == 7

assert box[0][0] == 0.0
assert np.round(box[1][0], 2) == 6.72

lmp.reset_box([0.0,0.0,0.0], [8.0,8.0,8.0], 0.0,0.0,0.0)
box = lmp.extract_box()
assert box[0][0] == 0.0
assert np.round(box[1][0], 2) == 8.0


def test_extract_fix():

x = lmp.extract_fix("2", 0, 1, 1)
assert np.round(x, 2) == -2.61

def test_extract_variable():

x = lmp.extract_variable("tt", "all", 0)
assert np.round(x, 2) == 1.13

x = lmp.extract_variable("fx", "all", 1)
assert len(x) == 128
assert np.round(x[0], 2) == -0.26

def test_scatter_atoms():

f = lmp.gather_atoms("f")
val = np.random.randint(0, 100)
f[1][0] = val
lmp.scatter_atoms("f", f)
f1 = lmp.gather_atoms("f")
assert f1[1][0] == val
class TestLocalLammpsLibrary(unittest.TestCase):
@classmethod
def setUpClass(cls):
execution_path = os.path.dirname(os.path.abspath(__file__))
cluster = LocalCluster(n_workers=1, threads_per_worker=2)
client = Client(cluster)
cls.lmp = LammpsLibrary(cores=2, mode='dask', client=client)
cls.lmp.file(os.path.join(execution_path, "in.simple"))

@classmethod
def tearDownClass(cls):
cls.lmp.close()

def test_extract_atom(self):
f = self.lmp.extract_atom("f")
self.assertEqual(len(f), 256)
self.assertEqual(np.round(f[0][0], 2), -0.26)

ids = self.lmp.extract_atom("id")
self.assertEqual(len(ids), 256)

def test_gather_atoms(self):
f = self.lmp.gather_atoms("f")
self.assertEqual(len(f), 256)
# this checks if info was gathered from
# all processors
self.assertEqual(np.round(f[-22][0], 2), 0.31)

ids = self.lmp.extract_atom("id")
self.assertEqual(len(ids), 256)

def test_extract_box(self):
box = self.lmp.extract_box()
self.assertEqual(len(box), 7)

self.assertEqual(box[0][0], 0.0)
self.assertEqual(np.round(box[1][0], 2), 6.72)

self.lmp.reset_box([0.0,0.0,0.0], [8.0,8.0,8.0], 0.0,0.0,0.0)
box = self.lmp.extract_box()
self.assertEqual(box[0][0], 0.0)
self.assertEqual(np.round(box[1][0], 2), 8.0)

def test_extract_fix(self):
x = self.lmp.extract_fix("2", 0, 1, 1)
self.assertEqual(np.round(x, 2), -2.61)

def test_extract_variable(self):
x = self.lmp.extract_variable("tt", "all", 0)
self.assertEqual(np.round(x, 2), 1.13)

x = self.lmp.extract_variable("fx", "all", 1)
self.assertEqual(len(x), 128)
self.assertEqual(np.round(x[0], 2), -0.26)

def test_scatter_atoms(self):
f = self.lmp.gather_atoms("f")
val = np.random.randint(0, 100)
f[1][0] = val
self.lmp.scatter_atoms("f", f)
f1 = self.lmp.gather_atoms("f")
self.assertEqual(f1[1][0], val)

f = self.lmp.gather_atoms("f", ids=[1,2])
val = np.random.randint(0, 100)
f[1][1] = val
self.lmp.scatter_atoms("f", f, ids=[1,2])
f1 = self.lmp.gather_atoms("f", ids=[1,2])
self.assertEqual(f1[1][1], val)


if __name__ == "__main__":
unittest.main()

f = lmp.gather_atoms("f", ids=[1,2])
val = np.random.randint(0, 100)
f[1][1] = val
lmp.scatter_atoms("f", f, ids=[1,2])
f1 = lmp.gather_atoms("f", ids=[1,2])
assert f1[1][1] == val
113 changes: 62 additions & 51 deletions tests/test_pylammpsmpi_local.py
Original file line number Diff line number Diff line change
@@ -1,71 +1,82 @@
import pytest
import os
# coding: utf-8
# Copyright (c) Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department
# Distributed under the terms of "New BSD License", see the LICENSE file.

import unittest
import numpy as np
import os
from pylammpsmpi import LammpsLibrary

lmp = LammpsLibrary(cores=2, mode='local')
lmp.file("tests/in.simple")

def test_extract_atom():

f = lmp.extract_atom("f")
assert len(f) == 256
assert np.round(f[0][0], 2) == -0.26

ids = lmp.extract_atom("id")
assert len(ids) == 256
class TestLocalLammpsLibrary(unittest.TestCase):
@classmethod
def setUpClass(cls):
execution_path = os.path.dirname(os.path.abspath(__file__))
cls.lmp = LammpsLibrary(cores=2, mode='local')
cls.lmp.file(os.path.join(execution_path, "in.simple"))

def test_gather_atoms():
@classmethod
def tearDownClass(cls):
cls.lmp.close()

f = lmp.gather_atoms("f")
assert len(f) == 256
#this checks if info was gathered from
#all processors
assert np.round(f[-22][0], 2) == 0.31
def test_extract_atom(self):
f = self.lmp.extract_atom("f")
self.assertEqual(len(f), 256)
self.assertEqual(np.round(f[0][0], 2), -0.26)

ids = lmp.extract_atom("id")
assert len(ids) == 256
ids = self.lmp.extract_atom("id")
self.assertEqual(len(ids), 256)

def test_extract_box():
def test_gather_atoms(self):
f = self.lmp.gather_atoms("f")
self.assertEqual(len(f), 256)
# this checks if info was gathered from
# all processors
self.assertEqual(np.round(f[-22][0], 2), 0.31)

box = lmp.extract_box()
assert len(box) == 7
ids = self.lmp.extract_atom("id")
self.assertEqual(len(ids), 256)

assert box[0][0] == 0.0
assert np.round(box[1][0], 2) == 6.72
def test_extract_box(self):

lmp.reset_box([0.0,0.0,0.0], [8.0,8.0,8.0], 0.0,0.0,0.0)
box = lmp.extract_box()
assert box[0][0] == 0.0
assert np.round(box[1][0], 2) == 8.0
box = self.lmp.extract_box()
self.assertEqual(len(box), 7)

self.assertEqual(box[0][0], 0.0)
self.assertEqual(np.round(box[1][0], 2), 6.72)

def test_extract_fix():
self.lmp.reset_box([0.0, 0.0, 0.0], [8.0, 8.0, 8.0], 0.0, 0.0, 0.0)
box = self.lmp.extract_box()
self.assertEqual(box[0][0], 0.0)
self.assertEqual(np.round(box[1][0], 2), 8.0)

x = lmp.extract_fix("2", 0, 1, 1)
assert np.round(x, 2) == -2.61
def test_extract_fix(self):
x = self.lmp.extract_fix("2", 0, 1, 1)
self.assertEqual(np.round(x, 2), -2.61)

def test_extract_variable():
def test_extract_variable(self):
x = self.lmp.extract_variable("tt", "all", 0)
self.assertEqual(np.round(x, 2), 1.13)
x = self.lmp.extract_variable("fx", "all", 1)
self.assertEqual(len(x), 128)
self.assertEqual(np.round(x[0], 2), -0.26)

x = lmp.extract_variable("tt", "all", 0)
assert np.round(x, 2) == 1.13
def test_scatter_atoms(self):

x = lmp.extract_variable("fx", "all", 1)
assert len(x) == 128
assert np.round(x[0], 2) == -0.26
f = self.lmp.gather_atoms("f")
val = np.random.randint(0, 100)
f[1][0] = val
self.lmp.scatter_atoms("f", f)
f1 = self.lmp.gather_atoms("f")
self.assertEqual(f1[1][0], val)

def test_scatter_atoms():
f = self.lmp.gather_atoms("f", ids=[1, 2])
val = np.random.randint(0, 100)
f[1][1] = val
self.lmp.scatter_atoms("f", f, ids=[1, 2])
f1 = self.lmp.gather_atoms("f", ids=[1, 2])
self.assertEqual(f1[1][1], val)

f = lmp.gather_atoms("f")
val = np.random.randint(0, 100)
f[1][0] = val
lmp.scatter_atoms("f", f)
f1 = lmp.gather_atoms("f")
assert f1[1][0] == val

f = lmp.gather_atoms("f", ids=[1,2])
val = np.random.randint(0, 100)
f[1][1] = val
lmp.scatter_atoms("f", f, ids=[1,2])
f1 = lmp.gather_atoms("f", ids=[1,2])
assert f1[1][1] == val
if __name__ == "__main__":
unittest.main()

0 comments on commit d7c5fdf

Please sign in to comment.