コード例 #1
0
ファイル: test_ncfs.py プロジェクト: dvalters/fuse-netcdf
 def setUp(self):
     self.ds = create_test_dataset_1()
     vardata_repr = VardataAsFlatTextFiles()
     attr_repr = AttributesAsTextFiles()
     dimnames_repr = DimNamesAsTextFiles()
     self.ncfs = NCFS(self.ds, vardata_repr, attr_repr, dimnames_repr)
     self.testvar = self.ncfs.get_variable('/y/DATA_REPR')
コード例 #2
0
ファイル: test_ncfs.py プロジェクト: dvalters/fuse-netcdf
class TestIsVariableDimensions(unittest.TestCase):
    def setUp(self):
        self.ncfs = NCFS(FakeDataset(), None, None, None)

    def test_is_var_dimensions_1(self):
        self.assertTrue(self.ncfs.is_var_dimensions('/abcd/DIMENSIONS'))

    def test_is_var_dimensions_2(self):
        self.assertFalse(self.ncfs.is_var_dimensions('/abcd/DATA_REPR'))
コード例 #3
0
ファイル: test_ncfs.py プロジェクト: dvalters/fuse-netcdf
class TestDimensions(unittest.TestCase):
    def setUp(self):
        self.ds = create_test_dataset_1()
        dimnames_repr = DimNamesAsTextFiles()
        self.ncfs = NCFS(self.ds, None, None, dimnames_repr)

    def tearDown(self):
        self.ds.close()

    def test_reading_dimensions(self):
        expected = 'x\ny\n'
        self.assertMultiLineEqual(
            str(self.ncfs.read('/foovar/DIMENSIONS', 4, 0)), expected)

    def test_renaming_all_dimensions(self):
        self.ncfs.write('/foovar/DIMENSIONS', 'lon\nlat\n', 0, 0)
        expected = (u'lon', u'lat')
        # were dimensions renamed?
        self.assertEqual(self.ds.variables['foovar'].dimensions, expected)
        # was the 'x' Dimension Variable renamed to 'lon'?
        self.assertTrue('lon' in self.ds.variables)

    def test_renaming_some_dimensions(self):
        self.ncfs.write('/foovar/DIMENSIONS', 'x\nlat\n', 0, 0)
        expected = (u'x', u'lat')
        # were dimensions renamed?
        self.assertEqual(self.ds.variables['foovar'].dimensions, expected)
        # is the 'x' Dimension Variable still named 'x'?
        self.assertTrue('x' in self.ds.variables)

    def test_ignoring_invalid_edits(self):
        # if new list has wrong number of dimensions, ingore the change
        self.assertRaises(FuseOSError, self.ncfs.write, '/foovar/DIMENSIONS',
                          'a\nb\nc\n', 0, 0)
        expected = (u'x', u'y')
        self.assertEqual(self.ds.variables['foovar'].dimensions, expected)

    def test_renaming_dimension_variable(self):
        self.ncfs.rename('/x', 'lon')
        # did renaming Dimension Variable also renamed corresponding Dimension?
        self.assertFalse('x' in self.ds.variables)
        self.assertTrue('lon' in self.ds.variables)
        self.assertFalse('x' in self.ds.dimensions)
        self.assertTrue('lon' in self.ds.dimensions)

    def test_swapping_dimension_names(self):
        self.ncfs.write('/foovar/DIMENSIONS', 'y\nx\n', 0, 0)
        self.assertEqual(self.ds.variables['foovar'].dimensions, (u'y', u'x'))
        # were dimension variables swapped as well?
        self.assertTrue((self.ds.variables['y'][:] == [1, 2, 3]).all())
        self.assertTrue((self.ds.variables['x'][:] == [4., 5., 6.]).all())

    def test_duplicate_names(self):
        self.assertRaises(FuseOSError, self.ncfs.write, '/foovar/DIMENSIONS',
                          'y\ny\n', 0, 0)
        # was this edit ignored?
        self.assertEqual(self.ds.variables['foovar'].dimensions, (u'x', u'y'))
コード例 #4
0
class TestIsVarDir(unittest.TestCase):
    def setUp(self):
        self.ncfs = NCFS(None, None, None)

    def test_is_var_dir_1(self):
        self.assertTrue(self.ncfs.is_var_dir('/abcd'))

    def test_is_var_dir_2(self):
        self.assertFalse(self.ncfs.is_var_dir('/abcd/def'))

    def test_is_var_dir_3(self):
        self.assertFalse(self.ncfs.is_var_dir('/'))

    def test_is_var_dir_4(self):
        self.assertFalse(self.ncfs.is_var_dir('/abcd/DATA_REPR'))
コード例 #5
0
ファイル: test_ncfs.py プロジェクト: dvalters/fuse-netcdf
class TestIsVarData(unittest.TestCase):
    def setUp(self):
        self.ncfs = NCFS(FakeDataset(), None, None, None)

    def test_is_var_data_1(self):
        self.assertFalse(self.ncfs.is_var_data('/abcd'))

    def test_is_var_data_2(self):
        self.assertFalse(self.ncfs.is_var_data('/abcd/def'))

    def test_is_var_data_3(self):
        self.assertFalse(self.ncfs.is_var_data('/'))

    def test_is_var_data_4(self):
        self.assertTrue(self.ncfs.is_var_data('/abcd/DATA_REPR'))
