def test_exists_false(self): indata = 'test.nc' if exists(indata): remove(indata) fdesc = FileDesc(indata) actual = fdesc.exists() expected = False print_test_message('FileDesc.exists() == {}'.format(expected), input=indata, actual=actual, expected=expected) self.assertEqual(actual, expected, 'FileDesc.exists() failed')
def test_exists_true(self): indata = 'test.nc' if not exists(indata): open(indata, 'w').close() fdesc = FileDesc(indata) actual = fdesc.exists() expected = True print_test_message('FileDesc.exists() == {}'.format(expected), input=indata, actual=actual, expected=expected) self.assertEqual(actual, expected, 'FileDesc.exists() failed') if exists(indata): remove(indata)
def test_attributes_default(self): fdesc = FileDesc('test.nc') actual = fdesc.attributes expected = {} print_test_message('FileDesc.attributes == {}'.format(expected), actual=actual, expected=expected) self.assertEqual(actual, expected, 'FileDesc.attributes failed')
def test_exists_true(self): indata = "test.nc" if not exists(indata): open(indata, "w").close() fdesc = FileDesc(indata) actual = fdesc.exists() expected = True print_test_message( "FileDesc.exists() == {}".format(expected), input=indata, actual=actual, expected=expected, ) self.assertEqual(actual, expected, "FileDesc.exists() failed") if exists(indata): remove(indata)
def test_format_default(self): indata = 'test.nc' fdesc = FileDesc(indata) actual = fdesc.format expected = 'NETCDF4_CLASSIC' print_test_message('FileDesc.format == {}'.format(expected), input=indata, actual=actual, expected=expected) self.assertEqual(actual, expected, 'FileDesc.format failed')
def test_format_valid(self): indata = 'NETCDF4' fdesc = FileDesc('test.nc', format=indata) actual = fdesc.format expected = indata print_test_message('FileDesc.format == {}'.format(expected), input=indata, actual=actual, expected=expected) self.assertEqual(actual, expected, 'FileDesc.format failed')
def test_attributes_valid(self): indata = {'a': 'attribute 1', 'b': 'attribute 2'} fdesc = FileDesc('test.nc', attributes=indata) actual = fdesc.attributes expected = indata print_test_message('FileDesc.attributes == {}'.format(expected), input=indata, actual=actual, expected=expected) self.assertEqual(actual, expected, 'FileDesc.attributes failed')
def test_name(self): indata = 'test.nc' fdesc = FileDesc(indata) actual = fdesc.name expected = indata print_test_message('FileDesc.name == {}'.format(indata), input=indata, actual=actual, expected=expected) self.assertEqual(actual, expected, 'FileDesc.name failed')
def test_type(self): indata = 'test.nc' fdesc = FileDesc(indata) actual = type(fdesc) expected = FileDesc print_test_message('FileDesc.__init__({})'.format(indata), input=indata, actual=actual, expected=expected) self.assertEqual(actual, expected, 'No FileDesc created')
def test_attributes_default(self): fdesc = FileDesc("test.nc") actual = fdesc.attributes expected = {} print_test_message( "FileDesc.attributes == {}".format(expected), actual=actual, expected=expected, ) self.assertEqual(actual, expected, "FileDesc.attributes failed")
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_type(self): indata = "test.nc" fdesc = FileDesc(indata) actual = type(fdesc) expected = FileDesc print_test_message( "FileDesc.__init__({})".format(indata), input=indata, actual=actual, expected=expected, ) self.assertEqual(actual, expected, "No FileDesc created")
def test_format_valid(self): indata = "NETCDF4" fdesc = FileDesc("test.nc", format=indata) actual = fdesc.format expected = indata print_test_message( "FileDesc.format == {}".format(expected), input=indata, actual=actual, expected=expected, ) self.assertEqual(actual, expected, "FileDesc.format failed")
def test_format_default(self): indata = "test.nc" fdesc = FileDesc(indata) actual = fdesc.format expected = "NETCDF4_CLASSIC" print_test_message( "FileDesc.format == {}".format(expected), input=indata, actual=actual, expected=expected, ) self.assertEqual(actual, expected, "FileDesc.format failed")
def test_attributes_valid(self): indata = {"a": "attribute 1", "b": "attribute 2"} fdesc = FileDesc("test.nc", attributes=indata) actual = fdesc.attributes expected = indata print_test_message( "FileDesc.attributes == {}".format(expected), input=indata, actual=actual, expected=expected, ) self.assertEqual(actual, expected, "FileDesc.attributes failed")
def test_name(self): indata = "test.nc" fdesc = FileDesc(indata) actual = fdesc.name expected = indata print_test_message( "FileDesc.name == {}".format(indata), input=indata, actual=actual, expected=expected, ) self.assertEqual(actual, expected, "FileDesc.name failed")
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_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_autoparse_time_variable_missing(self): indata = (VariableDesc('a'), VariableDesc('b')) with self.assertRaises(ValueError): FileDesc('test.nc', variables=indata, autoparse_time_variable='t')
def test_autoparse_time_variable_missing(self): indata = (VariableDesc("a"), VariableDesc("b")) with self.assertRaises(ValueError): FileDesc("test.nc", variables=indata, autoparse_time_variable="t")