def test_refdatetime(self): indata = '0001-01-01 00:00:00 -05:00' vdesc = VariableDesc('x', attributes={'units': 'days since {}'.format(indata)}) actual = vdesc.refdatetime() expected = indata print_test_message('VariableDesc.refdatetime()', indata=indata, actual=actual, expected=expected) self.assertEqual(actual, expected, 'Default VariableDesc.refdatetime() not {}'.format(indata))
def test_units(self): indata = 'm' vdesc = VariableDesc('x', attributes={'units': indata}) actual = vdesc.units() expected = indata print_test_message('VariableDesc.units()', indata=indata, actual=actual, expected=expected) self.assertEqual(actual, expected, 'Default VariableDesc.units() not {}'.format(indata))
def test_unique_same_names_same_dims(self): indata = [VariableDesc('x', dimensions=[DimensionDesc('x')]), VariableDesc('x', dimensions=[DimensionDesc('x')])] actual = VariableDesc.unique(indata) expected = OrderedDict([(indata[0].name, indata[0])]) print_test_message('VariableDesc.unique()', input=indata, actual=actual, expected=expected) self.assertEqual(actual, expected, 'VariableDesc.unique failes with all-same list')
def test_cfunits(self): units = 'days' calendar = 'noleap' vdesc = VariableDesc('x', attributes={'units': units, 'calendar': calendar}) actual = vdesc.cfunits() expected = Unit(units, calendar=calendar) print_test_message('VariableDesc.cfunits()', actual=actual, expected=expected) self.assertEqual(actual, expected, 'Default VariableDesc.cfunits() not {}'.format(expected))
def test_units_default(self): vdesc = VariableDesc("x") actual = vdesc.units() expected = None print_test_message( "VariableDesc.units() == nounit", actual=actual, expected=expected ) self.assertEqual(actual, expected, "Default VariableDesc.units() not None")
def test_cfunits_default(self): vdesc = VariableDesc("time") actual = vdesc.cfunits() expected = Unit("?") print_test_message( "VariableDesc.cfunits() == None", actual=actual, expected=expected ) self.assertEqual(actual, expected, "Default VariableDesc.cfunits() not None")
def test_unique_same_names_diff_dims(self): indata = [ VariableDesc("x", dimensions=[DimensionDesc("x")]), VariableDesc("x", dimensions=[DimensionDesc("y")]), ] expected = ValueError print_test_message("VariableDesc.unique()", input=indata, expected=expected) self.assertRaises(expected, VariableDesc.unique, indata)
def test_equals_diff_dims(self): vdims1 = tuple(DimensionDesc(d) for d in ('a', 'b')) vdims2 = tuple(DimensionDesc(d) for d in ('a', 'b', 'c')) actual = VariableDesc('x', dimensions=vdims1) expected = VariableDesc('x', dimensions=vdims2) print_test_message('VariableDesc(dims1) != VariableDesc(dims2)', actual=str(actual), expected=str(expected)) self.assertNotEqual(actual, expected, 'Differently dimensioned VariableDesc objects equal')
def test_equals_diff_dtype(self): actual = VariableDesc('x', datatype='double') expected = VariableDesc('x', datatype='float') print_test_message('VariableDesc(d) != VariableDesc(f)', actual=str(actual), expected=str(expected)) self.assertNotEqual(actual, expected, 'Differently typed VariableDesc objects equal')
def test_calendar(self): indata = 'noleap' vdesc = VariableDesc('x', attributes={'units': 'days', 'calendar': indata}) actual = vdesc.calendar() expected = indata print_test_message('VariableDesc.calendar()', indata=indata, actual=actual, expected=expected) self.assertEqual(actual, expected, 'VariableDesc.calendar() not {}'.format(indata))
def test_refdatetime_default(self): vdesc = VariableDesc('x') actual = vdesc.refdatetime() expected = None print_test_message('VariableDesc.refdatetime() == None', actual=actual, expected=expected) self.assertEqual(actual, expected, 'Default VariableDesc.refdatetime() not None')
def test_cfunits_default(self): vdesc = VariableDesc('time') actual = vdesc.cfunits() expected = Unit('?') print_test_message('VariableDesc.cfunits() == None', actual=actual, expected=expected) self.assertEqual(actual, expected, 'Default VariableDesc.cfunits() not None')
def test_calendar_default(self): vdesc = VariableDesc('x') actual = vdesc.calendar() expected = None print_test_message('VariableDesc.calendar()', actual=actual, expected=expected) self.assertEqual(actual, expected, 'Default VariableDesc.calendar() not None')
def test_units_default(self): vdesc = VariableDesc('x') actual = vdesc.units() expected = None print_test_message('VariableDesc.units() == nounit', actual=actual, expected=expected) self.assertEqual(actual, expected, 'Default VariableDesc.units() not None')
def test_equals_diff_name(self): kwargs = {'datatype': 'double', 'dimensions': tuple(DimensionDesc(d) for d in ('a', 'b')), 'attributes': {'a1': 'at1', 'a2': 'at2'}, 'definition': 'y + z'} actual = VariableDesc('a', **kwargs) expected = VariableDesc('b', **kwargs) print_test_message('VariableDesc(a) != VariableDesc(b)', actual=str(actual), expected=str(expected)) self.assertNotEqual(actual, expected, 'Differently named VariableDesc objects equal')
def test_equals_same(self): kwargs = {'datatype': 'double', 'dimensions': tuple(DimensionDesc(d) for d in ('a', 'b')), 'attributes': {'a1': 'at1', 'a2': 'at2'}, 'definition': 'y + z'} actual = VariableDesc('x', **kwargs) expected = VariableDesc('x', **kwargs) print_test_message('VariableDesc == VariableDesc', actual=str(actual), expected=str(expected)) self.assertEqual(actual, expected, 'Identical VariableDesc objects not equal')
def test_unique_diff_names(self): indata = [VariableDesc('x'), VariableDesc('y')] actual = VariableDesc.unique(indata) expected = OrderedDict((d.name, d) for d in indata) print_test_message('VariableDesc.unique()', input=indata, actual=actual, expected=expected) self.assertEqual(actual, expected, 'VariableDesc.unique failes with all-same list')
def test_unique_same_names(self): indata = [VariableDesc("x"), VariableDesc("x")] actual = VariableDesc.unique(indata) expected = OrderedDict([(indata[0].name, indata[0])]) print_test_message( "VariableDesc.unique()", input=indata, actual=actual, expected=expected ) self.assertEqual( actual, expected, "VariableDesc.unique failes with all-same list" )
def test_unique_single(self): indata = [VariableDesc("x")] actual = VariableDesc.unique(indata) expected = OrderedDict((d.name, d) for d in indata) print_test_message( "VariableDesc.unique()", input=indata, actual=actual, expected=expected ) self.assertEqual( actual, expected, "VariableDesc.unique failes with single-item list" )
def test_cfunits(self): units = "days" calendar = "noleap" vdesc = VariableDesc("x", attributes={"units": units, "calendar": calendar}) actual = vdesc.cfunits() expected = Unit(units, calendar=calendar) print_test_message("VariableDesc.cfunits()", actual=actual, expected=expected) self.assertEqual( actual, expected, "Default VariableDesc.cfunits() not {}".format(expected) )
def test_units(self): indata = "m" vdesc = VariableDesc("x", attributes={"units": indata}) actual = vdesc.units() expected = indata print_test_message( "VariableDesc.units()", indata=indata, actual=actual, expected=expected ) self.assertEqual( actual, expected, "Default VariableDesc.units() not {}".format(indata) )
def test_equals_diff_dtype(self): actual = VariableDesc("x", datatype="double") expected = VariableDesc("x", datatype="float") print_test_message( "VariableDesc(d) != VariableDesc(f)", actual=str(actual), expected=str(expected), ) self.assertNotEqual( actual, expected, "Differently typed VariableDesc objects equal" )
def test_calendar(self): indata = "noleap" vdesc = VariableDesc("x", attributes={"units": "days", "calendar": indata}) actual = vdesc.calendar() expected = indata print_test_message( "VariableDesc.calendar()", indata=indata, actual=actual, expected=expected ) self.assertEqual( actual, expected, "VariableDesc.calendar() not {}".format(indata) )
def test_autoparse_time_variable_hidden(self): indata = (VariableDesc('a'), VariableDesc('b'), VariableDesc('_t')) fdesc = FileDesc('test.nc', variables=indata, autoparse_time_variable='_t') actual = fdesc.variables expected = OrderedDict((d.name, d) for d in indata) print_test_message('FileDesc.variables', input=indata, actual=actual, expected=expected) self.assertEqual(actual, expected, 'FileDesc.variables failed') actual = fdesc.dimensions expected = OrderedDict() print_test_message('FileDesc.dimensions', input=indata, actual=actual, expected=expected) self.assertEqual(actual, expected, 'FileDesc.dimensions failed')
def test_equals_same(self): kwargs = { "datatype": "double", "dimensions": tuple(DimensionDesc(d) for d in ("a", "b")), "attributes": {"a1": "at1", "a2": "at2"}, "definition": "y + z", } actual = VariableDesc("x", **kwargs) expected = VariableDesc("x", **kwargs) print_test_message( "VariableDesc == VariableDesc", actual=str(actual), expected=str(expected) ) self.assertEqual(actual, expected, "Identical VariableDesc objects not equal")
def test_equals_diff_dims(self): vdims1 = tuple(DimensionDesc(d) for d in ("a", "b")) vdims2 = tuple(DimensionDesc(d) for d in ("a", "b", "c")) actual = VariableDesc("x", dimensions=vdims1) expected = VariableDesc("x", dimensions=vdims2) print_test_message( "VariableDesc(dims1) != VariableDesc(dims2)", actual=str(actual), expected=str(expected), ) self.assertNotEqual( actual, expected, "Differently dimensioned VariableDesc objects equal" )
def test_refdatetime(self): indata = "0001-01-01 00:00:00 -05:00" vdesc = VariableDesc("x", attributes={"units": "days since {}".format(indata)}) actual = vdesc.refdatetime() expected = indata print_test_message( "VariableDesc.refdatetime()", indata=indata, actual=actual, expected=expected, ) self.assertEqual( actual, expected, "Default VariableDesc.refdatetime() not {}".format(indata) )
def test_autoparse_time_variable_hidden(self): indata = (VariableDesc("a"), VariableDesc("b"), VariableDesc("_t")) fdesc = FileDesc("test.nc", variables=indata, autoparse_time_variable="_t") actual = fdesc.variables expected = OrderedDict((d.name, d) for d in indata) print_test_message( "FileDesc.variables", input=indata, actual=actual, expected=expected ) self.assertEqual(actual, expected, "FileDesc.variables failed") actual = fdesc.dimensions expected = OrderedDict() print_test_message( "FileDesc.dimensions", input=indata, actual=actual, expected=expected ) self.assertEqual(actual, expected, "FileDesc.dimensions failed")
def test_variables_same_dims(self): indata = (VariableDesc('a', dimensions=[DimensionDesc('x', 4)]), VariableDesc('b', dimensions=[DimensionDesc('x', 4)])) fdesc = FileDesc('test.nc', variables=indata) actual = fdesc.variables expected = OrderedDict((d.name, d) for d in indata) print_test_message('FileDesc.variables', input=indata, actual=actual, expected=expected) self.assertEqual(actual, expected, 'FileDesc.variables failed') adim = fdesc.variables['a'].dimensions['x'] bdim = fdesc.variables['b'].dimensions['x'] print_test_message('FileDesc.dimensions', adim=adim, bdim=bdim) self.assertEqual(adim, bdim, 'FileDesc.dimensions failed') actual = fdesc.dimensions expected = OrderedDict([(adim.name, adim)]) print_test_message('FileDesc.dimensions', actual=actual, expected=expected) self.assertEqual(actual, expected, 'FileDesc.dimensions failed')
def test_name(self): indata = 'x' vdesc = VariableDesc(indata) actual = vdesc.name expected = indata print_test_message('VariableDesc.name', indata=indata, actual=actual, expected=expected) self.assertEqual(actual, expected, 'VariableDesc.name does not match')