コード例 #6
0
class TestIsVarAttribute(unittest.TestCase):
    def setUp(self):
        self.ncfs = NCFS(None, None, None)

    def test_is_var_attr_1(self):
        self.assertFalse(self.ncfs.is_var_attr('/abcd'))

    def test_is_var_attr_2(self):
        self.assertTrue(self.ncfs.is_var_attr('/abcd/def'))

    def test_is_var_attr_3(self):
        self.assertFalse(self.ncfs.is_var_attr('/'))

    def test_is_var_attr_4(self):
        self.assertFalse(self.ncfs.is_var_attr('/abcd/DATA_REPR'))

    def test_is_var_attr_5(self):
        self.assertFalse(self.ncfs.is_var_attr('/abcd/dimensions'))
コード例 #7
0
ファイル: test_ncfs.py プロジェクト: dvalters/fuse-netcdf
class TestCreatingInvalidNames(unittest.TestCase):
    def setUp(self):
        self.ds = create_test_dataset_1()
        self.ncfs = NCFS(self.ds, None, None, None)

    def tearDown(self):
        self.ds.close()

    def test_dot_file_as_global_attr(self):
        self.ncfs.create('/.foo', mode=int('0100644', 8))
        self.assertFalse('.foo' in self.ds.ncattrs())

    def test_emacs_tempfile_as_global_attr(self):
        self.ncfs.create('/foo~', mode=int('0100644', 8))
        self.assertFalse('foo~' in self.ds.ncattrs())

    def test_dot_file_as_variable_attr(self):
        self.ncfs.create('/foovar/.foo', mode=int('0100644', 8))
        self.assertFalse(self.ncfs.exists('/foovar/.foo'))

    def test_emacs_tempfile_as_variable_attr(self):
        self.ncfs.create('/foovar/foo~', mode=int('0100644', 8))
        self.assertFalse(self.ncfs.exists('/foovar/foo~'))
コード例 #8
0
class TestWrite(unittest.TestCase):
    def setUp(self):
        self.ds = create_test_dataset_1()
        self.ncfs = NCFS(self.ds, None, None)

    def tearDown(self):
        self.ds.close()

    def test_writing_to_existing_attr(self):
        self.ncfs.write('/foovar/fooattr', '123', offset=0)
        self.assertEqual(self.ds.variables['foovar'].fooattr, '123')

    def test_creating_new_attr(self):
        self.ncfs.create('/foovar/xyz', mode=int('0100644', 8))
        self.assertEqual(self.ds.variables['foovar'].xyz, '')

    def test_appending_to_existing_attr(self):
        self.ncfs.write('/foovar/fooattr', '123', offset=3)
        self.assertEqual(self.ds.variables['foovar'].fooattr, 'abc123')

    def test_deleting_existing_attr(self):
        self.ncfs.unlink('/foovar/fooattr')
        self.assertRaises(AttributeError,
                          self.ds.variables['foovar'].getncattr, 'foovar')
コード例 #9
0
ファイル: test_ncfs.py プロジェクト: dvalters/fuse-netcdf
class TestExists(unittest.TestCase):
    def setUp(self):
        self.ncfs = NCFS(FakeDataset(), None, None, None)

    def test_exists_1(self):
        self.assertTrue(self.ncfs.exists('/foovar'))

    def test_exists_2(self):
        self.assertTrue(self.ncfs.exists('/foovar/fooattr'))

    def test_exists_3(self):
        self.assertFalse(self.ncfs.exists('/foovar/fooattr/foo'))

    def test_exists_4(self):
        self.assertTrue(self.ncfs.exists('/'))

    def test_exists_5(self):
        self.assertTrue(self.ncfs.exists('/foovar/DATA_REPR'))

    def test_exists_6(self):
        self.assertTrue(self.ncfs.exists('/foovar/DIMENSIONS'))
コード例 #10
0
 def setUp(self):
     dataset = FakeDataset()
     self.ncfs = NCFS(dataset, None, None)
コード例 #11
0
ファイル: test_ncfs.py プロジェクト: dvalters/fuse-netcdf
class TestGlobalAttrs(unittest.TestCase):
    def setUp(self):
        self.ds = create_test_dataset_1()
        self.ncfs = NCFS(self.ds, None, None, None)

    def tearDown(self):
        self.ds.close()

    def test_creating_new_global_attr(self):
        self.ncfs.create('/attr2', mode=int('0100644', 8))
        self.assertTrue('attr2' in self.ds.ncattrs())

    def test_writing_to_existing_global_attr(self):
        self.ncfs.write('/attr1', 'newattr1val', offset=0)
        self.assertEqual(self.ds.getncattr('attr1'), 'newattr1val')

    def test_writing_to_existing_global_attr_2(self):
        self.ncfs.write('/attr1', 'x', offset=0)
        self.assertEqual(self.ds.getncattr('attr1'), 'xttrval1')

    def test_is_global_attr_on_existing_attr(self):
        self.assertTrue(self.ncfs.is_global_attr('/attr1'))

    def test_is_global_attr_on_nonexisting_attr(self):
        self.assertTrue(self.ncfs.is_global_attr('/attr99'))

    def test_get_global_attr(self):
        self.assertTrue(self.ncfs.get_global_attr('/attr1') is not None)

    def test_exist_on_global_attr(self):
        self.assertTrue(self.ncfs.exists('/attr1'))

    def test_is_var_dir_on_existing_global_attr(self):
        self.assertFalse(self.ncfs.is_var_dir('/attr1'))

    def test_deleting_existing_global_attr(self):
        self.ncfs.unlink('/attr1')
        self.assertFalse('attr1' in self.ds.ncattrs())
