Skip to content

Commit

Permalink
cleanup pygridgen imports in tests
Browse files Browse the repository at this point in the history
now it's optional and a minimal test suite can run
on windows
  • Loading branch information
phobson committed Oct 1, 2015
1 parent 003ca15 commit 4c2c7ad
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Icon
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
.noseids

# C extensions
*.so
Expand Down
2 changes: 1 addition & 1 deletion pygridtools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .core import *
from .misc import *
from .core import *
from . import iotools
from . import viz
2 changes: 1 addition & 1 deletion pygridtools/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def plotPygridgen(grid, ax=None):
if ax.is_last_row():
ax.set_xlabel('$nx = {}$'.format(grid.nx), size=14)

fig, ax = plotCells(grid.x, grid.y, ax=ax, engine='mpl')
fig = plotCells(grid.x, grid.y, ax=ax, engine='mpl')

return fig

Expand Down
34 changes: 23 additions & 11 deletions testing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@
import matplotlib; matplotlib.use('agg')
import pandas
import fiona
import pygridgen

#from pygridtools.misc import Grid

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


@nt.nottest
class fakegrid(object):
def __init__(self):
self.x, self.y = makeSimpleNodes()
boundary = makeSimpleBoundary()
self.xbry = boundary['x']
self.ybry = boundary['y']
self.beta = boundary['beta']
self.ny, self.nx = self.x.shape
self.x_rho, self.y_rho = makeSimpleCells()


def makeSimpleBoundary():
xbry = np.array([1, 2, 2, 2, 3, 4, 4, 3, 2, 2, 1, 1, 1])
ybry = np.array([4, 4, 3, 2, 2, 2, 1, 1, 1, 0, 0, 1, 4])
Expand All @@ -22,13 +30,17 @@ def makeSimpleGrid():
'''
Makes a basic grid for testing purposes
'''
boundary = makeSimpleBoundary()
np.random.seed(0)
ny = 9
nx = 7
ul_idx = 0
grid = pygridgen.Gridgen(boundary.x, boundary.y, boundary.beta,
(ny, nx), ul_idx=ul_idx)
try:
import pygridgen
boundary = makeSimpleBoundary()
np.random.seed(0)
ny = 9
nx = 7
ul_idx = 0
grid = pygridgen.Gridgen(boundary.x, boundary.y, boundary.beta,
(ny, nx), ul_idx=ul_idx)
except ImportError:
grid = fakegrid()

return grid

Expand Down
64 changes: 64 additions & 0 deletions tests/baseline_files/grid_mac.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
## 7 x 9
1.000 -0.000
1.500 -0.000
2.000 -0.000
NaN NaN
NaN NaN
NaN NaN
NaN NaN
1.000 0.500
1.500 0.500
2.000 0.500
NaN NaN
NaN NaN
NaN NaN
NaN NaN
1.000 1.000
1.500 1.000
2.000 1.000
2.500 1.000
3.000 1.000
3.500 1.000
4.000 1.000
1.000 1.500
1.500 1.500
2.000 1.500
2.500 1.500
3.000 1.500
3.500 1.500
4.000 1.500
1.000 2.000
1.500 2.000
2.000 2.000
2.500 2.000
3.000 2.000
3.500 2.000
4.000 2.000
1.000 2.500
1.500 2.500
2.000 2.500
NaN NaN
NaN NaN
NaN NaN
NaN NaN
1.000 3.000
1.500 3.000
2.000 3.000
NaN NaN
NaN NaN
NaN NaN
NaN NaN
1.000 3.500
1.500 3.500
2.000 3.500
NaN NaN
NaN NaN
NaN NaN
NaN NaN
1.000 4.000
1.500 4.000
2.000 4.000
NaN NaN
NaN NaN
NaN NaN
NaN NaN
64 changes: 64 additions & 0 deletions tests/baseline_files/grid_win.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
## 7 x 9
1.000 0.000
1.500 0.000
2.000 0.000
NaN NaN
NaN NaN
NaN NaN
NaN NaN
1.000 0.500
1.500 0.500
2.000 0.500
NaN NaN
NaN NaN
NaN NaN
NaN NaN
1.000 1.000
1.500 1.000
2.000 1.000
2.500 1.000
3.000 1.000
3.500 1.000
4.000 1.000
1.000 1.500
1.500 1.500
2.000 1.500
2.500 1.500
3.000 1.500
3.500 1.500
4.000 1.500
1.000 2.000
1.500 2.000
2.000 2.000
2.500 2.000
3.000 2.000
3.500 2.000
4.000 2.000
1.000 2.500
1.500 2.500
2.000 2.500
NaN NaN
NaN NaN
NaN NaN
NaN NaN
1.000 3.000
1.500 3.000
2.000 3.000
NaN NaN
NaN NaN
NaN NaN
NaN NaN
1.000 3.500
1.500 3.500
2.000 3.500
NaN NaN
NaN NaN
NaN NaN
NaN NaN
1.000 4.000
1.500 4.000
2.000 4.000
NaN NaN
NaN NaN
NaN NaN
NaN NaN
11 changes: 9 additions & 2 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
from numpy import nan
import matplotlib.pyplot as plt
import pandas
import pygridgen

