Skip to content

Commit

Permalink
Added tests and code style checks for use in Jenkins.
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRhiem committed Nov 11, 2014
1 parent aaaf629 commit 6412b82
Show file tree
Hide file tree
Showing 11 changed files with 642 additions and 3 deletions.
49 changes: 49 additions & 0 deletions ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

export PYTHONPATH=`pwd`:$PYTHONPATH

# Set up virtual environment
[ ! -e env ] || rm -rf env
virtualenv --python=python2.7 env
. env/bin/activate
# Install testing packages
pip install pep8 pylint pytest pytest-cov

# Install requirements
pip install numpy gr glfw PyOpenGL


# PEP8 conformance check (will cause build failure if python files are not PEP8 conformant)
pep8 $(find . -path ./env -prune -o -name "*.py" -print) | tee pep8.log
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
echo "Failed PEP8 conformance check!";
exit 1;
fi


# PyLint code style check (will NOT cause build failure as pylint tends to overreact)
if [[ ! -f pylintrc ]]; then
echo "pylintrc missing!";
exit 1;
fi
pylint --rcfile=pylintrc "--msg-template={path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" $(find . -path ./env -prune -o -path ./tests -prune -o -name "*.py" -print) | tee pylint.log


# Run py.test (will cause build failure if a test fails)
if [[ ! -f pytest.ini ]]; then
echo "pytest.ini missing!";
exit 1;
fi
if [[ ! -f coveragerc ]]; then
echo "coveragerc missing!";
exit 1;
fi
py.test --cov-config coveragerc --cov-report html --cov . | tee py.test.log
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
echo "Failed tests!";
exit 1;
fi


# Report build success
exit 0
3 changes: 3 additions & 0 deletions coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[run]
omit = env/*, setup.py, examples/*
branch = True
13 changes: 11 additions & 2 deletions mogli.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,13 @@ def calculate_bonds(self, method='radii', param=None):
# Bonds were calculated for this molecule already.
# Reuse those, if the method and optional parameter are like those
# provided to this function.
if self.bonds.method == method and self.bonds.param == param:
return
if self.bonds.method == method:
if self.bonds.param == param:
return
elif param is None:
# Allow reuse when default param is used.
if method == 'radii' and self.bonds.param == 1.0:
return

if method == 'radii':
radii = ATOM_VALENCE_RADII[self.atomic_numbers]
Expand Down Expand Up @@ -375,6 +380,10 @@ def show(molecule, width=500, height=500,
if show_bonds:
molecule.calculate_bonds(bonds_method, bonds_param)

# If GR3 was initialized earlier, it would use a different context, so
# it will be terminated first.
gr3.terminate()

# Initialize GLFW and create an OpenGL context
glfw.init()
window = glfw.create_window(width, height, title, None, None)
Expand Down
Loading

0 comments on commit 6412b82

Please sign in to comment.