コード例 #12
0
 def setUp(self):
     self.ncfs = NCFS(None, None, None)
コード例 #13
0
ファイル: test_ncfs.py プロジェクト: dvalters/fuse-netcdf
 def setUp(self):
     self.ds = create_test_dataset_1()
     dimnames_repr = DimNamesAsTextFiles()
     self.ncfs = NCFS(self.ds, None, None, dimnames_repr)
コード例 #14
0
 def setUp(self):
     self.ds = create_test_dataset_1()
     self.ncfs = NCFS(self.ds, None, None)
コード例 #15
0
ファイル: test_ncfs.py プロジェクト: dvalters/fuse-netcdf
class TestEditingVariables(unittest.TestCase):

    __name__ = ''

    def setUp(self):
        self.ds = create_test_dataset_1()
        vardata_repr = VardataAsFlatTextFiles()
        attr_repr = AttributesAsTextFiles()
        dimnames_repr = DimNamesAsTextFiles()
        self.ncfs = NCFS(self.ds, vardata_repr, attr_repr, dimnames_repr)
        self.testvar = self.ncfs.get_variable('/y/DATA_REPR')

    def tearDown(self):
        self.ds.close()

    def test_editing_entire_text_of_dimension_variable(self):
        self.ncfs.write('/y/DATA_REPR', '7.0\n8.0\n9.0\n', 0)
        expected = [7., 8., 9.]
        self.assertEqual(list(self.testvar[:]), expected)

    def test_editing_partial_text_of_dimension_variable(self):
        with self.assertRaises(FuseOSError) as cm:
            self.ncfs.write('/y/DATA_REPR', '7.0\n8.0', 0)
        self.assertEqual(cm.exception.errno, errno.EACCES)

    @unittest.skip
    def test_2writes_followed_by_a_release(self):
        self.ncfs.write('/y/DATA_REPR', '7.0\n8.0', 0)
        self.ncfs.write('/y/DATA_REPR', '\n9.0\n', 8)
        self.ncfs.release('/y/DATA_REPR')
        v = self.ncfs.get_variable('/y/DATA_REPR')
        expected = [7., 8., 9.]
        self.assertEqual(list(v[:]), expected)
コード例 #16
0
ファイル: test_ncfs.py プロジェクト: dvalters/fuse-netcdf
 def setUp(self):
     self.ncfs = NCFS(FakeDataset(), None, None, None)
コード例 #17
0
ファイル: test_ncfs.py プロジェクト: dvalters/fuse-netcdf
class TestWrite(unittest.TestCase):
    def setUp(self):
        self.ds = create_test_dataset_1()
        self.ncfs = NCFS(self.ds, None, None, None)

    def tearDown(self):
        self.ds.close()

    def test_writing_to_existing_attr(self):
        self.ncfs.write('/foovar/fooattr', '123', offset=0)
        self.assertEqual(self.ds.variables['foovar'].fooattr, '123')

    def test_creating_new_attr(self):
        self.ncfs.create('/foovar/xyz', mode=int('0100644', 8))
        self.assertEqual(self.ds.variables['foovar'].xyz, '')

    def test_appending_to_existing_attr(self):
        self.ncfs.write('/foovar/fooattr', '123', offset=3)
        self.assertEqual(self.ds.variables['foovar'].fooattr, 'abc123')

    def test_deleting_existing_attr(self):
        self.ncfs.unlink('/foovar/fooattr')
        self.assertTrue('fooattr' not in self.ds.variables['foovar'].ncattrs())

    def test_truncating_global_attr(self):
        self.ncfs.truncate('/attr1', 3)
        self.assertEqual(self.ds.getncattr('attr1'), 'att')

    def test_increasing_global_attr_length(self):
        self.ncfs.truncate('/attr1', 10)
        self.assertEqual(self.ds.getncattr('attr1'), 'attrval1  ')

    def test_truncating_variable_attr(self):
        self.ncfs.truncate('/foovar/fooattr', 2)
        self.assertEqual(self.ncfs.get_var_attr('/foovar/fooattr'), 'ab')

    def test_increasing_variable_attr_length(self):
        self.ncfs.truncate('/foovar/fooattr', 10)
        self.assertEqual(self.ncfs.get_var_attr('/foovar/fooattr'),
                         'abc       ')