Example #1
0
 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')
Example #2
0
 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)
Example #3
0
 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')
Example #4
0
 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)
Example #5
0
 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')
Example #6
0
 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')
Example #7
0
 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')
Example #8
0
 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')
Example #9
0
 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')
Example #10
0
 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")
Example #11
0
 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')
Example #12
0
 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")
Example #13
0
 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")
Example #14
0
 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")
Example #15
0
 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")
Example #16
0
 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")
Example #17
0
 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")
Example #18
0
 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')
Example #19
0
 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")
Example #20
0
 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')
Example #21
0
 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")