Skip to content

Commit

Permalink
Merge pull request pygridgen#25 from phobson/move-to-pytest-py3.5
Browse files Browse the repository at this point in the history
Move to pytest
  • Loading branch information
phobson committed Jun 29, 2016
2 parents 750adcc + e815200 commit f4b1cf5
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 151 deletions.
17 changes: 10 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ matrix:
- python: 2.7
env:
- COVERAGE=false
- python: 3.3
env:
- COVERAGE=false
- python: 3.4
env:
- COVERAGE=false
Expand All @@ -22,21 +19,27 @@ before_install:
- ./miniconda.sh -b -p $HOME/miniconda
- export PATH=$HOME/miniconda/bin:$PATH
- conda update --yes conda
- conda install --yes nomkl

install:
- conda create --name testenv --yes python=$TRAVIS_PYTHON_VERSION numpy matplotlib nose pyyaml requests docopt coverage
- conda create --name testenv --yes python=$TRAVIS_PYTHON_VERSION numpy matplotlib docopt requests pyyaml pytest
- source activate testenv
- conda install --yes pyproj gridgen --channel=IOOS
- conda install --yes pyproj gridgen --channel=conda-forge
- pip install .
- pip install coveralls


before_script:
- ls -al /usr/local/lib
- ls -al /usr/local/include
- conda list

script:
- nosetests --with-coverage --cover-package=pygridgen --verbose
- python check_pygridgen.py ${ARGS}

after_success:
- if [ ${COVERAGE} = true ]; then coveralls; fi
- if [ ${COVERAGE} = true ]; then
coverage run --source pygridgen check_pygridgen.py;
coverage report -m;
coveralls;
fi
7 changes: 7 additions & 0 deletions check_pygridgen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import sys
import matplotlib
matplotlib.use('agg')

