4
4
# Created: October 2, 2004
5
# Author: Ivan Vilata i Balaguer - reverse:net.selidor@ivan
5
# Author: Ivan Vilata i Balaguer - reverse:com.carabos@ivilata
7
# $Source: /cvsroot/pytables/pytables/test/test_filenode.py,v $
8
# $Id: test_filenode.py,v 1.3.2.5 2004/11/18 19:22:15 ivilata Exp $
7
# $Source: /home/ivan/_/programari/pytables/svn/cvs/pytables/pytables/test/test_filenode.py,v $
8
# $Id: test_filenode.py 1009 2005-06-15 13:39:15Z faltet $
10
10
########################################################################
377
377
IOError, FileNode.openNode, self.h5file.getNode('/test'), 'w')
380
def test03_OpenFileNoAttrs(self):
381
"Opening a node with no type attributes."
383
node = self.h5file.getNode('/test')
384
self.h5file.delAttrNode('/test', '_type')
385
# Another way to get the same result is changing the value.
386
##self.h5file.setAttrNode('/test', '_type', 'foobar')
387
self.assertRaises(ValueError, FileNode.openNode, node)
380
# This no longer works since type and type version attributes
381
# are now system attributes. ivb(2004-12-29)
382
##def test03_OpenFileNoAttrs(self):
383
## "Opening a node with no type attributes."
385
## node = self.h5file.getNode('/test')
386
## self.h5file.delNodeAttr('/test', '_type')
387
## # Another way to get the same result is changing the value.
388
## ##self.h5file.setNodeAttr('/test', '_type', 'foobar')
389
## self.assertRaises(ValueError, FileNode.openNode, node)
752
754
os.remove(self.h5fname)
755
def test00_GetTypeAttr(self):
756
"Getting the type attribute of a file node."
757
# This no longer works since type and type version attributes
758
# are now system attributes. ivb(2004-12-29)
759
##def test00_GetTypeAttr(self):
760
## "Getting the type attribute of a file node."
763
## getattr(self.fnode.attrs, '_type', None), FileNode.NodeType,
764
## "File node has no '_type' attribute.")
767
def test00_MangleTypeAttrs(self):
768
"Mangling the type attributes on a file node."
770
nodeType = getattr(self.fnode.attrs, 'NODE_TYPE', None)
758
771
self.assertEqual(
759
getattr(self.fnode.attrs, '_type', None), FileNode.NodeType,
760
"File node has no '_type' attribute.")
763
def test01_SetSystemAttr(self):
764
"Setting a system attribute on a file node."
767
RuntimeError, setattr, self.fnode.attrs, 'CLASS', 'foobar')
772
nodeType, FileNode.NodeType,
773
"File node does not have a valid 'NODE_TYPE' attribute.")
775
nodeTypeVersion = getattr(self.fnode.attrs, 'NODE_TYPE_VERSION', None)
777
nodeTypeVersion in FileNode.NodeTypeVersions,
778
"File node does not have a valid 'NODE_TYPE_VERSION' attribute.")
780
# System attributes are now writable. ivb(2004-12-30)
783
## setattr, self.fnode.attrs, 'NODE_TYPE', 'foobar')
786
## setattr, self.fnode.attrs, 'NODE_TYPE_VERSION', 'foobar')
790
delattr, self.fnode.attrs, 'NODE_TYPE')
793
delattr, self.fnode.attrs, 'NODE_TYPE_VERSION')
796
# System attributes are now writable. ivb(2004-12-30)
797
##def test01_SetSystemAttr(self):
798
## "Setting a system attribute on a file node."
800
## self.assertRaises(
801
## AttributeError, setattr, self.fnode.attrs, 'CLASS', 'foobar')
770
804
def test02_SetGetDelUserAttr(self):
890
class OldVersionTestCaseMixin:
891
"""Mix-in class for old version compatibility test cases.
893
It provides some basic tests for file operations and attribute handling.
894
Sub-classes must provide the 'oldversion' attribute
895
and the 'oldh5fname' attribute.
901
This method sets the following instance attributes:
902
* 'h5fname', the name of the temporary HDF5 file
903
* 'h5file', the writable, temporary HDF5 file with a '/test' node
904
* 'fnode', the writable file node in '/test'
907
self.h5fname = tempfile.mktemp(suffix = '.h5')
909
oldh5f = tables.openFile(self.oldh5fname)
910
oldh5f.copyFile(self.h5fname)
913
self.h5file = tables.openFile(
915
title = "Test for file node old version compatibility")
916
self.fnode = FileNode.openNode(self.h5file.root.test, 'a+')
920
"""tearDown() -> None
922
Closes 'fnode' and 'h5file'; removes 'h5fname'.
929
os.remove(self.h5fname)
932
def test00_Read(self):
933
"Reading an old version file node."
935
self.fnode.lineSeparator = '\n'
937
line = self.fnode.readline()
938
self.assertEqual(line, 'This is only\n')
940
line = self.fnode.readline()
941
self.assertEqual(line, 'a test file\n')
943
line = self.fnode.readline()
944
self.assertEqual(line, 'for FileNode version %d\n' % self.oldversion)
946
line = self.fnode.readline()
947
self.assertEqual(line, '')
950
line = self.fnode.readline()
951
self.assertEqual(line, 'This is only\n')
954
def test01_Write(self):
955
"Writing an old version file node."
957
self.fnode.lineSeparator = '\n'
959
self.fnode.write('foobar\n')
960
self.fnode.seek(-7, 2)
961
line = self.fnode.readline()
962
self.assertEqual(line, 'foobar\n')
965
def test02_Attributes(self):
966
"Accessing attributes in an old version file node."
968
self.fnode.attrs.userAttr = 'foobar'
970
getattr(self.fnode.attrs, 'userAttr', None), 'foobar',
971
"User attribute was not correctly set.")
973
self.fnode.attrs.userAttr = 'bazquux'
975
getattr(self.fnode.attrs, 'userAttr', None), 'bazquux',
976
"User attribute was not correctly changed.")
978
del self.fnode.attrs.userAttr
980
getattr(self.fnode.attrs, 'userAttr', None), None,
981
"User attribute was not deleted.")
985
class Version1TestCase(OldVersionTestCaseMixin, unittest.TestCase):
986
"Basic test for version 1 format compatibility."
989
oldh5fname = 'test_filenode_v1.h5'
856
993
#----------------------------------------------------------------------