コード例 #1
0
 def __call__(self, fname, datadir=None):
     if datadir is None:
         datadir = self._default_path
     fpath = os.path.join(datadir, fname)
     try:
         return self._cache[fpath]
     except KeyError:
         pass
     d = np.load(fpath)
     ret = Bunch(d)
     self._cache[fpath] = ret
     return ret
コード例 #2
0
    def record_details(self, evalargs):
        tline = self.testline
        i0 = 5 + tline.index('find(')
        tline = tline[i0:-1]
        checks = tline.split('|')
        parts = []
        for check in checks:
            check = check.replace(' ', '')
            if check.startswith('('):
                check = check[1:-1]
            part = Bunch(check=check)
            LHS, RHS = check.split('>=')
            part.tolerance = eval(RHS, *evalargs)
            # Sometimes there is an extra set of ().
            if LHS.startswith('('):
                LHS = LHS[1:-1]
            LHS = LHS[4:-1]  # chop off abs(...)
            target, calculated = LHS.split('-')
            part.checkval = eval(target, *evalargs)
            part.val = eval(calculated, *evalargs)
            parts.append(part)

        self.details = parts
コード例 #3
0
import os

import numpy as np
from numpy.testing import assert_array_equal, assert_almost_equal

import gsw
from gsw._utilities import Bunch

root_path = os.path.abspath(os.path.dirname(__file__))

cv = Bunch(np.load(os.path.join(root_path, 'gsw_cv_v3_0.npz')))
# Override the original with what we calculate using pchip interp
cv.geo_strf_velocity = np.load(os.path.join(root_path,'geo_strf_velocity.npy'))

lon = [1, 2]
lat = [45, 45]
expected = 78626.18767687

# distance tests

def test_list():
    value = gsw.distance(lon, lat, p=0, axis=-1)
    assert_almost_equal(expected, value)

def test_1darray():
    value = gsw.distance(np.array(lon), np.array(lat), p=0, axis=-1)
    assert_almost_equal(expected, value)

def test_1darray_default_p():
    # @match_args_return doesn't see the default p.
    value = gsw.distance(np.array(lon), np.array(lat))
コード例 #4
0
                        action='store_true',
                        help='print output mismatch arrays')
    parser.add_argument('--find',
                        help='run functions with this substring')

    args = parser.parse_args()

    if args.mfiledir:
        mfile = os.path.join(args.mfiledir, "gsw_check_functions.m")
    else:
        mfile = "gsw_check_functions_save.m"
    checks = parse_check_functions(mfile)

    #datadir = os.path.join(os.path.dirname(gsw.utilities.__file__), 'data')
    datadir = './'
    cv = Bunch(np.load(os.path.join(datadir, 'gsw_cv_v3_0.npz')))
    cf = Bunch()

    if args.find:
        checks = [c for c in checks if args.find in c.runline]

    for fc in checks:
        fc.run()

    passes = [f for f in checks if f.passed]
    failures = [f for f in checks if f.passed is False]

    run_problems = [f for f in checks if f.exception is not None]

    etypes = [NameError, UnboundLocalError, TypeError, AttributeError]
    ex_dict = dict()
コード例 #5
0
from gsw._utilities import Bunch
from check_functions import parse_check_functions

root_path = os.path.abspath(os.path.dirname(__file__))

# Function checks that we can't handle automatically yet.
blacklist = ['deltaSA_atlas',  # the test is complicated; doesn't fit the pattern.
             #'CT_from_entropy', # needs prior entropy_from_CT; don't have it in C
             #'CT_first_derivatives', # passes, but has trouble in "details";
                                      # see check_functions.py
             #'entropy_second_derivatives', # OK now; handling extra parens.
             #'melting_ice_into_seawater',  # OK now; fixed nargs mismatch.
             ]

# We get an overflow from ct_from_enthalpy_exact, but the test passes.
cv = Bunch(np.load(os.path.join(root_path, 'gsw_cv_v3_0.npz')))
cf = Bunch()

d = dir(gsw)
funcnames = [name for name in d if '__' not in name]

mfuncs = parse_check_functions(os.path.join(root_path, 'gsw_check_functions_save.m'))
mfuncs = [mf for mf in mfuncs if mf.name in d and mf.name not in blacklist]
mfuncnames = [mf.name for mf in mfuncs]


@pytest.fixture(scope='session', params=mfuncs)
def cfcf(request):
    return cv, cf, request.param

コード例 #6
0
Tests for the unwrapped ufuncs.

This is a WIP; it doesn't work yet for all cases, and might not be a good
approach anyway.  For now, test_check_functions is adequate, handling the
wrapped ufuncs via check_functions "eval" and "exec" machinery.
"""
import pytest

import numpy as np
from numpy.testing import assert_allclose

import gsw
from gsw._utilities import Bunch
from gsw.tests.check_functions import parse_check_functions

cv = Bunch(np.load('gsw_cv_v3_0.npz'))
cf = Bunch()

d = dir(gsw._gsw_ufuncs)
funcnames = [name for name in d if '__' not in name]

mfuncs = parse_check_functions('gsw_check_functions_save.m')
mfuncs = [mf for mf in mfuncs if mf.name in d]
mfuncnames = [mf.name for mf in mfuncs]

@pytest.fixture(scope='session', params=mfuncs)
def cfcf(request):
    return cv, cf, request.param

def test_mechanism(cfcf):
    cv, cf, mfunc = cfcf
コード例 #7
0
def setup(request, lonshift):
    cvshift = Bunch(**cv)
    cvshift.long_chck_cast = cv.long_chck_cast + lonshift
    return cvshift, cf, request.param