import nose.tools as nt
import numpy.testing as nptest
import pandas.util.testing as pdtest

import pygridgen
from pygridtools import core
import testing

try:
import pygridgen
has_pgg = True
except ImportError:
has_pgg = False


class test__PointSet(object):
def setup(self):
Expand Down Expand Up @@ -626,6 +630,7 @@ def setup(self):
'ul_idx': 0
}

@nptest.dec.skipif(not has_pgg)
def test_with_coords_and_bathy(self):
grid = core.makeGrid(
coords=self.coords,
Expand All @@ -634,6 +639,7 @@ def test_with_coords_and_bathy(self):
)
nt.assert_true(isinstance(grid, pygridgen.Gridgen))

@nptest.dec.skipif(not has_pgg)
@nt.raises(ValueError)
def test_makegrid_no_nx(self):
nx = self.gridparams.pop('nx')
Expand All @@ -643,6 +649,7 @@ def test_makegrid_no_nx(self):
**self.gridparams
)

@nptest.dec.skipif(not has_pgg)
@nt.raises(ValueError)
def test_makegrid_no_ny(self):
ny = self.gridparams.pop('ny')
Expand Down
8 changes: 7 additions & 1 deletion tests/test_iotools.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,15 @@ def test_filter_nosqueeze(self):
def test_dumpGridFile():
grid = testing.makeSimpleGrid()
outputfile = 'tests/result_files/grid.out'
baselinefile = 'tests/baseline_files/grid.out'
iotools.dumpGridFiles(grid, outputfile)

if sys.platform == 'win32':
baselinefile = 'tests/baseline_files/grid_win.out'
elif sys.platform == 'darwin':
baselinefile = 'tests/baseline_files/grid_osx.out'
else:
baselinefile = 'tests/baseline_files/grid.out'

testing.compareTextFiles(outputfile, baselinefile)


Expand Down
9 changes: 8 additions & 1 deletion tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from numpy import nan
import matplotlib.pyplot as plt
import pandas
import pygridgen

import nose.tools as nt
import numpy.testing as nptest
Expand All @@ -15,6 +14,12 @@

np.set_printoptions(linewidth=150, nanstr='-')

try:
import pygridgen
has_pgg = True
except ImportError:
has_pgg = False


def test_points_inside_poly():
polyverts = np.array([[0, 0], [0, 1], [1, 1], [1, 0]])
Expand Down Expand Up @@ -160,6 +165,7 @@ def setup(self):
[100.5 , 100.55, nan, nan, nan, nan]
]))

@nptest.dec.skipif(not has_pgg)
def test_fake_bathy(self):
elev = misc.interpolateBathymetry(None, self.grid.x_rho, self.grid.y_rho)
nptest.assert_array_equal(
Expand All @@ -169,6 +175,7 @@ def test_fake_bathy(self):
)
nt.assert_tuple_equal(elev.shape, self.grid.x_rho.shape)

@nptest.dec.skipif(not has_pgg)
def test_real_bathy(self):
elev = misc.interpolateBathymetry(
self.bathy, self.grid.x_rho, self.grid.y_rho
Expand Down

0 comments on commit 4c2c7ad

Please sign in to comment.