Beispiel #1
0
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       ')
Beispiel #2
0
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())
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')
Beispiel #4
0
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~'))