import pygridgen
status = pygridgen.test(*sys.argv[1:])
sys.exit(status)
18 changes: 11 additions & 7 deletions pygridgen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# encoding: utf-8
'''
"""
PYGRIDGEN is a tool for building curvilinear grids.
PYGRIDGEN is based on Pavel Sakov's gridgen c-library, with python capabilities
Expand All @@ -10,13 +10,17 @@
Released under an MIT license.
'''
"""


from .grid import *
from .csa import *
from .boundary_interactor import *

__authors__ = ['Robert Hetland <hetland@tamu.edu>',
'Rich Signell <rsignell@gmail.com']
from .tests import test

__authors__ = [
'Robert Hetland <hetland@tamu.edu>',
'Rich Signell <rsignell@gmail.com',
'Paul Hobson <phobson@geosyntec.com>'
]

__version__ = '0.1.0'
__version__ = '0.2.dev'
10 changes: 10 additions & 0 deletions pygridgen/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from pkg_resources import resource_filename

import pytest

import pygridgen

def test(*args):
options = [resource_filename('pygridgen', 'tests')]
options.extend(list(args))
return pytest.main(options)
73 changes: 32 additions & 41 deletions tests/test_focus.py → pygridgen/tests/test_focus.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy

import numpy.testing as nptest
import nose.tools as nt
import pytest

import pygridgen

Expand Down Expand Up @@ -36,21 +37,21 @@ def setup(self):
)
self.focused_x, self.focused_y = self.focus(self.x, self.y)

@nt.raises(ValueError)
def test_call_bad_x_pos(self):
self.focus([1.1], [0.5])
with pytest.raises(ValueError):
self.focus([1.1], [0.5])

@nt.raises(ValueError)
def test_call_bad_x_neg(self):
self.focus([-0.1], [0.5])
with pytest.raises(ValueError):
self.focus([-0.1], [0.5])

@nt.raises(ValueError)
def test_call_bad_y_pos(self):
self.focus([0.5], [1.1])
with pytest.raises(ValueError):
self.focus([0.5], [1.1])

@nt.raises(ValueError)
def test_call_bad_y_neg(self):
self.focus([0.5], [-0.1])
with pytest.raises(ValueError):
self.focus([0.5], [-0.1])

def test_focused_x(self):
nptest.assert_array_almost_equal(
Expand All @@ -67,35 +68,28 @@ def test_focused_y(self):
)

def test_pos(self):
nt.assert_true(hasattr(self.focus, self.pos_attr))
nt.assert_equal(getattr(self.focus, self.pos_attr) , self.pos)
assert getattr(self.focus, self.pos_attr) == self.pos

def test_factor(self):
nt.assert_true(hasattr(self.focus, 'factor'))
nt.assert_equal(self.focus.factor, self.factor)
assert self.focus.factor == self.factor

def test_reach(self):
nt.assert_true(hasattr(self.focus, self.reach_attr))
nt.assert_equal(
getattr(self.focus, self.reach_attr),
self.reach
)
assert getattr(self.focus, self.reach_attr) == self.reach

@nt.raises(ValueError)
def test_badaxis(self):
focus = pygridgen.grid._FocusPoint(0.1, 'xjunk', 2, 0.25)
with pytest.raises(ValueError):
focus = pygridgen.grid._FocusPoint(0.1, 'xjunk', 2, 0.25)

@nt.raises(ValueError)
def test_position_positive(self):
focus = pygridgen.grid._FocusPoint(1.1, self.axis, 2, 0.25)
with pytest.raises(ValueError):
focus = pygridgen.grid._FocusPoint(1.1, self.axis, 2, 0.25)

@nt.raises(ValueError)
def test_position_negative(self):
focus = pygridgen.grid._FocusPoint(-0.1, self.axis, 2, 0.25)
with pytest.raises(ValueError):
focus = pygridgen.grid._FocusPoint(-0.1, self.axis, 2, 0.25)


class test__Focus_x(_focusPointMixin):
@nt.nottest
class Test__Focus_x(_focusPointMixin):
def main_setup(self):
self.axis = 'x'
self.focus = pygridgen.grid._FocusPoint(
Expand All @@ -106,8 +100,7 @@ def main_setup(self):
self.focused_x, self.focused_y = self.focus(self.x, self.y)


class test__Focus_y(_focusPointMixin):
@nt.nottest
class Test__Focus_y(_focusPointMixin):
def main_setup(self):
self.axis = 'y'
self.pos_attr = 'pos'
Expand All @@ -117,7 +110,7 @@ def main_setup(self):
self.known_focused_y = self.known_focused.T


class test_Focus(object):
class Test_Focus(object):
def setup(self):
self.focus = pygridgen.Focus()
self.known_focused_x = numpy.array([
Expand Down Expand Up @@ -151,25 +144,23 @@ def setup(self):
self.focus.add_focus(0.50, 'y', factor=2, extent=0.3)

def test__focuspoints(self):
nt.assert_true(hasattr(self.focus, '_focuspoints'))
nt.assert_true(isinstance(self.focus._focuspoints, list))
nt.assert_equal(len(self.focus._focuspoints), 3)
assert isinstance(self.focus._focuspoints, list)
assert len(self.focus._focuspoints) == 3

def test_add_focus_x(self):
self.focus.add_focus(0.99, 'x', factor=3, extent=0.1)
nt.assert_true(len(self.focus._focuspoints), 4)
nt.assert_true(isinstance(self.focus._focuspoints[-1], pygridgen.grid._FocusPoint))
nt.assert_equal(self.focus._focuspoints[-1].pos, 0.99)
nt.assert_equal(self.focus._focuspoints[-1].axis, 'x')
assert len(self.focus._focuspoints), 4
assert isinstance(self.focus._focuspoints[-1], pygridgen.grid._FocusPoint)
assert self.focus._focuspoints[-1].pos == 0.99
assert self.focus._focuspoints[-1].axis == 'x'

def test_add_focus_y(self):
self.focus.add_focus(0.99, 'y', factor=3, extent=0.1)
nt.assert_true(len(self.focus._focuspoints), 4)
nt.assert_true(isinstance(self.focus._focuspoints[-1], pygridgen.grid._FocusPoint))
nt.assert_equal(self.focus._focuspoints[-1].pos, 0.99)
nt.assert_equal(self.focus._focuspoints[-1].axis, 'y')
assert len(self.focus._focuspoints), 4
assert isinstance(self.focus._focuspoints[-1], pygridgen.grid._FocusPoint)
assert self.focus._focuspoints[-1].pos == 0.99
assert self.focus._focuspoints[-1].axis == 'y'

@nt.nottest
def do_call(self):
_x = numpy.linspace(0, 1, num=10)
_y = numpy.linspace(0, 1, num=10)
Expand Down

0 comments on commit f4b1cf5

Please sign in to comment.