From 7cd96efbfbdd6c1b65220c5fca8daaa0f0c1409c Mon Sep 17 00:00:00 2001 From: billmills Date: Sun, 16 Jul 2023 14:05:11 -0400 Subject: [PATCH 1/6] all passing in pytest --- Dockerfile | 4 +- Dockerfile-testing-base | 2 +- tests/__init__.py | 0 tests/core_test.py | 722 ++++++++++++++++++++++++++++++++++++++++ tests/netcdf_test.py | 149 +++++++++ tests/netcdf_tests.py | 151 --------- tests/test_cotede.py | 329 +++++++++--------- tests/tests.py | 697 -------------------------------------- 8 files changed, 1035 insertions(+), 1019 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/core_test.py create mode 100644 tests/netcdf_test.py delete mode 100644 tests/netcdf_tests.py delete mode 100644 tests/tests.py diff --git a/Dockerfile b/Dockerfile index 0a90c75..846d676 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ -FROM iquod/wodpy:test-base-220904 +FROM iquod/wodpy:test-base-230716 WORKDIR /wodpy COPY . . -CMD nosetests tests/*.py \ No newline at end of file +CMD pytest \ No newline at end of file diff --git a/Dockerfile-testing-base b/Dockerfile-testing-base index 97663a2..9001da1 100644 --- a/Dockerfile-testing-base +++ b/Dockerfile-testing-base @@ -1,4 +1,4 @@ FROM python:3.9 RUN apt-get update -y && apt-get install -y libhdf5-serial-dev netcdf-bin libnetcdf-dev -RUN pip install numpy pandas cftime netCDF4 nose \ No newline at end of file +RUN pip install numpy pandas cftime netCDF4 pytest \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/core_test.py b/tests/core_test.py new file mode 100644 index 0000000..86b9001 --- /dev/null +++ b/tests/core_test.py @@ -0,0 +1,722 @@ +from datetime import datetime +from wodpy import wod +import numpy, math, pandas, pytest + +@pytest.fixture +def classic1(): + # WOD13 format data + classic = open("tests/testData/classic.dat") + # example from pp 124 of http://data.nodc.noaa.gov/woa/WOD/DOC/wodreadme.pdf + return wod.WodProfile(classic) + +@pytest.fixture +def classic2(): + # WOD13 format data + classic = open("tests/testData/classic.dat") + c = wod.WodProfile(classic) # iterate past the first object in the file + # example with missing salinity information + return wod.WodProfile(classic) + +@pytest.fixture +def iquod1(): + # IQuOD 0.1 format data + # short example (unpacked by hand to validate) + iquod = open("tests/testData/iquod.dat") + return wod.WodProfile(iquod) + +@pytest.fixture +def iquod2(): + # IQuOD 0.1 format data + iquod = open("tests/testData/iquod.dat") + c = wod.WodProfile(iquod) # iterate past the first object in the file + # example with metadata + return wod.WodProfile(iquod) + +@pytest.fixture +def path1(): + # data with some interesting pathologies + path = open("tests/testData/pathological.dat") + return wod.WodProfile(path) + +# =================================================================== +# check the example from pp 124 of +# http://data.nodc.noaa.gov/woa/WOD/DOC/wodreadme.pdf +# is extracted correctly by base functions. +# data is in `data/classic.dat` + +def test_latitude(classic1): + ''' + check latitude == 61.930 + ''' + + latitude = classic1.latitude() + df_latitude = classic1.df().attrs['latitude'] + np_latitude = classic1.npdict()['latitude'] + header_latitude = classic1.header().latitude + assert latitude == 61.930, 'latitude should have been 61.930, instead read %f' % latitude + assert df_latitude == 61.930, 'dataframe latitude should have been 61.930, instead read %f' % df_latitude + assert np_latitude == 61.930, 'np dict latitude should have been 61.930, instead read %f' % np_latitude + assert header_latitude == 61.930, 'header latitude should have been 61.930, instead read %f' % header_latitude + +def test_latitude_error(classic1): + ''' + check latitude error is None + ''' + + latitude_unc = classic1.latitude_unc() + df_latitude_unc = classic1.df().attrs['latitude_unc'] + np_latitude_unc = classic1.npdict()['latitude_unc'] + header_latitude_unc = classic1.header().latitude_unc + assert latitude_unc is None, 'latitude error is undefined for this profile, instead read %f' % latitude_unc + assert df_latitude_unc is None, 'dataframe latitude error is undefined for this profile, instead read %f' % df_latitude_unc + assert np_latitude_unc is None, 'npdict latitude error is undefined for this profile, instead read %f' % np_latitude_unc + assert math.isnan(header_latitude_unc) , 'header latitude error is undefined for this profile, instead read %f' % header_latitude_unc + +def test_longitude(classic1): + ''' + check longitude == -172.270 + ''' + + longitude = classic1.longitude() + df_longitude = classic1.df().attrs['longitude'] + np_longitude = classic1.npdict()['longitude'] + header_longitude = classic1.header().longitude + assert longitude == -172.270, 'longitude should have been -172.270, instead read %f' % longitude + assert df_longitude == -172.270, 'dataframe longitude should have been -172.270, instead read %f' % df_longitude + assert np_longitude == -172.270, 'np dict longitude should have been -172.270, instead read %f' % np_longitude + assert header_longitude == -172.270, 'header longitude should have been -172.270, instead read %f' % header_longitude + +def test_longitude_error(classic1): + ''' + check longitude error is None + ''' + + longitude_unc = classic1.longitude_unc() + df_longitude_unc = classic1.df().attrs['longitude_unc'] + np_longitude_unc = classic1.npdict()['longitude_unc'] + header_longitude_unc = classic1.header().longitude_unc + assert longitude_unc is None, 'longitude error is undefined for this profile, instead read %f' % longitude_unc + assert df_longitude_unc is None, 'dataframe longitude error is undefined for this profile, instead read %f' % df_longitude_unc + assert np_longitude_unc is None, 'np dict longitude error is undefined for this profile, instead read %f' % np_longitude_unc + assert math.isnan(header_longitude_unc), 'header longitude error is undefined for this profile, instead read %f' % header_longitude_unc + +def test_uid(classic1): + ''' + check profile ID == 67064 + ''' + + uid = classic1.uid() + df_uid = classic1.df().attrs['uid'] + np_uid = classic1.npdict()['uid'] + header_uid = classic1.header().uid + assert uid == 67064, 'uid should have been 67064, instead read %f' % uid + assert df_uid == 67064, 'dataframe uid should have been 67064, instead read %f' % df_uid + assert np_uid == 67064, 'np dict uid should have been 67064, instead read %f' % np_uid + assert header_uid == 67064, 'header uid should have been 67064, instead read %f' % header_uid + +def test_n_levels(classic1): + ''' + check the number of levels == 4 + ''' + + levels = classic1.n_levels() + df_levels = classic1.df().attrs['n_levels'] + np_levels = classic1.npdict()['n_levels'] + header_n_levels = classic1.header().n_levels + assert levels == 4, 'levels should have been 4, instead read %f' % levels + assert df_levels == 4, 'dataframe levels should have been 4, instead read %f' % df_levels + assert np_levels == 4, 'np dict levels should have been 4, instead read %f' % np_levels + assert header_n_levels == 4, 'header levels should have been 4, instead read %f' % header_levels + +def test_year(classic1): + ''' + check year == 1934 + ''' + + year = classic1.year() + df_year = classic1.df().attrs['year'] + np_year = classic1.npdict()['year'] + header_year = classic1.header().year + assert year == 1934, 'year should have been 1934, instead read %f' % year + assert df_year == 1934, 'dataframe year should have been 1934, instead read %f' % df_year + assert np_year == 1934, 'np dict year should have been 1934, instead read %f' % np_year + assert header_year == 1934, 'header year should have been 1934, instead read %f' % header_year + +def test_month(classic1): + ''' + check month == 8 + ''' + + month = classic1.month() + df_month = classic1.df().attrs['month'] + np_month = classic1.npdict()['month'] + header_month = classic1.header().month + assert month == 8, 'month should have been 8, instead read %f' % month + assert df_month == 8, 'dataframe month should have been 8, instead read %f' % df_month + assert np_month == 8, 'np dict month should have been 8, instead read %f' % np_month + assert header_month == 8, 'header month should have been 8, instead read %f' % header_month + + +def test_day(classic1): + ''' + check day == 7 + ''' + + day = classic1.day() + df_day = classic1.df().attrs['day'] + np_day = classic1.npdict()['day'] + header_day = classic1.header().day + assert day == 7, 'day should have been 7, instead read %f' % day + assert df_day == 7, 'dataframe day should have been 7, instead read %f' % df_day + assert np_day == 7, 'np dict day should have been 7, instead read %f' % np_day + assert header_day == 7, 'header day should have been 7, instead read %f' % header_day + +def test_time(classic1): + ''' + check time == 10.37 + ''' + + time = classic1.time() + df_time = classic1.df().attrs['time'] + np_time = classic1.npdict()['time'] + header_time = classic1.header().time + assert time == 10.37, 'time should have been 10.37, instead read %f' % time + assert df_time == 10.37, 'dataframe time should have been 10.37, instead read %f' % df_time + assert np_time == 10.37, 'np dict time should have been 10.37, instead read %f' % np_time + assert header_time == 10.37, 'header time should have been 10.37, instead read %f' % header_time + + +def test_datetime(classic1): + ''' + check datetime 1934-8-7 10:22:12 + ''' + + d = classic1.datetime() + assert d == datetime(1934, 8, 7, 10, 22, 12), \ + 'time should have been 1934-08-07 10:22:12, instead read %s' \ + % d + + +def test_probe_type(classic1): + ''' + check probe type == 7 + ''' + + probe = classic1.probe_type() + df_probe = classic1.df().attrs['probe_type'] + np_probe = classic1.npdict()['probe_type'] + header_probe = classic1.header().probe_type + assert probe == 7, 'probe should have been 7, instead read %f' % probe + assert df_probe == 7, 'dataframe probe should have been 7, instead read %f' % df_probe + assert np_probe == 7, 'np dict probe should have been 7, instead read %f' % np_probe + assert header_probe == 7, 'header probe should have been 7, instead read %f' % header_probe + + +def test_depth(classic1): + ''' + check depths == [0.0, 10.0, 25.0, 50.0] + ''' + + truth = [0.0, 10.0, 25.0, 50.0] + z = classic1.z() + df_z = classic1.df()['z'] + np_z = classic1.npdict()['z'] + assert numpy.array_equal(z, truth), 'depths should have been [0, 10, 25, 50], instead read %s' % z.__str__() + assert numpy.array_equal(df_z, truth), 'dataframe depths should have been [0, 10, 25, 50], instead read %s' % df_z.tolist().__str__() + assert numpy.array_equal(np_z, truth), 'numpy dict depths should have been [0, 10, 25, 50], instead read %s' % np_z.__str__() + +def test_depth_error(classic1): + ''' + check depth errors == [--,--,--,--] (all masked) + ''' + + truth = numpy.ma.MaskedArray([0,0,0,0], [True, True, True, True]) + dftruth = pandas.Series(numpy.nan, index=[0,1,2,3]) + z_unc = classic1.z_unc() + df_z_unc = classic1.df()['z_unc'] + np_z_unc = classic1.npdict()['z_unc'] + assert numpy.array_equal(z_unc, truth), 'depth errors should have been all masked, instead read %s' % z_unc.__str__() + assert df_z_unc.equals(dftruth), 'dataframe depth errors should have been all masked, instead read %s' % df_z_unc.__str__() + assert numpy.array_equal(np_z_unc, truth), 'numpy dict depth errors should have been all masked, instead read %s' % np_z_unc.__str__() + +def test_temperature(classic1): + ''' + check temperatures == [8.960, 8.950, 0.900, -1.230] + ''' + + truth = [8.960, 8.950, 0.900, -1.230] + t = classic1.t() + df_t = classic1.df()['t'] + np_t = classic1.npdict()['t'] + assert numpy.array_equal(t, truth), 'temperatures should have been [8.96, 8.95, 0.9, -1.23], instead read %s' % t.__str__() + assert numpy.array_equal(df_t, truth), 'dataframe temperatures should have been [8.96, 8.95, 0.9, -1.23], instead read \n%s' % df_t.__str__() + assert numpy.array_equal(np_t, truth), 'numpy dict temperatures should have been [8.96, 8.95, 0.9, -1.23], instead read %s' % np_t.__str__() + +def test_temperature_error(classic1): + ''' + check temperature errors == [--,--,--,--] (all masked) + ''' + + truth = numpy.ma.MaskedArray([0,0,0,0], [True, True, True, True]) + dftruth = pandas.Series(numpy.nan, index=[0,1,2,3]) + t_unc = classic1.t_unc() + df_t_unc = classic1.df()['t_unc'] + np_t_unc = classic1.npdict()['t_unc'] + + assert numpy.array_equal(t_unc, truth), 'temperature errors should have been all masked, instead read %s' % t_unc.__str__() + assert df_t_unc.equals(dftruth), 'dataframe temperature errors should have been all masked, instead read %s' % df_t_unc.__str__() + assert numpy.array_equal(np_t_unc, truth), 'numpy dict temperature errors should have been all masked, instead read %s' % np_t_unc.__str__() + + +def test_salinity(classic1): + ''' + check salinities == [30.900, 30.900, 31.910, 32.410] + ''' + + truth = [30.900, 30.900, 31.910, 32.410] + s = classic1.s() + df_s = classic1.df()['s'] + np_s = classic1.npdict()['s'] + assert numpy.array_equal(s, truth), 'salinities should have been [30.9, 30.9, 31.91, 32.41], instead read %s' % s.__str__() + assert numpy.array_equal(df_s, truth), 'dataframe salinities should have been [30.9, 30.9, 31.91, 32.41], instead read \n%s' % df_s.__str__() + assert numpy.array_equal(np_s, truth), 'numpy dict salinities should have been [30.9, 30.9, 31.91, 32.41], instead read %s' % np_s.__str__() + +def test_salinity_error(classic1): + ''' + check salinity errors == [--,--,--,--] (all masked) + ''' + + truth = numpy.ma.MaskedArray([0,0,0,0], [True, True, True, True]) + dftruth = pandas.Series(numpy.nan, index=[0,1,2,3]) + s_unc = classic1.s_unc() + df_s_unc = classic1.df()['s_unc'] + np_s_unc = classic1.npdict()['s_unc'] + + assert numpy.array_equal(s_unc, truth), 'salinity errors should have been all masked, instead read %s' % s_unc.__str__() + assert df_s_unc.equals(dftruth), 'dataframe salinity errors should have been all masked, instead read %s' % df_s_unc.__str__() + assert numpy.array_equal(np_s_unc, truth), 'numpy dict salinity errors should have been all masked, instead read %s' % np_s_unc.__str__() + +def test_oxygen(classic1): + ''' + check oxygen levels = [6.750, 6.700, 8.620, 7.280] + ''' + + truth = [6.750, 6.700, 8.620, 7.280] + o2 = classic1.oxygen() + df_o2 = classic1.df()['oxygen'] + np_o2 = classic1.npdict()['oxygen'] + + assert numpy.array_equal(o2, truth), 'oxygen levels should have been [6.750, 6.700, 8.620, 7.280], instead read %s' % o2.__str__() + assert numpy.array_equal(df_o2, truth), 'dataframe oxygen levels should have been [6.750, 6.700, 8.620, 7.280], instead read \n%s' % df_o2.__str__() + assert numpy.array_equal(np_o2, truth), 'numpy dict oxygen levels should have been [6.750, 6.700, 8.620, 7.280], instead read %s' % np_o2.__str__() + +def test_phosphate(classic1): + ''' + check phosphate levels = [0.650, 0.710, 0.900, 1.170] + ''' + + truth = [0.650, 0.710, 0.900, 1.170] + phos = classic1.phosphate() + df_phos = classic1.df()['phosphate'] + np_phos = classic1.npdict()['phosphate'] + + assert numpy.array_equal(phos, truth), 'phosphate levels should have been [0.650, 0.710, 0.900, 1.170], instead read %s' % phos.__str__() + assert numpy.array_equal(df_phos, truth), 'dataframe phosphate levels should have been [0.650, 0.710, 0.900, 1.170], instead read \n%s' % df_phos.__str__() + assert numpy.array_equal(np_phos, truth), 'numpy dict phosphate levels should have been [0.650, 0.710, 0.900, 1.170], instead read %s' % np_phos.__str__() + +def test_silicate(classic1): + ''' + check silicate levels = [20.500, 12.300, 15.400, 25.600] + ''' + + truth = [20.500, 12.300, 15.400, 25.600] + sili = classic1.silicate() + df_sili = classic1.df()['silicate'] + np_sili = classic1.npdict()['silicate'] + + assert numpy.array_equal(sili, truth), 'silicate levels should have been [20.500, 12.300, 15.400, 25.600], instead read %s' % sili.__str__() + assert numpy.array_equal(df_sili, truth), 'dataframe silicate levels should have been [20.500, 12.300, 15.400, 25.600], instead read \n%s' % df_sili.__str__() + assert numpy.array_equal(np_sili, truth), 'numpy dict silicate levels should have been [20.500, 12.300, 15.400, 25.600], instead read %s' % np_sili.__str__() + +def test_pH(classic1): + ''' + check pH levels = [8.100, 8.100, 8.100, 8.050] + ''' + + truth = [8.100, 8.100, 8.100, 8.050] + pH = classic1.pH() + df_pH = classic1.df()['pH'] + np_pH = classic1.npdict()['pH'] + + assert numpy.array_equal(pH, truth), 'pH levels should have been [8.100, 8.100, 8.100, 8.050], instead read %s' % pH.__str__() + assert numpy.array_equal(df_pH, truth), 'dataframe pH levels should have been [8.100, 8.100, 8.100, 8.050], instead read \n%s' % df_pH.__str__() + assert numpy.array_equal(np_pH, truth), 'numpy dict pH levels should have been [8.100, 8.100, 8.100, 8.050], instead read %s' % np_pH.__str__() + +def test_PI(classic1): + ''' + check for PI code + ''' + + truth = [{'Variable code': 0, 'P.I. code': 215}, {'Variable code': 0, 'P.I. code': 216}, {'Variable code': -5006, 'P.I. code': 217}, {'Variable code': -5002, 'P.I. code': 218}] + PIs = classic1.PIs() + df_PIs = classic1.df().attrs['PIs'] + np_PIs = classic1.npdict()['PIs'] + assert numpy.array_equal(PIs, truth), 'PIs should have been [{"Variable code": 0, "P.I. code": 215}, {"Variable code": 0, "P.I. code": 216}, {"Variable code": -5006, "P.I. code": 217}, {"Variable code": -5002, "P.I. code": 218}], instead read %s' % PIs.__str__() + assert numpy.array_equal(df_PIs, truth), 'dataframe PIs should have been [{"Variable code": 0, "P.I. code": 215}, {"Variable code": 0, "P.I. code": 216}, {"Variable code": -5006, "P.I. code": 217}, {"Variable code": -5002, "P.I. code": 218}], instead read \n%s' % PIs.__str__() + assert numpy.array_equal(np_PIs, truth), 'numpy dict PIs should have been [{"Variable code": 0, "P.I. code": 215}, {"Variable code": 0, "P.I. code": 216}, {"Variable code": -5006, "P.I. code": 217}, {"Variable code": -5002, "P.I. code": 218}], instead read %s' % PIs.__str__() + +def test_originator_cruise(classic1): + + truth = 'STOCS85A' + originator_cruise = classic1.originator_cruise() + df_originator_cruise = classic1.df().attrs['originator_cruise'] + np_originator_cruise = classic1.npdict()['originator_cruise'] + assert originator_cruise == truth, 'Originator cruise should have been STOCS85A, instead read %s' % originator_cruise + assert df_originator_cruise == truth, 'dataframe riginator cruise should have been STOCS85A, instead read %s' % df_originator_cruise + assert np_originator_cruise == truth, 'numpy dict originator cruise should have been STOCS85A, instead read %s' % np_originator_cruise + +def test_originator_station(classic1): + + truth = None + originator_station = classic1.originator_station() + df_originator_station = classic1.df().attrs['originator_station'] + np_originator_station = classic1.npdict()['originator_station'] + assert originator_station == truth + assert df_originator_station == truth + assert np_originator_station == truth + +# =================================================================== +# spot check another pre-iquod profile with many missing values +# data: data/classic.dat + +def test_missing_vars(classic2): + ''' + check that error value extraction does not fail when measured value is missing + note if a variable value is missing, wodpy assumes the error on the value will also be missing + ''' + + truth = numpy.ma.MaskedArray([0]*24, [True]*24) + s_unc = classic2.s_unc() + assert numpy.array_equal(s_unc, truth), 'expected salinity errors to all be missing, but got %s instead' % s_unc.__str__() + +# =================================================================== +# check that an IQuOD v 0.1 profile is unpacked correctly +# data is in `data/iquod.dat` + +def test_iquod_latitude(iquod1): + ''' + check latitude == 34.5883 + ''' + + latitude = iquod1.latitude() + df_latitude = iquod1.df().attrs['latitude'] + np_latitude = iquod1.npdict()['latitude'] + header_latitude = iquod1.header().latitude + assert latitude == 34.5883, 'latitude should have been 34.5883, instead read %f' % latitude + assert df_latitude == 34.5883, 'dataframe latitude should have been 34.5883, instead read %f' % df_latitude + assert np_latitude == 34.5883, 'np dict latitude should have been 34.5883, instead read %f' % np_latitude + assert header_latitude == 34.5883, 'header latitude should have been 34.5883, instead read %f' % header_latitude + +def test_iquod_latitude_error(iquod1): + ''' + check latitude error is None + ''' + + latitude_unc = iquod1.latitude_unc() + df_latitude_unc = iquod1.df().attrs['latitude_unc'] + np_latitude_unc = iquod1.npdict()['latitude_unc'] + header_latitude_unc = iquod1.header().latitude_unc + assert latitude_unc is None, 'latitude error is undefined for this profile, instead read %f' % latitude_unc + assert df_latitude_unc is None, 'dataframe latitude error is undefined for this profile, instead read %f' % df_latitude_unc + assert np_latitude_unc is None, 'npdict latitude error is undefined for this profile, instead read %f' % np_latitude_unc + assert math.isnan(header_latitude_unc) , 'header latitude error is undefined for this profile, instead read %f' % header_latitude_unc + +def test_iquod_longitude(iquod1): + ''' + check longitude == 134.2433 + ''' + + longitude = iquod1.longitude() + df_longitude = iquod1.df().attrs['longitude'] + np_longitude = iquod1.npdict()['longitude'] + header_longitude = iquod1.header().longitude + assert longitude == 134.2433, 'longitude should have been 134.2433, instead read %f' % longitude + assert df_longitude == 134.2433, 'dataframe longitude should have been 134.2433, instead read %f' % df_longitude + assert np_longitude == 134.2433, 'np dict longitude should have been 134.2433, instead read %f' % np_longitude + assert header_longitude == 134.2433, 'header longitude should have been 134.2433, instead read %f' % header_longitude + +def test_iquod_longitude_error(iquod1): + ''' + check longitude error is None + ''' + + longitude_unc = iquod1.longitude_unc() + df_longitude_unc = iquod1.df().attrs['longitude_unc'] + np_longitude_unc = iquod1.npdict()['longitude_unc'] + header_longitude_unc = iquod1.header().longitude_unc + assert longitude_unc is None, 'longitude error is undefined for this profile, instead read %f' % longitude_unc + assert df_longitude_unc is None, 'dataframe longitude error is undefined for this profile, instead read %f' % df_longitude_unc + assert np_longitude_unc is None, 'npdict longitude error is undefined for this profile, instead read %f' % np_longitude_unc + assert math.isnan(header_longitude_unc) , 'header longitude error is undefined for this profile, instead read %f' % header_longitude_unc + + +def test_iquod_uid(iquod1): + ''' + check cruise ID == 13393621 + ''' + + uid = iquod1.uid() + df_uid = iquod1.df().attrs['uid'] + np_uid = iquod1.npdict()['uid'] + header_uid = iquod1.header().uid + assert uid == 13393621, 'uid should have been 13393621, instead read %f' % uid + assert df_uid == 13393621, 'dataframe uid should have been 13393621, instead read %f' % df_uid + assert np_uid == 13393621, 'np dict uid should have been 13393621, instead read %f' % np_uid + assert header_uid == 13393621, 'header uid should have been 13393621, instead read %f' % header_uid + +def test_iquod_n_levels(iquod1): + ''' + check the number of levels == 5 + ''' + + levels = iquod1.n_levels() + df_levels = iquod1.df().attrs['n_levels'] + np_levels = iquod1.npdict()['n_levels'] + header_n_levels = iquod1.header().n_levels + assert levels == 5, 'levels should have been 5, instead read %f' % levels + assert df_levels == 5, 'dataframe levels should have been 5, instead read %f' % df_levels + assert np_levels == 5, 'np dict levels should have been 5, instead read %f' % np_levels + assert header_n_levels == 5, 'header levels should have been 5, instead read %f' % header_levels + +def test_iquod_year(iquod1): + ''' + check year == 2000 + ''' + + year = iquod1.year() + df_year = iquod1.df().attrs['year'] + np_year = iquod1.npdict()['year'] + header_year = iquod1.header().year + assert year == 2000, 'year should have been 2000, instead read %f' % year + assert df_year == 2000, 'dataframe year should have been 2000, instead read %f' % df_year + assert np_year == 2000, 'np dict year should have been 2000, instead read %f' % np_year + assert header_year == 2000, 'header year should have been 2000, instead read %f' % header_year + +def test_iquod_month(iquod1): + ''' + check month == 1 + ''' + + month = iquod1.month() + df_month = iquod1.df().attrs['month'] + np_month = iquod1.npdict()['month'] + header_month = iquod1.header().month + assert month == 1, 'month should have been 1, instead read %f' % month + assert df_month == 1, 'dataframe month should have been 1, instead read %f' % df_month + assert np_month == 1, 'np dict month should have been 1, instead read %f' % np_month + assert header_month == 1, 'header month should have been 1, instead read %f' % header_month + +def test_iquod_day(iquod1): + ''' + check day == 4 + ''' + + day = iquod1.day() + df_day = iquod1.df().attrs['day'] + np_day = iquod1.npdict()['day'] + header_day = iquod1.header().day + assert day == 4, 'day should have been 4, instead read %f' % day + assert df_day == 4, 'dataframe day should have been 4, instead read %f' % df_day + assert np_day == 4, 'np dict day should have been 4, instead read %f' % np_day + assert header_day == 4, 'header day should have been 4, instead read %f' % header_day + +def test_iquod_time(iquod1): + ''' + check time == 3.7 + ''' + + time = iquod1.time() + df_time = iquod1.df().attrs['time'] + np_time = iquod1.npdict()['time'] + header_time = iquod1.header().time + assert time == 3.7, 'time should have been 3.7, instead read %f' % time + assert df_time == 3.7, 'dataframe time should have been 3.7, instead read %f' % df_time + assert np_time == 3.7, 'np dict time should have been 3.7, instead read %f' % np_time + assert header_time == 3.7, 'header time should have been 3.7, instead read %f' % header_time + + +def test_iquod_datetime(iquod1): + ''' + check datetime 2000-1-4 3:42:00 + ''' + + d = iquod1.datetime() + assert d == datetime(2000, 1, 4, 3, 42, 00), \ + 'time should have been 2000-01-04 3:42:00, instead read %s' \ + % d + + +def test_iquod_probe_type(iquod1): + ''' + check probe type == 4 + ''' + + probe = iquod1.probe_type() + df_probe = iquod1.df().attrs['probe_type'] + np_probe = iquod1.npdict()['probe_type'] + header_probe = iquod1.header().probe_type + assert probe == 4, 'probe should have been 4, instead read %f' % probe + assert df_probe == 4, 'dataframe probe should have been 4, instead read %f' % df_probe + assert np_probe == 4, 'np dict probe should have been 4, instead read %f' % np_probe + assert header_probe == 4, 'header probe should have been 4, instead read %f' % header_probe + +def test_iquod_depth(iquod1): + ''' + check depths == [0,2,5,10,20] + ''' + + truth = [0,2,5,10,20] + z = iquod1.z() + df_z = iquod1.df()['z'] + np_z = iquod1.npdict()['z'] + assert numpy.array_equal(z, truth), 'depths should have been [0,2,5,10,20], instead read %s' % z.__str__() + assert numpy.array_equal(df_z, truth), 'dataframe depths should have been [0,2,5,10,20], instead read %s' % df_z.tolist().__str__() + assert numpy.array_equal(np_z, truth), 'numpy dict depths should have been [0,2,5,10,20], instead read %s' % np_z.__str__() + +def test_iquod_depth_error(iquod1): + ''' + check depth errors == [0,.0016,.004,.008,.016] + ''' + + truth = [0,.0016,.004,.008,.016] + z_unc = iquod1.z_unc() + df_z_unc = iquod1.df()['z_unc'] + np_z_unc = iquod1.npdict()['z_unc'] + assert numpy.array_equal(z_unc, truth), 'depth errors should have been [0,.0016,.004,.008,.016], instead read %s' % z_unc.__str__() + assert numpy.array_equal(df_z_unc, truth), 'dataframe depth errors should have been [0,.0016,.004,.008,.016], instead read %s' % df_z_unc.__str__() + assert numpy.array_equal(np_z_unc, truth), 'numpy dict depth errors should have been [0,.0016,.004,.008,.016], instead read %s' % np_z_unc.__str__() + +def test_iquod_temperature(iquod1): + ''' + check temperatures == [11.1,11.2,11.0,11.0,11.0] + ''' + + truth = [11.1,11.2,11.0,11.0,11.0] + t = iquod1.t() + df_t = iquod1.df()['t'] + np_t = iquod1.npdict()['t'] + assert numpy.array_equal(t, truth), 'temperatures should have been [11.1,11.2,11.0,11.0,11.0], instead read %s' % t.__str__() + assert numpy.array_equal(df_t, truth), 'dataframe temperatures should have been [11.1,11.2,11.0,11.0,11.0], instead read \n%s' % df_t.__str__() + assert numpy.array_equal(np_t, truth), 'numpy dict temperatures should have been [11.1,11.2,11.0,11.0,11.0], instead read %s' % np_t.__str__() + +def test_iquod_temperature_error(iquod1): + ''' + check temperature errors == [.01,.01,.01,.01,.01] + ''' + + truth = [.01,.01,.01,.01,.01] + t_unc = iquod1.t_unc() + df_t_unc = iquod1.df()['t_unc'] + np_t_unc = iquod1.npdict()['t_unc'] + assert numpy.array_equal(t_unc, truth), 'temperature errors should have been [.01,.01,.01,.01,.01], instead read %s' % t_unc.__str__() + assert numpy.array_equal(df_t_unc, truth), 'dataframe temperature errors should have been [.01,.01,.01,.01,.01], instead read %s' % df_t_unc.__str__() + assert numpy.array_equal(np_t_unc, truth), 'numpy dict temperature errors should have been [.01,.01,.01,.01,.01], instead read %s' % np_t_unc.__str__() + +def test_iquod_salinity(iquod1): + ''' + check salinities == [31.53,31.47,31.49,31.49,31.50] + ''' + + truth = [31.53,31.47,31.49,31.49,31.50] + s = iquod1.s() + df_s = iquod1.df()['s'] + np_s = iquod1.npdict()['s'] + assert numpy.array_equal(s, truth), 'salinities should have been [31.53,31.47,31.49,31.49,31.50], instead read %s' % s.__str__() + assert numpy.array_equal(df_s, truth), 'dataframe salinities should have been [31.53,31.47,31.49,31.49,31.50], instead read \n%s' % df_s.__str__() + assert numpy.array_equal(np_s, truth), 'numpy dict salinities should have been [31.53,31.47,31.49,31.49,31.50], instead read %s' % np_s.__str__() + +def test_iquod_salinity_error(iquod1): + ''' + check temperature errors == [.02,.02,.02,.02,.02] + ''' + + truth = [.02,.02,.02,.02,.02] + s_unc = iquod1.s_unc() + df_s_unc = iquod1.df()['s_unc'] + np_s_unc = iquod1.npdict()['s_unc'] + assert numpy.array_equal(s_unc, truth), 'salinity errors should have been [.02,.02,.02,.02,.02], instead read %s' % s_unc.__str__() + assert numpy.array_equal(df_s_unc, truth), 'dataframe salinity errors should have been [.02,.02,.02,.02,.02], instead read %s' % df_s_unc.__str__() + assert numpy.array_equal(np_s_unc, truth), 'numpy dict salinity errors should have been [.02,.02,.02,.02,.02], instead read %s' % np_s_unc.__str__() + + # metadata tests + +def test_metadata(iquod2): + ''' + check correct unpacking of temperature and salinity metadata from iquod profile + ''' + + truth_t = [{'code': 3, 'value': 102.0, 'iMeta': 0}, {'code': 5, 'value': 411.0, 'iMeta': 0}] + truth_s = [{'code': 3, 'value': 202.0, 'iMeta': 0}, {'code': 5, 'value': 411.0, 'iMeta': 0}] + t_meta = iquod2.t_metadata() + s_meta = iquod2.s_metadata() + df_t_meta = iquod2.df().attrs['t_metadata'] + df_s_meta = iquod2.df().attrs['s_metadata'] + np_t_meta = iquod2.npdict()['t_metadata'] + np_s_meta = iquod2.npdict()['s_metadata'] + + assert numpy.array_equal(truth_t, t_meta), "temperature metadata should have been [{'code': 3, 'value': 102.0, 'iMeta': 0}, {'code': 5, 'value': 411.0, 'iMeta': 0}], instead read %s" % t_meta.__str__() + assert numpy.array_equal(truth_s, s_meta), "salinity metadata should have been [{'code': 3, 'value': 202.0, 'iMeta': 0}, {'code': 5, 'value': 411.0, 'iMeta': 0}], instead read %s" % s_meta.__str__() + assert numpy.array_equal(truth_t, df_t_meta), "dataframe temperature metadata should have been [{'code': 3, 'value': 102.0, 'iMeta': 0}, {'code': 5, 'value': 411.0, 'iMeta': 0}], instead read %s" % df_t_meta.__str__() + assert numpy.array_equal(truth_s, df_s_meta), "dataframe salinity metadata should have been [{'code': 3, 'value': 202.0, 'iMeta': 0}, {'code': 5, 'value': 411.0, 'iMeta': 0}], instead read %s" % df_s_meta.__str__() + assert numpy.array_equal(truth_t, np_t_meta), "dict temperature metadata should have been [{'code': 3, 'value': 102.0, 'iMeta': 0}, {'code': 5, 'value': 411.0, 'iMeta': 0}], instead read %s" % np_t_meta.__str__() + assert numpy.array_equal(truth_s, np_s_meta), "dict salinity metadata should have been [{'code': 3, 'value': 202.0, 'iMeta': 0}, {'code': 5, 'value': 411.0, 'iMeta': 0}], instead read %s" % np_s_meta.__str__() + +def test_missing_metadata(classic1, classic2, iquod1): + ''' + make sure absent metadata doesn't cause problems + ''' + + # pre-iquod format + t_meta = classic1.t_metadata() + s_meta = classic1.s_metadata() + assert numpy.array_equal([], t_meta), 'temperature metadata should have been [], instead read %s' % t_meta.__str__() + assert numpy.array_equal([], s_meta), 'salinity metadata should have been [], instead read %s' % s_meta.__str__() + + # iquod format + t_meta = iquod1.t_metadata() + s_meta = iquod1.s_metadata() + assert numpy.array_equal([], t_meta), 'iquod temperature metadata should have been [], instead read %s' % t_meta.__str__() + assert numpy.array_equal([], s_meta), 'iquod salinity metadata should have been [], instead read %s' % s_meta.__str__() + + # pre-iquod format, with metadata (but no intelligent metadata flag) + truth_t = [{'code': 5, 'value': 4.0, 'iMeta': 0}] + t_meta = classic2.t_metadata() + assert numpy.array_equal(truth_t, t_meta), "temperature metadata should have been [{'code': 5, 'value': 4.0, 'iMeta': 0}], instead read %s" % t_meta.__str__() + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/netcdf_test.py b/tests/netcdf_test.py new file mode 100644 index 0000000..d651c30 --- /dev/null +++ b/tests/netcdf_test.py @@ -0,0 +1,149 @@ +from datetime import datetime, timedelta +from wodpy import wodnc +import numpy, math, pandas, pytest + +@pytest.fixture +def classic1(): + # example from pp 124 of http://data.nodc.noaa.gov/woa/WOD/DOC/wodreadme.pdf + # with IQuOD flags + r = wodnc.Ragged("tests/testData/ocldb1570984477.6279_OSD.nc") + return wodnc.ncProfile(r, 55) + +def test_latitude(classic1): + ''' + check latitude == 61.93 + ''' + + latitude = classic1.latitude() + assert round(latitude, 2) == 61.93, 'latitude should have been approx 61.93, instead read %f' % latitude + +def test_longitude(classic1): + ''' + check latitude == -172.270 + ''' + + longitude = classic1.longitude() + assert round(longitude, 2) == -172.270, 'longitude should have been approx -172.270, instead read %f' % latitude + +def test_uid(classic1): + ''' + check profile ID == 67064 + ''' + + uid = classic1.uid() + assert uid == 67064, 'uid should have been 67064, instead read %f' % uid + +def test_n_levels(classic1): + ''' + check the number of levels == 4 + ''' + + levels = classic1.n_levels() + assert levels == 4, 'levels should have been 4, instead read %f' % levels + +def test_year(classic1): + ''' + check year == 1934 + ''' + + year = classic1.year() + assert year == 1934, 'year should have been 1934, instead read %f' % year + +def test_month(classic1): + ''' + check month == 8 + ''' + + month = classic1.month() + assert month == 8, 'month should have been 8, instead read %f' % month + +def test_day(classic1): + ''' + check day == 7 + ''' + + day = classic1.day() + assert day == 7, 'day should have been 7, instead read %f' % day + +def test_time(classic1): + ''' + check time == 10.37 + ''' + + time = classic1.time() + assert round(time,2) == 10.37, 'time should have been 10.37, instead read %f' % time + +def test_datetime(classic1): + ''' + check datetime is close to 1934-8-7 10:22:12 + allow a 36 second (== 0.01 hour) deviation for round off error in the time + ''' + + d = classic1.datetime() + assert timedelta(seconds=-18) < (d - datetime(1934, 8, 7, 10, 22, 12)) < timedelta(seconds=18), 'time should have been close to 1934-08-07 10:22:12, instead read %s' % d + +def test_probe_type(classic1): + ''' + check probe type == 7 + ''' + + probe = classic1.probe_type() + assert probe == 7, 'probe should have been 7, instead read %f' % probe + +def test_depth(classic1): + ''' + check depths == [0.0, 10.0, 25.0, 50.0] + ''' + + truth = [0.0, 10.0, 25.0, 50.0] + truth = [numpy.float32(t) for t in truth] + z = classic1.z() + assert numpy.array_equal(z, truth), 'depths should have been [0, 10, 25, 50], instead read %s' % z.__str__() + +def test_temperature(classic1): + ''' + check temperatures == [8.960, 8.950, 0.900, -1.230] + ''' + + truth = [8.960, 8.950, 0.900, -1.230] + truth = [numpy.float32(t) for t in truth] + t = classic1.t() + assert numpy.array_equal(t, truth), 'temperatures should have been [8.96, 8.95, 0.9, -1.23], instead read %s' % t.__str__() + +def test_salinity(classic1): + ''' + check salinities == [30.900, 30.900, 31.910, 32.410] + ''' + + truth = [30.900, 30.900, 31.910, 32.410] + truth = [numpy.float32(t) for t in truth] + s = classic1.s() + assert numpy.array_equal(s, truth), 'salinities should have been [30.9, 30.9, 31.91, 32.41], instead read %s' % s.__str__() + +def test_oxygen(classic1): + truth = [293.90298, 291.90366, 375.3761, 317.39523] + truth = [numpy.float32(t) for t in truth] + s = classic1.oxygen() + assert numpy.array_equal(s, truth), 'dissolved oxygen should have been [293.90298, 291.90366, 375.3761, 317.39523], instead read %s' % s.__str__() + +def test_phosphate(classic1): + truth = [0.63, 0.69, 0.88, 1.14] + truth = [numpy.float32(t) for t in truth] + s = classic1.phosphate() + assert numpy.array_equal(s, truth), 'phosphate should have been [0.63, 0.69, 0.88, 1.14], instead read %s' % s.__str__() + +def test_silicate(classic1): + truth = [20, 12, 15, 25] + truth = [numpy.float32(t) for t in truth] + s = classic1.silicate() + assert numpy.array_equal(s, truth), 'silicate should have been [20, 12, 15, 25], instead read %s' % s.__str__() + +def test_pH(classic1): + truth = [8.100, 8.100, 8.100, 8.050] + truth = [numpy.float32(t) for t in truth] + s = classic1.pH() + assert numpy.array_equal(s, truth), 'pH should have been [8.100, 8.100, 8.100, 8.050], instead read %s' % s.__str__() + + + + diff --git a/tests/netcdf_tests.py b/tests/netcdf_tests.py deleted file mode 100644 index 1f65ed8..0000000 --- a/tests/netcdf_tests.py +++ /dev/null @@ -1,151 +0,0 @@ -from datetime import datetime, timedelta -from wodpy import wodnc -import numpy, math, pandas - -class TestClass(): - def setUp(self): - - # example from pp 124 of http://data.nodc.noaa.gov/woa/WOD/DOC/wodreadme.pdf - # with IQuOD flags - r = wodnc.Ragged("tests/testData/ocldb1570984477.6279_OSD.nc") - self.classic1 = wodnc.ncProfile(r, 55) - - return - - def tearDown(self): - return - - def test_latitude(self): - ''' - check latitude == 61.93 - ''' - - latitude = self.classic1.latitude() - assert round(latitude, 2) == 61.93, 'latitude should have been approx 61.93, instead read %f' % latitude - - def test_longitude(self): - ''' - check latitude == -172.270 - ''' - - longitude = self.classic1.longitude() - assert round(longitude, 2) == -172.270, 'longitude should have been approx -172.270, instead read %f' % latitude - - def test_uid(self): - ''' - check profile ID == 67064 - ''' - - uid = self.classic1.uid() - assert uid == 67064, 'uid should have been 67064, instead read %f' % uid - - def test_n_levels(self): - ''' - check the number of levels == 4 - ''' - - levels = self.classic1.n_levels() - assert levels == 4, 'levels should have been 4, instead read %f' % levels - - def test_year(self): - ''' - check year == 1934 - ''' - - year = self.classic1.year() - assert year == 1934, 'year should have been 1934, instead read %f' % year - - def test_month(self): - ''' - check month == 8 - ''' - - month = self.classic1.month() - assert month == 8, 'month should have been 8, instead read %f' % month - - def test_day(self): - ''' - check day == 7 - ''' - - day = self.classic1.day() - assert day == 7, 'day should have been 7, instead read %f' % day - - def test_time(self): - ''' - check time == 10.37 - ''' - - time = self.classic1.time() - assert round(time,2) == 10.37, 'time should have been 10.37, instead read %f' % time - - def test_datetime(self): - ''' - check datetime is close to 1934-8-7 10:22:12 - allow a 36 second (== 0.01 hour) deviation for round off error in the time - ''' - - d = self.classic1.datetime() - assert timedelta(seconds=-18) < (d - datetime(1934, 8, 7, 10, 22, 12)) < timedelta(seconds=18), 'time should have been close to 1934-08-07 10:22:12, instead read %s' % d - - def test_probe_type(self): - ''' - check probe type == 7 - ''' - - probe = self.classic1.probe_type() - assert probe == 7, 'probe should have been 7, instead read %f' % probe - - def test_depth(self): - ''' - check depths == [0.0, 10.0, 25.0, 50.0] - ''' - - truth = [0.0, 10.0, 25.0, 50.0] - truth = [numpy.float32(t) for t in truth] - z = self.classic1.z() - assert numpy.array_equal(z, truth), 'depths should have been [0, 10, 25, 50], instead read %s' % z.__str__() - - def test_temperature(self): - ''' - check temperatures == [8.960, 8.950, 0.900, -1.230] - ''' - - truth = [8.960, 8.950, 0.900, -1.230] - truth = [numpy.float32(t) for t in truth] - t = self.classic1.t() - assert numpy.array_equal(t, truth), 'temperatures should have been [8.96, 8.95, 0.9, -1.23], instead read %s' % t.__str__() - - def test_salinity(self): - ''' - check salinities == [30.900, 30.900, 31.910, 32.410] - ''' - - truth = [30.900, 30.900, 31.910, 32.410] - truth = [numpy.float32(t) for t in truth] - s = self.classic1.s() - assert numpy.array_equal(s, truth), 'salinities should have been [30.9, 30.9, 31.91, 32.41], instead read %s' % s.__str__() - - def test_oxygen(self): - truth = [293.90298, 291.90366, 375.3761, 317.39523] - truth = [numpy.float32(t) for t in truth] - s = self.classic1.oxygen() - assert numpy.array_equal(s, truth), 'dissolved oxygen should have been [293.90298, 291.90366, 375.3761, 317.39523], instead read %s' % s.__str__() - - def test_phosphate(self): - truth = [0.63, 0.69, 0.88, 1.14] - truth = [numpy.float32(t) for t in truth] - s = self.classic1.phosphate() - assert numpy.array_equal(s, truth), 'phosphate should have been [0.63, 0.69, 0.88, 1.14], instead read %s' % s.__str__() - - def test_silicate(self): - truth = [20, 12, 15, 25] - truth = [numpy.float32(t) for t in truth] - s = self.classic1.silicate() - assert numpy.array_equal(s, truth), 'silicate should have been [20, 12, 15, 25], instead read %s' % s.__str__() - - def test_pH(self): - truth = [8.100, 8.100, 8.100, 8.050] - truth = [numpy.float32(t) for t in truth] - s = self.classic1.pH() - assert numpy.array_equal(s, truth), 'pH should have been [8.100, 8.100, 8.100, 8.050], instead read %s' % s.__str__() \ No newline at end of file diff --git a/tests/test_cotede.py b/tests/test_cotede.py index c92fffc..3d08608 100644 --- a/tests/test_cotede.py +++ b/tests/test_cotede.py @@ -1,175 +1,168 @@ from datetime import datetime, timedelta from wodpy import wod, wodnc from wodpy.extra import Wod4CoTeDe -import numpy - -class TestClass(): - def setUp(self): - - #create an artificial profile to trigger the temperature flag - #sets first temperature to 99.9; otherwise identical to data/example.dat - file = open("tests/testData/classic.dat") - self.demoProfile = Wod4CoTeDe(file) - - ragged = wodnc.Ragged("tests/testData/ocldb1570984477.6279_OSD.nc") - self.demonetCDF = Wod4CoTeDe(ragged, 55) - return - - # =================================================================== - # check the example from pp 137 of - # http://data.nodc.noaa.gov/woa/WOD/DOC/wodreadme.pdf - # is extracted correctly by base functions. - # data is in `example.dat` +import numpy, pytest + +@pytest.fixture +def demoProfile(): + # WOD13 format data + file = open("tests/testData/classic.dat") + return Wod4CoTeDe(file) + +@pytest.fixture +def demonetCDF(): + ragged = wodnc.Ragged("tests/testData/ocldb1570984477.6279_OSD.nc") + return Wod4CoTeDe(ragged, 55) + +def test_latitude(demoProfile, demonetCDF): + ''' + check latitude == 61.930 + ''' + + latitude = demoProfile.attributes['LATITUDE'] + nclatitude = demonetCDF.attributes['LATITUDE'] + assert latitude == 61.930, 'latitude should have been 61.930, instead read %f' % latitude + assert round(nclatitude, 2) == 61.93, 'latitude should have been about 61.93, instead read %f' % nclatitude + +def test_longitude(demoProfile, demonetCDF): + ''' + check longitude == -172.270 + ''' + + longitude = demoProfile.attributes['LONGITUDE'] + nclongitude = demonetCDF.attributes['LONGITUDE'] + assert longitude == -172.270, 'longitude should have been -172.270, instead read %f' % longitude + assert round(nclongitude, 2) == -172.27, 'longitude should have been about -172.270, instead read %f' % nclongitude + +def test_uid(demoProfile, demonetCDF): + ''' + check cruise ID == 67064 + ''' + + uid = demoProfile.attributes['uid'] + ncuid = demonetCDF.attributes['uid'] + assert uid == 67064, 'uid should have been 67064, instead read %f' % uid + assert ncuid == 67064, 'uid should have been 67064, instead read %f' % ncuid + +def test_n_levels(demoProfile, demonetCDF): + ''' + check the number of levels == 4 + ''' + + levels = demoProfile.attributes['n_levels'] + nclevels = demonetCDF.attributes['n_levels'] + assert levels == 4, 'levels should have been 4, instead read %f' % levels + assert nclevels == 4, 'levels should have been 4, instead read %f' % nclevels + +def test_datetime(demoProfile, demonetCDF): + ''' + check datetime == 1934-08-07 10:22:12 + ''' + + truth = datetime(1934, 8, 7, 10, 22, 12) + time = demoProfile.attributes['datetime'] + nctime = demonetCDF.attributes['datetime'] + assert time - truth < timedelta(minutes=1), 'time should have been about 1934-08-07 10:22:12, instead read %s' % time + assert nctime - truth < timedelta(minutes=1), 'time should have been about 1934-08-07 10:22:12, instead read %s' % nctime + + +def test_probe_type(demoProfile, demonetCDF): + ''' + check probe type == 7 (bottle/rossete/net) + ''' + + probe = demoProfile.attributes['probe_type'] + ncprobe = demonetCDF.attributes['probe_type'] + assert probe == 'bottle/rossete/net', 'probe should have been , instead read %s' % probe + assert ncprobe == 'bottle/rossete/net', 'probe should have been , instead read %s' % ncprobe + + +def test_depth(demoProfile, demonetCDF): + ''' + check depths == [0.0, 10.0, 25.0, 50.0] + ''' + + truth = [0.0, 10.0, 25.0, 50.0] + z = demoProfile['DEPTH'] + ncz = demonetCDF['DEPTH'] + assert numpy.array_equal(z, truth), 'depths should have been [0, 10, 25, 50], instead read %s' % z.__str__() + assert numpy.array_equal(ncz, truth), 'depths should have been [0, 10, 25, 50], instead read %s' % ncz.__str__() + + +def test_temperature(demoProfile, demonetCDF): + ''' + check temperatures == [8.960, 8.950, 0.900, -1.230] + ''' + + truth = [8.960, 8.950, 0.900, -1.230] + t = [round(float(x),2) for x in demoProfile['TEMP']] + nct = [round(float(x),2) for x in demonetCDF['TEMP']] + assert numpy.array_equal(t, truth), 'temperatures should have been [8.96, 8.95, 0.9, -1.23], instead read %s' % t.__str__() + assert numpy.array_equal(nct, truth), 'temperatures should have been [8.96, 8.95, 0.9, -1.23], instead read %s' % nct.__str__() + + +def test_salinity(demoProfile, demonetCDF): + ''' + check salinities == [30.900, 30.900, 31.910, 32.410] + ''' - def test_latitude(self): - ''' - check latitude == 61.930 - ''' - - latitude = self.demoProfile.attributes['LATITUDE'] - nclatitude = self.demonetCDF.attributes['LATITUDE'] - assert latitude == 61.930, 'latitude should have been 61.930, instead read %f' % latitude - assert round(nclatitude, 2) == 61.93, 'latitude should have been about 61.93, instead read %f' % nclatitude - - def test_longitude(self): - ''' - check longitude == -172.270 - ''' - - longitude = self.demoProfile.attributes['LONGITUDE'] - nclongitude = self.demonetCDF.attributes['LONGITUDE'] - assert longitude == -172.270, 'longitude should have been -172.270, instead read %f' % longitude - assert round(nclongitude, 2) == -172.27, 'longitude should have been about -172.270, instead read %f' % nclongitude - - def test_uid(self): - ''' - check cruise ID == 67064 - ''' - - uid = self.demoProfile.attributes['uid'] - ncuid = self.demonetCDF.attributes['uid'] - assert uid == 67064, 'uid should have been 67064, instead read %f' % uid - assert ncuid == 67064, 'uid should have been 67064, instead read %f' % ncuid - - def test_n_levels(self): - ''' - check the number of levels == 4 - ''' - - levels = self.demoProfile.attributes['n_levels'] - nclevels = self.demonetCDF.attributes['n_levels'] - assert levels == 4, 'levels should have been 4, instead read %f' % levels - assert nclevels == 4, 'levels should have been 4, instead read %f' % nclevels - - def test_datetime(self): - ''' - check datetime == 1934-08-07 10:22:12 - ''' - - truth = datetime(1934, 8, 7, 10, 22, 12) - time = self.demoProfile.attributes['datetime'] - nctime = self.demonetCDF.attributes['datetime'] - assert time - truth < timedelta(minutes=1), 'time should have been about 1934-08-07 10:22:12, instead read %s' % time - assert nctime - truth < timedelta(minutes=1), 'time should have been about 1934-08-07 10:22:12, instead read %s' % nctime - - - def test_probe_type(self): - ''' - check probe type == 7 (bottle/rossete/net) - ''' - - probe = self.demoProfile.attributes['probe_type'] - ncprobe = self.demonetCDF.attributes['probe_type'] - assert probe == 'bottle/rossete/net', 'probe should have been , instead read %s' % probe - assert ncprobe == 'bottle/rossete/net', 'probe should have been , instead read %s' % ncprobe - - - def test_depth(self): - ''' - check depths == [0.0, 10.0, 25.0, 50.0] - ''' - - truth = [0.0, 10.0, 25.0, 50.0] - z = self.demoProfile['DEPTH'] - ncz = self.demonetCDF['DEPTH'] - assert numpy.array_equal(z, truth), 'depths should have been [0, 10, 25, 50], instead read %s' % z.__str__() - assert numpy.array_equal(ncz, truth), 'depths should have been [0, 10, 25, 50], instead read %s' % ncz.__str__() - - - def test_temperature(self): - ''' - check temperatures == [8.960, 8.950, 0.900, -1.230] - ''' - - truth = [8.960, 8.950, 0.900, -1.230] - t = [round(float(x),2) for x in self.demoProfile['TEMP']] - nct = [round(float(x),2) for x in self.demonetCDF['TEMP']] - assert numpy.array_equal(t, truth), 'temperatures should have been [8.96, 8.95, 0.9, -1.23], instead read %s' % t.__str__() - assert numpy.array_equal(nct, truth), 'temperatures should have been [8.96, 8.95, 0.9, -1.23], instead read %s' % nct.__str__() - - - def test_salinity(self): - ''' - check salinities == [30.900, 30.900, 31.910, 32.410] - ''' - - truth = [30.900, 30.900, 31.910, 32.410] - s = [round(float(x),2) for x in self.demoProfile['PSAL']] - ncs = [round(float(x),2) for x in self.demonetCDF['PSAL']] - assert numpy.array_equal(s, truth), 'salinities should have been [30.9, 30.9, 31.91, 32.41], instead read %s' % s.__str__() - assert numpy.array_equal(ncs, truth), 'salinities should have been [30.9, 30.9, 31.91, 32.41], instead read %s' % ncs.__str__() - - def test_oxygen(self): - ''' - check oxygen levels = [6.750, 6.700, 8.620, 7.280] - ''' - - truth = [6.750, 6.700, 8.620, 7.280] - truth_nc = [293.90298, 291.90366, 375.3761, 317.39523] - o2 = [round(float(x),2) for x in self.demoProfile['oxygen']] - nco2 = [round(float(x),5) for x in self.demonetCDF['oxygen']] - assert numpy.array_equal(o2, truth), 'oxygen levels should have been [6.750, 6.700, 8.620, 7.280], instead read %s' % o2.__str__() - assert numpy.array_equal(nco2, truth_nc), 'oxygen levels should have been [293.90298, 291.90366, 375.3761, 317.39523], instead read %s' % nco2.__str__() - - - def test_phosphate(self): - ''' - check phosphate levels = [0.650, 0.710, 0.900, 1.170] - ''' - - truth = [0.650, 0.710, 0.900, 1.170] - truth_nc = [0.63, 0.69, 0.88, 1.14] - phos = self.demoProfile['phosphate'] - phos = [round(float(x),2) for x in self.demoProfile['phosphate']] - ncphos = [round(float(x),2) for x in self.demonetCDF['phosphate']] - assert numpy.array_equal(phos, truth), 'phosphate levels should have been [0.650, 0.710, 0.900, 1.170], instead read %s' % phos.__str__() - assert numpy.array_equal(ncphos, truth_nc), 'phosphate levels should have been [0.63, 0.69, 0.88, 1.14], instead read %s' % ncphos.__str__() - - - def test_silicate(self): - ''' - check silicate levels = [20.500, 12.300, 15.400, 25.600] - ''' - - truth = [20.500, 12.300, 15.400, 25.600] - truth_nc = [20, 12, 15, 25] - sili = [round(float(x),2) for x in self.demoProfile['silicate']] - ncsili = [round(float(x),2) for x in self.demonetCDF['silicate']] - assert numpy.array_equal(sili, truth), 'silicate levels should have been [20.500, 12.300, 15.400, 25.600], instead read %s' % sili.__str__() - assert numpy.array_equal(ncsili, truth_nc), 'silicate levels should have been [20, 12, 15, 25], instead read %s' % ncsili.__str__() - - - def test_pH(self): - ''' - check pH levels = [8.100, 8.100, 8.100, 8.050] - ''' - - truth = [8.100, 8.100, 8.100, 8.050] - pH = self.demoProfile['pH'] - pH = [round(float(x),2) for x in self.demoProfile['pH']] - ncpH = [round(float(x),2) for x in self.demonetCDF['pH']] - assert numpy.array_equal(pH, truth), 'pH levels should have been [8.100, 8.100, 8.100, 8.050], instead read %s' % pH.__str__() - assert numpy.array_equal(ncpH, truth), 'pH levels should have been [8.100, 8.100, 8.100, 8.050], instead read %s' % ncpH.__str__() + truth = [30.900, 30.900, 31.910, 32.410] + s = [round(float(x),2) for x in demoProfile['PSAL']] + ncs = [round(float(x),2) for x in demonetCDF['PSAL']] + assert numpy.array_equal(s, truth), 'salinities should have been [30.9, 30.9, 31.91, 32.41], instead read %s' % s.__str__() + assert numpy.array_equal(ncs, truth), 'salinities should have been [30.9, 30.9, 31.91, 32.41], instead read %s' % ncs.__str__() + +def test_oxygen(demoProfile, demonetCDF): + ''' + check oxygen levels = [6.750, 6.700, 8.620, 7.280] + ''' + + truth = [6.750, 6.700, 8.620, 7.280] + truth_nc = [293.90298, 291.90366, 375.3761, 317.39523] + o2 = [round(float(x),2) for x in demoProfile['oxygen']] + nco2 = [round(float(x),5) for x in demonetCDF['oxygen']] + assert numpy.array_equal(o2, truth), 'oxygen levels should have been [6.750, 6.700, 8.620, 7.280], instead read %s' % o2.__str__() + assert numpy.array_equal(nco2, truth_nc), 'oxygen levels should have been [293.90298, 291.90366, 375.3761, 317.39523], instead read %s' % nco2.__str__() + + +def test_phosphate(demoProfile, demonetCDF): + ''' + check phosphate levels = [0.650, 0.710, 0.900, 1.170] + ''' + + truth = [0.650, 0.710, 0.900, 1.170] + truth_nc = [0.63, 0.69, 0.88, 1.14] + phos = demoProfile['phosphate'] + phos = [round(float(x),2) for x in demoProfile['phosphate']] + ncphos = [round(float(x),2) for x in demonetCDF['phosphate']] + assert numpy.array_equal(phos, truth), 'phosphate levels should have been [0.650, 0.710, 0.900, 1.170], instead read %s' % phos.__str__() + assert numpy.array_equal(ncphos, truth_nc), 'phosphate levels should have been [0.63, 0.69, 0.88, 1.14], instead read %s' % ncphos.__str__() + + +def test_silicate(demoProfile, demonetCDF): + ''' + check silicate levels = [20.500, 12.300, 15.400, 25.600] + ''' + + truth = [20.500, 12.300, 15.400, 25.600] + truth_nc = [20, 12, 15, 25] + sili = [round(float(x),2) for x in demoProfile['silicate']] + ncsili = [round(float(x),2) for x in demonetCDF['silicate']] + assert numpy.array_equal(sili, truth), 'silicate levels should have been [20.500, 12.300, 15.400, 25.600], instead read %s' % sili.__str__() + assert numpy.array_equal(ncsili, truth_nc), 'silicate levels should have been [20, 12, 15, 25], instead read %s' % ncsili.__str__() + + +def test_pH(demoProfile, demonetCDF): + ''' + check pH levels = [8.100, 8.100, 8.100, 8.050] + ''' + + truth = [8.100, 8.100, 8.100, 8.050] + pH = demoProfile['pH'] + pH = [round(float(x),2) for x in demoProfile['pH']] + ncpH = [round(float(x),2) for x in demonetCDF['pH']] + assert numpy.array_equal(pH, truth), 'pH levels should have been [8.100, 8.100, 8.100, 8.050], instead read %s' % pH.__str__() + assert numpy.array_equal(ncpH, truth), 'pH levels should have been [8.100, 8.100, 8.100, 8.050], instead read %s' % ncpH.__str__() diff --git a/tests/tests.py b/tests/tests.py deleted file mode 100644 index 7c01701..0000000 --- a/tests/tests.py +++ /dev/null @@ -1,697 +0,0 @@ -from datetime import datetime -from wodpy import wod -import numpy, math, pandas - -class TestClass(): - def setUp(self): - - # WOD13 format data - classic = open("tests/testData/classic.dat") - # example from pp 124 of http://data.nodc.noaa.gov/woa/WOD/DOC/wodreadme.pdf - self.classic1 = wod.WodProfile(classic) - self.classic1_df = self.classic1.df() - self.classic1_dict = self.classic1.npdict() - self.classic1_head = self.classic1.header() - # example with missing salinity information - self.classic2 = wod.WodProfile(classic) - - # IQuOD 0.1 format data - # short example (unpacked by hand to validate) - iquod = open("tests/testData/iquod.dat") - self.iquod1 = wod.WodProfile(iquod) - self.iquod1_df = self.iquod1.df() - self.iquod1_dict = self.iquod1.npdict() - self.iquod1_head = self.iquod1.header() - # example with some metadata - self.iquod2 = wod.WodProfile(iquod) - self.iquod2_df = self.iquod2.df() - self.iquod2_dict = self.iquod2.npdict() - - # data with some interesting pathologies - path = open("tests/testData/pathological.dat") - self.path1 = wod.WodProfile(path) - self.path1_df = self.path1.df() - self.path1_dict = self.path1.npdict() - self.path1_head = self.path1.header() - - return - - def tearDown(self): - return - - # =================================================================== - # check the example from pp 124 of - # http://data.nodc.noaa.gov/woa/WOD/DOC/wodreadme.pdf - # is extracted correctly by base functions. - # data is in `data/classic.dat` - - def test_latitude(self): - ''' - check latitude == 61.930 - ''' - - latitude = self.classic1.latitude() - df_latitude = self.classic1_df.attrs['latitude'] - np_latitude = self.classic1_dict['latitude'] - header_latitude = self.classic1_head.latitude - assert latitude == 61.930, 'latitude should have been 61.930, instead read %f' % latitude - assert df_latitude == 61.930, 'dataframe latitude should have been 61.930, instead read %f' % df_latitude - assert np_latitude == 61.930, 'np dict latitude should have been 61.930, instead read %f' % np_latitude - assert header_latitude == 61.930, 'header latitude should have been 61.930, instead read %f' % header_latitude - - def test_latitude_error(self): - ''' - check latitude error is None - ''' - - latitude_unc = self.classic1.latitude_unc() - df_latitude_unc = self.classic1_df.attrs['latitude_unc'] - np_latitude_unc = self.classic1_dict['latitude_unc'] - header_latitude_unc = self.classic1_head.latitude_unc - assert latitude_unc is None, 'latitude error is undefined for this profile, instead read %f' % latitude_unc - assert df_latitude_unc is None, 'dataframe latitude error is undefined for this profile, instead read %f' % df_latitude_unc - assert np_latitude_unc is None, 'npdict latitude error is undefined for this profile, instead read %f' % np_latitude_unc - assert math.isnan(header_latitude_unc) , 'header latitude error is undefined for this profile, instead read %f' % header_latitude_unc - - def test_longitude(self): - ''' - check longitude == -172.270 - ''' - - longitude = self.classic1.longitude() - df_longitude = self.classic1_df.attrs['longitude'] - np_longitude = self.classic1_dict['longitude'] - header_longitude = self.classic1_head.longitude - assert longitude == -172.270, 'longitude should have been -172.270, instead read %f' % longitude - assert df_longitude == -172.270, 'dataframe longitude should have been -172.270, instead read %f' % df_longitude - assert np_longitude == -172.270, 'np dict longitude should have been -172.270, instead read %f' % np_longitude - assert header_longitude == -172.270, 'header longitude should have been -172.270, instead read %f' % header_longitude - - def test_longitude_error(self): - ''' - check longitude error is None - ''' - - longitude_unc = self.classic1.longitude_unc() - df_longitude_unc = self.classic1_df.attrs['longitude_unc'] - np_longitude_unc = self.classic1_dict['longitude_unc'] - header_longitude_unc = self.classic1_head.longitude_unc - assert longitude_unc is None, 'longitude error is undefined for this profile, instead read %f' % longitude_unc - assert df_longitude_unc is None, 'dataframe longitude error is undefined for this profile, instead read %f' % df_longitude_unc - assert np_longitude_unc is None, 'np dict longitude error is undefined for this profile, instead read %f' % np_longitude_unc - assert math.isnan(header_longitude_unc), 'header longitude error is undefined for this profile, instead read %f' % header_longitude_unc - - def test_uid(self): - ''' - check profile ID == 67064 - ''' - - uid = self.classic1.uid() - df_uid = self.classic1_df.attrs['uid'] - np_uid = self.classic1_dict['uid'] - header_uid = self.classic1_head.uid - assert uid == 67064, 'uid should have been 67064, instead read %f' % uid - assert df_uid == 67064, 'dataframe uid should have been 67064, instead read %f' % df_uid - assert np_uid == 67064, 'np dict uid should have been 67064, instead read %f' % np_uid - assert header_uid == 67064, 'header uid should have been 67064, instead read %f' % header_uid - - def test_n_levels(self): - ''' - check the number of levels == 4 - ''' - - levels = self.classic1.n_levels() - df_levels = self.classic1_df.attrs['n_levels'] - np_levels = self.classic1_dict['n_levels'] - header_n_levels = self.classic1_head.n_levels - assert levels == 4, 'levels should have been 4, instead read %f' % levels - assert df_levels == 4, 'dataframe levels should have been 4, instead read %f' % df_levels - assert np_levels == 4, 'np dict levels should have been 4, instead read %f' % np_levels - assert header_n_levels == 4, 'header levels should have been 4, instead read %f' % header_levels - - def test_year(self): - ''' - check year == 1934 - ''' - - year = self.classic1.year() - df_year = self.classic1_df.attrs['year'] - np_year = self.classic1_dict['year'] - header_year = self.classic1_head.year - assert year == 1934, 'year should have been 1934, instead read %f' % year - assert df_year == 1934, 'dataframe year should have been 1934, instead read %f' % df_year - assert np_year == 1934, 'np dict year should have been 1934, instead read %f' % np_year - assert header_year == 1934, 'header year should have been 1934, instead read %f' % header_year - - def test_month(self): - ''' - check month == 8 - ''' - - month = self.classic1.month() - df_month = self.classic1_df.attrs['month'] - np_month = self.classic1_dict['month'] - header_month = self.classic1_head.month - assert month == 8, 'month should have been 8, instead read %f' % month - assert df_month == 8, 'dataframe month should have been 8, instead read %f' % df_month - assert np_month == 8, 'np dict month should have been 8, instead read %f' % np_month - assert header_month == 8, 'header month should have been 8, instead read %f' % header_month - - - def test_day(self): - ''' - check day == 7 - ''' - - day = self.classic1.day() - df_day = self.classic1_df.attrs['day'] - np_day = self.classic1_dict['day'] - header_day = self.classic1_head.day - assert day == 7, 'day should have been 7, instead read %f' % day - assert df_day == 7, 'dataframe day should have been 7, instead read %f' % df_day - assert np_day == 7, 'np dict day should have been 7, instead read %f' % np_day - assert header_day == 7, 'header day should have been 7, instead read %f' % header_day - - def test_time(self): - ''' - check time == 10.37 - ''' - - time = self.classic1.time() - df_time = self.classic1_df.attrs['time'] - np_time = self.classic1_dict['time'] - header_time = self.classic1_head.time - assert time == 10.37, 'time should have been 10.37, instead read %f' % time - assert df_time == 10.37, 'dataframe time should have been 10.37, instead read %f' % df_time - assert np_time == 10.37, 'np dict time should have been 10.37, instead read %f' % np_time - assert header_time == 10.37, 'header time should have been 10.37, instead read %f' % header_time - - - def test_datetime(self): - ''' - check datetime 1934-8-7 10:22:12 - ''' - - d = self.classic1.datetime() - assert d == datetime(1934, 8, 7, 10, 22, 12), \ - 'time should have been 1934-08-07 10:22:12, instead read %s' \ - % d - - - def test_probe_type(self): - ''' - check probe type == 7 - ''' - - probe = self.classic1.probe_type() - df_probe = self.classic1_df.attrs['probe_type'] - np_probe = self.classic1_dict['probe_type'] - header_probe = self.classic1_head.probe_type - assert probe == 7, 'probe should have been 7, instead read %f' % probe - assert df_probe == 7, 'dataframe probe should have been 7, instead read %f' % df_probe - assert np_probe == 7, 'np dict probe should have been 7, instead read %f' % np_probe - assert header_probe == 7, 'header probe should have been 7, instead read %f' % header_probe - - - def test_depth(self): - ''' - check depths == [0.0, 10.0, 25.0, 50.0] - ''' - - truth = [0.0, 10.0, 25.0, 50.0] - z = self.classic1.z() - df_z = self.classic1_df['z'] - np_z = self.classic1_dict['z'] - assert numpy.array_equal(z, truth), 'depths should have been [0, 10, 25, 50], instead read %s' % z.__str__() - assert numpy.array_equal(df_z, truth), 'dataframe depths should have been [0, 10, 25, 50], instead read %s' % df_z.tolist().__str__() - assert numpy.array_equal(np_z, truth), 'numpy dict depths should have been [0, 10, 25, 50], instead read %s' % np_z.__str__() - - def test_depth_error(self): - ''' - check depth errors == [--,--,--,--] (all masked) - ''' - - truth = numpy.ma.MaskedArray([0,0,0,0], [True, True, True, True]) - dftruth = pandas.Series(numpy.nan, index=[0,1,2,3]) - z_unc = self.classic1.z_unc() - df_z_unc = self.classic1_df['z_unc'] - np_z_unc = self.classic1_dict['z_unc'] - assert numpy.array_equal(z_unc, truth), 'depth errors should have been all masked, instead read %s' % z_unc.__str__() - assert df_z_unc.equals(dftruth), 'dataframe depth errors should have been all masked, instead read %s' % df_z_unc.__str__() - assert numpy.array_equal(np_z_unc, truth), 'numpy dict depth errors should have been all masked, instead read %s' % np_z_unc.__str__() - - def test_temperature(self): - ''' - check temperatures == [8.960, 8.950, 0.900, -1.230] - ''' - - truth = [8.960, 8.950, 0.900, -1.230] - t = self.classic1.t() - df_t = self.classic1_df['t'] - np_t = self.classic1_dict['t'] - assert numpy.array_equal(t, truth), 'temperatures should have been [8.96, 8.95, 0.9, -1.23], instead read %s' % t.__str__() - assert numpy.array_equal(df_t, truth), 'dataframe temperatures should have been [8.96, 8.95, 0.9, -1.23], instead read \n%s' % df_t.__str__() - assert numpy.array_equal(np_t, truth), 'numpy dict temperatures should have been [8.96, 8.95, 0.9, -1.23], instead read %s' % np_t.__str__() - - def test_temperature_error(self): - ''' - check temperature errors == [--,--,--,--] (all masked) - ''' - - truth = numpy.ma.MaskedArray([0,0,0,0], [True, True, True, True]) - dftruth = pandas.Series(numpy.nan, index=[0,1,2,3]) - t_unc = self.classic1.t_unc() - df_t_unc = self.classic1_df['t_unc'] - np_t_unc = self.classic1_dict['t_unc'] - - assert numpy.array_equal(t_unc, truth), 'temperature errors should have been all masked, instead read %s' % t_unc.__str__() - assert df_t_unc.equals(dftruth), 'dataframe temperature errors should have been all masked, instead read %s' % df_t_unc.__str__() - assert numpy.array_equal(np_t_unc, truth), 'numpy dict temperature errors should have been all masked, instead read %s' % np_t_unc.__str__() - - - def test_salinity(self): - ''' - check salinities == [30.900, 30.900, 31.910, 32.410] - ''' - - truth = [30.900, 30.900, 31.910, 32.410] - s = self.classic1.s() - df_s = self.classic1_df['s'] - np_s = self.classic1_dict['s'] - assert numpy.array_equal(s, truth), 'salinities should have been [30.9, 30.9, 31.91, 32.41], instead read %s' % s.__str__() - assert numpy.array_equal(df_s, truth), 'dataframe salinities should have been [30.9, 30.9, 31.91, 32.41], instead read \n%s' % df_s.__str__() - assert numpy.array_equal(np_s, truth), 'numpy dict salinities should have been [30.9, 30.9, 31.91, 32.41], instead read %s' % np_s.__str__() - - def test_salinity_error(self): - ''' - check salinity errors == [--,--,--,--] (all masked) - ''' - - truth = numpy.ma.MaskedArray([0,0,0,0], [True, True, True, True]) - dftruth = pandas.Series(numpy.nan, index=[0,1,2,3]) - s_unc = self.classic1.s_unc() - df_s_unc = self.classic1_df['s_unc'] - np_s_unc = self.classic1_dict['s_unc'] - - assert numpy.array_equal(s_unc, truth), 'salinity errors should have been all masked, instead read %s' % s_unc.__str__() - assert df_s_unc.equals(dftruth), 'dataframe salinity errors should have been all masked, instead read %s' % df_s_unc.__str__() - assert numpy.array_equal(np_s_unc, truth), 'numpy dict salinity errors should have been all masked, instead read %s' % np_s_unc.__str__() - - def test_oxygen(self): - ''' - check oxygen levels = [6.750, 6.700, 8.620, 7.280] - ''' - - truth = [6.750, 6.700, 8.620, 7.280] - o2 = self.classic1.oxygen() - df_o2 = self.classic1_df['oxygen'] - np_o2 = self.classic1_dict['oxygen'] - - assert numpy.array_equal(o2, truth), 'oxygen levels should have been [6.750, 6.700, 8.620, 7.280], instead read %s' % o2.__str__() - assert numpy.array_equal(df_o2, truth), 'dataframe oxygen levels should have been [6.750, 6.700, 8.620, 7.280], instead read \n%s' % df_o2.__str__() - assert numpy.array_equal(np_o2, truth), 'numpy dict oxygen levels should have been [6.750, 6.700, 8.620, 7.280], instead read %s' % np_o2.__str__() - - def test_phosphate(self): - ''' - check phosphate levels = [0.650, 0.710, 0.900, 1.170] - ''' - - truth = [0.650, 0.710, 0.900, 1.170] - phos = self.classic1.phosphate() - df_phos = self.classic1_df['phosphate'] - np_phos = self.classic1_dict['phosphate'] - - assert numpy.array_equal(phos, truth), 'phosphate levels should have been [0.650, 0.710, 0.900, 1.170], instead read %s' % phos.__str__() - assert numpy.array_equal(df_phos, truth), 'dataframe phosphate levels should have been [0.650, 0.710, 0.900, 1.170], instead read \n%s' % df_phos.__str__() - assert numpy.array_equal(np_phos, truth), 'numpy dict phosphate levels should have been [0.650, 0.710, 0.900, 1.170], instead read %s' % np_phos.__str__() - - def test_silicate(self): - ''' - check silicate levels = [20.500, 12.300, 15.400, 25.600] - ''' - - truth = [20.500, 12.300, 15.400, 25.600] - sili = self.classic1.silicate() - df_sili = self.classic1_df['silicate'] - np_sili = self.classic1_dict['silicate'] - - assert numpy.array_equal(sili, truth), 'silicate levels should have been [20.500, 12.300, 15.400, 25.600], instead read %s' % sili.__str__() - assert numpy.array_equal(df_sili, truth), 'dataframe silicate levels should have been [20.500, 12.300, 15.400, 25.600], instead read \n%s' % df_sili.__str__() - assert numpy.array_equal(np_sili, truth), 'numpy dict silicate levels should have been [20.500, 12.300, 15.400, 25.600], instead read %s' % np_sili.__str__() - - def test_pH(self): - ''' - check pH levels = [8.100, 8.100, 8.100, 8.050] - ''' - - truth = [8.100, 8.100, 8.100, 8.050] - pH = self.classic1.pH() - df_pH = self.classic1_df['pH'] - np_pH = self.classic1_dict['pH'] - - assert numpy.array_equal(pH, truth), 'pH levels should have been [8.100, 8.100, 8.100, 8.050], instead read %s' % pH.__str__() - assert numpy.array_equal(df_pH, truth), 'dataframe pH levels should have been [8.100, 8.100, 8.100, 8.050], instead read \n%s' % df_pH.__str__() - assert numpy.array_equal(np_pH, truth), 'numpy dict pH levels should have been [8.100, 8.100, 8.100, 8.050], instead read %s' % np_pH.__str__() - - def test_PI(self): - ''' - check for PI code - ''' - - truth = [{'Variable code': 0, 'P.I. code': 215}, {'Variable code': 0, 'P.I. code': 216}, {'Variable code': -5006, 'P.I. code': 217}, {'Variable code': -5002, 'P.I. code': 218}] - PIs = self.classic1.PIs() - df_PIs = self.classic1_df.attrs['PIs'] - np_PIs = self.classic1_dict['PIs'] - assert numpy.array_equal(PIs, truth), 'PIs should have been [{"Variable code": 0, "P.I. code": 215}, {"Variable code": 0, "P.I. code": 216}, {"Variable code": -5006, "P.I. code": 217}, {"Variable code": -5002, "P.I. code": 218}], instead read %s' % PIs.__str__() - assert numpy.array_equal(df_PIs, truth), 'dataframe PIs should have been [{"Variable code": 0, "P.I. code": 215}, {"Variable code": 0, "P.I. code": 216}, {"Variable code": -5006, "P.I. code": 217}, {"Variable code": -5002, "P.I. code": 218}], instead read \n%s' % PIs.__str__() - assert numpy.array_equal(np_PIs, truth), 'numpy dict PIs should have been [{"Variable code": 0, "P.I. code": 215}, {"Variable code": 0, "P.I. code": 216}, {"Variable code": -5006, "P.I. code": 217}, {"Variable code": -5002, "P.I. code": 218}], instead read %s' % PIs.__str__() - - def test_originator_cruise(self): - - truth = 'STOCS85A' - originator_cruise = self.classic1.originator_cruise() - df_originator_cruise = self.classic1_df.attrs['originator_cruise'] - np_originator_cruise = self.classic1_dict['originator_cruise'] - assert originator_cruise == truth, 'Originator cruise should have been STOCS85A, instead read %s' % originator_cruise - assert df_originator_cruise == truth, 'dataframe riginator cruise should have been STOCS85A, instead read %s' % df_originator_cruise - assert np_originator_cruise == truth, 'numpy dict originator cruise should have been STOCS85A, instead read %s' % np_originator_cruise - - def test_originator_station(self): - - truth = None - originator_station = self.classic1.originator_station() - df_originator_station = self.classic1_df.attrs['originator_station'] - np_originator_station = self.classic1_dict['originator_station'] - assert originator_station == truth - assert df_originator_station == truth - assert np_originator_station == truth - - # =================================================================== - # spot check another pre-iquod profile with many missing values - # data: data/classic.dat - - def test_missing_vars(self): - ''' - check that error value extraction does not fail when measured value is missing - note if a variable value is missing, wodpy assumes the error on the value will also be missing - ''' - - truth = numpy.ma.MaskedArray([0]*24, [True]*24) - s_unc = self.classic2.s_unc() - assert numpy.array_equal(s_unc, truth), 'expected salinity errors to all be missing, but got %s instead' % s_unc.__str__() - - # =================================================================== - # check that an IQuOD v 0.1 profile is unpacked correctly - # data is in `data/iquod.dat` - - def test_iquod_latitude(self): - ''' - check latitude == 34.5883 - ''' - - latitude = self.iquod1.latitude() - df_latitude = self.iquod1_df.attrs['latitude'] - np_latitude = self.iquod1_dict['latitude'] - header_latitude = self.iquod1_head.latitude - assert latitude == 34.5883, 'latitude should have been 34.5883, instead read %f' % latitude - assert df_latitude == 34.5883, 'dataframe latitude should have been 34.5883, instead read %f' % df_latitude - assert np_latitude == 34.5883, 'np dict latitude should have been 34.5883, instead read %f' % np_latitude - assert header_latitude == 34.5883, 'header latitude should have been 34.5883, instead read %f' % header_latitude - - def test_iquod_latitude_error(self): - ''' - check latitude error is None - ''' - - latitude_unc = self.iquod1.latitude_unc() - df_latitude_unc = self.iquod1_df.attrs['latitude_unc'] - np_latitude_unc = self.iquod1_dict['latitude_unc'] - header_latitude_unc = self.iquod1_head.latitude_unc - assert latitude_unc is None, 'latitude error is undefined for this profile, instead read %f' % latitude_unc - assert df_latitude_unc is None, 'dataframe latitude error is undefined for this profile, instead read %f' % df_latitude_unc - assert np_latitude_unc is None, 'npdict latitude error is undefined for this profile, instead read %f' % np_latitude_unc - assert math.isnan(header_latitude_unc) , 'header latitude error is undefined for this profile, instead read %f' % header_latitude_unc - - def test_iquod_longitude(self): - ''' - check longitude == 134.2433 - ''' - - longitude = self.iquod1.longitude() - df_longitude = self.iquod1_df.attrs['longitude'] - np_longitude = self.iquod1_dict['longitude'] - header_longitude = self.iquod1_head.longitude - assert longitude == 134.2433, 'longitude should have been 134.2433, instead read %f' % longitude - assert df_longitude == 134.2433, 'dataframe longitude should have been 134.2433, instead read %f' % df_longitude - assert np_longitude == 134.2433, 'np dict longitude should have been 134.2433, instead read %f' % np_longitude - assert header_longitude == 134.2433, 'header longitude should have been 134.2433, instead read %f' % header_longitude - - def test_iquod_longitude_error(self): - ''' - check longitude error is None - ''' - - longitude_unc = self.iquod1.longitude_unc() - df_longitude_unc = self.iquod1_df.attrs['longitude_unc'] - np_longitude_unc = self.iquod1_dict['longitude_unc'] - header_longitude_unc = self.iquod1_head.longitude_unc - assert longitude_unc is None, 'longitude error is undefined for this profile, instead read %f' % longitude_unc - assert df_longitude_unc is None, 'dataframe longitude error is undefined for this profile, instead read %f' % df_longitude_unc - assert np_longitude_unc is None, 'npdict longitude error is undefined for this profile, instead read %f' % np_longitude_unc - assert math.isnan(header_longitude_unc) , 'header longitude error is undefined for this profile, instead read %f' % header_longitude_unc - - - def test_iquod_uid(self): - ''' - check cruise ID == 13393621 - ''' - - uid = self.iquod1.uid() - df_uid = self.iquod1_df.attrs['uid'] - np_uid = self.iquod1_dict['uid'] - header_uid = self.iquod1_head.uid - assert uid == 13393621, 'uid should have been 13393621, instead read %f' % uid - assert df_uid == 13393621, 'dataframe uid should have been 13393621, instead read %f' % df_uid - assert np_uid == 13393621, 'np dict uid should have been 13393621, instead read %f' % np_uid - assert header_uid == 13393621, 'header uid should have been 13393621, instead read %f' % header_uid - - def test_iquod_n_levels(self): - ''' - check the number of levels == 5 - ''' - - levels = self.iquod1.n_levels() - df_levels = self.iquod1_df.attrs['n_levels'] - np_levels = self.iquod1_dict['n_levels'] - header_n_levels = self.iquod1_head.n_levels - assert levels == 5, 'levels should have been 5, instead read %f' % levels - assert df_levels == 5, 'dataframe levels should have been 5, instead read %f' % df_levels - assert np_levels == 5, 'np dict levels should have been 5, instead read %f' % np_levels - assert header_n_levels == 5, 'header levels should have been 5, instead read %f' % header_levels - - def test_iquod_year(self): - ''' - check year == 2000 - ''' - - year = self.iquod1.year() - df_year = self.iquod1_df.attrs['year'] - np_year = self.iquod1_dict['year'] - header_year = self.iquod1_head.year - assert year == 2000, 'year should have been 2000, instead read %f' % year - assert df_year == 2000, 'dataframe year should have been 2000, instead read %f' % df_year - assert np_year == 2000, 'np dict year should have been 2000, instead read %f' % np_year - assert header_year == 2000, 'header year should have been 2000, instead read %f' % header_year - - def test_iquod_month(self): - ''' - check month == 1 - ''' - - month = self.iquod1.month() - df_month = self.iquod1_df.attrs['month'] - np_month = self.iquod1_dict['month'] - header_month = self.iquod1_head.month - assert month == 1, 'month should have been 1, instead read %f' % month - assert df_month == 1, 'dataframe month should have been 1, instead read %f' % df_month - assert np_month == 1, 'np dict month should have been 1, instead read %f' % np_month - assert header_month == 1, 'header month should have been 1, instead read %f' % header_month - - def test_iquod_day(self): - ''' - check day == 4 - ''' - - day = self.iquod1.day() - df_day = self.iquod1_df.attrs['day'] - np_day = self.iquod1_dict['day'] - header_day = self.iquod1_head.day - assert day == 4, 'day should have been 4, instead read %f' % day - assert df_day == 4, 'dataframe day should have been 4, instead read %f' % df_day - assert np_day == 4, 'np dict day should have been 4, instead read %f' % np_day - assert header_day == 4, 'header day should have been 4, instead read %f' % header_day - - def test_iquod_time(self): - ''' - check time == 3.7 - ''' - - time = self.iquod1.time() - df_time = self.iquod1_df.attrs['time'] - np_time = self.iquod1_dict['time'] - header_time = self.iquod1_head.time - assert time == 3.7, 'time should have been 3.7, instead read %f' % time - assert df_time == 3.7, 'dataframe time should have been 3.7, instead read %f' % df_time - assert np_time == 3.7, 'np dict time should have been 3.7, instead read %f' % np_time - assert header_time == 3.7, 'header time should have been 3.7, instead read %f' % header_time - - - def test_iquod_datetime(self): - ''' - check datetime 2000-1-4 3:42:00 - ''' - - d = self.iquod1.datetime() - assert d == datetime(2000, 1, 4, 3, 42, 00), \ - 'time should have been 2000-01-04 3:42:00, instead read %s' \ - % d - - - def test_iquod_probe_type(self): - ''' - check probe type == 4 - ''' - - probe = self.iquod1.probe_type() - df_probe = self.iquod1_df.attrs['probe_type'] - np_probe = self.iquod1_dict['probe_type'] - header_probe = self.iquod1_head.probe_type - assert probe == 4, 'probe should have been 4, instead read %f' % probe - assert df_probe == 4, 'dataframe probe should have been 4, instead read %f' % df_probe - assert np_probe == 4, 'np dict probe should have been 4, instead read %f' % np_probe - assert header_probe == 4, 'header probe should have been 4, instead read %f' % header_probe - - def test_iquod_depth(self): - ''' - check depths == [0,2,5,10,20] - ''' - - truth = [0,2,5,10,20] - z = self.iquod1.z() - df_z = self.iquod1_df['z'] - np_z = self.iquod1_dict['z'] - assert numpy.array_equal(z, truth), 'depths should have been [0,2,5,10,20], instead read %s' % z.__str__() - assert numpy.array_equal(df_z, truth), 'dataframe depths should have been [0,2,5,10,20], instead read %s' % df_z.tolist().__str__() - assert numpy.array_equal(np_z, truth), 'numpy dict depths should have been [0,2,5,10,20], instead read %s' % np_z.__str__() - - def test_iquod_depth_error(self): - ''' - check depth errors == [0,.0016,.004,.008,.016] - ''' - - truth = [0,.0016,.004,.008,.016] - z_unc = self.iquod1.z_unc() - df_z_unc = self.iquod1_df['z_unc'] - np_z_unc = self.iquod1_dict['z_unc'] - assert numpy.array_equal(z_unc, truth), 'depth errors should have been [0,.0016,.004,.008,.016], instead read %s' % z_unc.__str__() - assert numpy.array_equal(df_z_unc, truth), 'dataframe depth errors should have been [0,.0016,.004,.008,.016], instead read %s' % df_z_unc.__str__() - assert numpy.array_equal(np_z_unc, truth), 'numpy dict depth errors should have been [0,.0016,.004,.008,.016], instead read %s' % np_z_unc.__str__() - - def test_iquod_temperature(self): - ''' - check temperatures == [11.1,11.2,11.0,11.0,11.0] - ''' - - truth = [11.1,11.2,11.0,11.0,11.0] - t = self.iquod1.t() - df_t = self.iquod1_df['t'] - np_t = self.iquod1_dict['t'] - assert numpy.array_equal(t, truth), 'temperatures should have been [11.1,11.2,11.0,11.0,11.0], instead read %s' % t.__str__() - assert numpy.array_equal(df_t, truth), 'dataframe temperatures should have been [11.1,11.2,11.0,11.0,11.0], instead read \n%s' % df_t.__str__() - assert numpy.array_equal(np_t, truth), 'numpy dict temperatures should have been [11.1,11.2,11.0,11.0,11.0], instead read %s' % np_t.__str__() - - def test_iquod_temperature_error(self): - ''' - check temperature errors == [.01,.01,.01,.01,.01] - ''' - - truth = [.01,.01,.01,.01,.01] - t_unc = self.iquod1.t_unc() - df_t_unc = self.iquod1_df['t_unc'] - np_t_unc = self.iquod1_dict['t_unc'] - assert numpy.array_equal(t_unc, truth), 'temperature errors should have been [.01,.01,.01,.01,.01], instead read %s' % t_unc.__str__() - assert numpy.array_equal(df_t_unc, truth), 'dataframe temperature errors should have been [.01,.01,.01,.01,.01], instead read %s' % df_t_unc.__str__() - assert numpy.array_equal(np_t_unc, truth), 'numpy dict temperature errors should have been [.01,.01,.01,.01,.01], instead read %s' % np_t_unc.__str__() - - def test_iquod_salinity(self): - ''' - check salinities == [31.53,31.47,31.49,31.49,31.50] - ''' - - truth = [31.53,31.47,31.49,31.49,31.50] - s = self.iquod1.s() - df_s = self.iquod1_df['s'] - np_s = self.iquod1_dict['s'] - assert numpy.array_equal(s, truth), 'salinities should have been [31.53,31.47,31.49,31.49,31.50], instead read %s' % s.__str__() - assert numpy.array_equal(df_s, truth), 'dataframe salinities should have been [31.53,31.47,31.49,31.49,31.50], instead read \n%s' % df_s.__str__() - assert numpy.array_equal(np_s, truth), 'numpy dict salinities should have been [31.53,31.47,31.49,31.49,31.50], instead read %s' % np_s.__str__() - - def test_iquod_salinity_error(self): - ''' - check temperature errors == [.02,.02,.02,.02,.02] - ''' - - truth = [.02,.02,.02,.02,.02] - s_unc = self.iquod1.s_unc() - df_s_unc = self.iquod1_df['s_unc'] - np_s_unc = self.iquod1_dict['s_unc'] - assert numpy.array_equal(s_unc, truth), 'salinity errors should have been [.02,.02,.02,.02,.02], instead read %s' % s_unc.__str__() - assert numpy.array_equal(df_s_unc, truth), 'dataframe salinity errors should have been [.02,.02,.02,.02,.02], instead read %s' % df_s_unc.__str__() - assert numpy.array_equal(np_s_unc, truth), 'numpy dict salinity errors should have been [.02,.02,.02,.02,.02], instead read %s' % np_s_unc.__str__() - - # metadata tests - - def test_metadata(self): - ''' - check correct unpacking of temperature and salinity metadata from iquod profile - ''' - - truth_t = [{'code': 3, 'value': 102.0, 'iMeta': 0}, {'code': 5, 'value': 411.0, 'iMeta': 0}] - truth_s = [{'code': 3, 'value': 202.0, 'iMeta': 0}, {'code': 5, 'value': 411.0, 'iMeta': 0}] - t_meta = self.iquod2.t_metadata() - s_meta = self.iquod2.s_metadata() - df_t_meta = self.iquod2_df.attrs['t_metadata'] - df_s_meta = self.iquod2_df.attrs['s_metadata'] - np_t_meta = self.iquod2_dict['t_metadata'] - np_s_meta = self.iquod2_dict['s_metadata'] - - assert numpy.array_equal(truth_t, t_meta), "temperature metadata should have been [{'code': 3, 'value': 102.0, 'iMeta': 0}, {'code': 5, 'value': 411.0, 'iMeta': 0}], instead read %s" % t_meta.__str__() - assert numpy.array_equal(truth_s, s_meta), "salinity metadata should have been [{'code': 3, 'value': 202.0, 'iMeta': 0}, {'code': 5, 'value': 411.0, 'iMeta': 0}], instead read %s" % s_meta.__str__() - assert numpy.array_equal(truth_t, df_t_meta), "dataframe temperature metadata should have been [{'code': 3, 'value': 102.0, 'iMeta': 0}, {'code': 5, 'value': 411.0, 'iMeta': 0}], instead read %s" % df_t_meta.__str__() - assert numpy.array_equal(truth_s, df_s_meta), "dataframe salinity metadata should have been [{'code': 3, 'value': 202.0, 'iMeta': 0}, {'code': 5, 'value': 411.0, 'iMeta': 0}], instead read %s" % df_s_meta.__str__() - assert numpy.array_equal(truth_t, np_t_meta), "dict temperature metadata should have been [{'code': 3, 'value': 102.0, 'iMeta': 0}, {'code': 5, 'value': 411.0, 'iMeta': 0}], instead read %s" % np_t_meta.__str__() - assert numpy.array_equal(truth_s, np_s_meta), "dict salinity metadata should have been [{'code': 3, 'value': 202.0, 'iMeta': 0}, {'code': 5, 'value': 411.0, 'iMeta': 0}], instead read %s" % np_s_meta.__str__() - - def test_missing_metadata(self): - ''' - make sure absent metadata doesn't cause problems - ''' - - # pre-iquod format - t_meta = self.classic1.t_metadata() - s_meta = self.classic1.s_metadata() - assert numpy.array_equal([], t_meta), 'temperature metadata should have been [], instead read %s' % t_meta.__str__() - assert numpy.array_equal([], s_meta), 'salinity metadata should have been [], instead read %s' % s_meta.__str__() - - # iquod format - t_meta = self.iquod1.t_metadata() - s_meta = self.iquod1.s_metadata() - assert numpy.array_equal([], t_meta), 'iquod temperature metadata should have been [], instead read %s' % t_meta.__str__() - assert numpy.array_equal([], s_meta), 'iquod salinity metadata should have been [], instead read %s' % s_meta.__str__() - - # pre-iquod format, with metadata (but no intelligent metadata flag) - truth_t = [{'code': 5, 'value': 4.0, 'iMeta': 0}] - t_meta = self.classic2.t_metadata() - assert numpy.array_equal(truth_t, t_meta), "temperature metadata should have been [{'code': 5, 'value': 4.0, 'iMeta': 0}], instead read %s" % t_meta.__str__() - - From 4e2a1022cca34e9bb4194b760155309692fa983a Mon Sep 17 00:00:00 2001 From: billmills Date: Sun, 16 Jul 2023 14:40:55 -0400 Subject: [PATCH 2/6] experimenting with gh actions --- .github/workflows/test.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..a45f669 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,16 @@ +name: unit_testing + +on: + pull_request: + branches: + - "main" + +jobs: + test: + runs-on: ubuntu-latest + container: iquod/wodpy:test-base-230716 + steps: + - name: checkout + uses: actions/checkout@v2 + - name: run_tests + run: pytest \ No newline at end of file From 1b049b60727a4a917f5875425274cf8c831420b0 Mon Sep 17 00:00:00 2001 From: billmills Date: Sun, 16 Jul 2023 14:44:24 -0400 Subject: [PATCH 3/6] attempt at pytests --- Dockerfile | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 846d676..0000000 --- a/Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM iquod/wodpy:test-base-230716 - -WORKDIR /wodpy -COPY . . -CMD pytest \ No newline at end of file From 2232dd2e36c2d998703ab6b6c054e5cf36fad53f Mon Sep 17 00:00:00 2001 From: billmills Date: Sun, 16 Jul 2023 14:47:23 -0400 Subject: [PATCH 4/6] remove travis config --- .travis.yml | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 94d80b5..0000000 --- a/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ -sudo: required - -language: python - -services: - - docker - -before_install: -- docker image pull python:3.9 - -script: -- docker image build -t wodpy:test . -- docker container run wodpy:test From 5989c1b87cbac07e092f26cfbed030fb4d38417c Mon Sep 17 00:00:00 2001 From: billmills Date: Sun, 16 Jul 2023 14:48:41 -0400 Subject: [PATCH 5/6] intentionally break tests --- tests/core_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core_test.py b/tests/core_test.py index 86b9001..eaa6b63 100644 --- a/tests/core_test.py +++ b/tests/core_test.py @@ -56,7 +56,7 @@ def test_latitude(classic1): assert latitude == 61.930, 'latitude should have been 61.930, instead read %f' % latitude assert df_latitude == 61.930, 'dataframe latitude should have been 61.930, instead read %f' % df_latitude assert np_latitude == 61.930, 'np dict latitude should have been 61.930, instead read %f' % np_latitude - assert header_latitude == 61.930, 'header latitude should have been 61.930, instead read %f' % header_latitude + assert header_latitude == 61.931, 'header latitude should have been 61.930, instead read %f' % header_latitude def test_latitude_error(classic1): ''' From 8ad8c78968e11de4f877af7eb17a33f351166f92 Mon Sep 17 00:00:00 2001 From: billmills Date: Sun, 16 Jul 2023 14:49:46 -0400 Subject: [PATCH 6/6] fix tests --- tests/core_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core_test.py b/tests/core_test.py index eaa6b63..86b9001 100644 --- a/tests/core_test.py +++ b/tests/core_test.py @@ -56,7 +56,7 @@ def test_latitude(classic1): assert latitude == 61.930, 'latitude should have been 61.930, instead read %f' % latitude assert df_latitude == 61.930, 'dataframe latitude should have been 61.930, instead read %f' % df_latitude assert np_latitude == 61.930, 'np dict latitude should have been 61.930, instead read %f' % np_latitude - assert header_latitude == 61.931, 'header latitude should have been 61.930, instead read %f' % header_latitude + assert header_latitude == 61.930, 'header latitude should have been 61.930, instead read %f' % header_latitude def test_latitude_error(classic1): '''