66NeXus tests converted to python.
77"""
88
9+ from __future__ import print_function
10+
911import nxs ,os ,numpy ,sys
1012
1113def memfootprint ():
1214 import gc
1315 objs = gc .get_objects ()
1416 classes = set ( c .__class__ for c in gc .get_objects () if hasattr (c ,'__class__' ) )
15- # print "\n".join([c.__name__ for c in classes])
16- print "#objects=" ,len (objs )
17- print "#classes=" ,len (classes )
17+ # print( "\n".join([c.__name__ for c in classes]) )
18+ print ( "#objects=" ,len (objs ) )
19+ print ( "#classes=" ,len (classes ) )
1820
1921def leak_test1 (n = 1000 , mode = 'w5' ):
2022# import gc
@@ -25,10 +27,10 @@ def leak_test1(n = 1000, mode='w5'):
2527 except OSError : pass
2628 file = nxs .open (filename ,mode )
2729 file .close ()
28- print "File should exist now"
30+ print ( "File should exist now" )
2931 for i in range (n ):
3032 if i % 100 == 0 :
31- print "loop count %d" % i
33+ print ( "loop count %d" % i )
3234 memfootprint ()
3335 file .open ()
3436 file .close ()
@@ -39,31 +41,31 @@ def _show(file, indent=0):
3941 prefix = ' ' * indent
4042 link = file .link ()
4143 if link :
42- print "%(prefix)s-> %(link)s" % locals ()
44+ print ( "%(prefix)s-> %(link)s" % locals () )
4345 return
4446 for attr ,value in file .attrs ():
45- print "%(prefix)s@%(attr)s: %(value)s" % locals ()
47+ print ( "%(prefix)s@%(attr)s: %(value)s" % locals () )
4648 for name ,nxclass in file .entries ():
4749 if nxclass == "SDS" :
4850 shape ,dtype = file .getinfo ()
4951 dims = "x" .join ([str (x ) for x in shape ])
50- print "%(prefix)s%(name)s %(dtype)s %(dims)s" % locals ()
52+ print ( "%(prefix)s%(name)s %(dtype)s %(dims)s" % locals () )
5153 link = file .link ()
5254 if link :
53- print " %(prefix)s-> %(link)s" % locals ()
55+ print ( " %(prefix)s-> %(link)s" % locals () )
5456 else :
5557 for attr ,value in file .attrs ():
56- print " %(prefix)s@%(attr)s: %(value)s" % locals ()
58+ print ( " %(prefix)s@%(attr)s: %(value)s" % locals () )
5759 if numpy .prod (shape ) < 8 :
5860 value = file .getdata ()
59- print " %s%s" % (prefix ,str (value ))
61+ print ( " %s%s" % (prefix ,str (value ) ))
6062 else :
61- print "%(prefix)s%(name)s %(nxclass)s" % locals ()
63+ print ( "%(prefix)s%(name)s %(nxclass)s" % locals () )
6264 _show (file , indent + 2 )
6365
6466def show_structure (filename ):
6567 file = nxs .open (filename )
66- print "=== File" ,file .inquirefile ()
68+ print ( "=== File" ,file .inquirefile () )
6769 _show (file )
6870
6971
@@ -168,7 +170,7 @@ def populate(filename,mode):
168170failures = 0
169171def fail (msg ):
170172 global failures
171- print "FAIL:" ,msg
173+ print ( "FAIL:" ,msg )
172174 failures += 1
173175
174176def dicteq (a ,b ):
@@ -177,14 +179,14 @@ def dicteq(a,b):
177179 """
178180 for k ,v in a .iteritems ():
179181 if k not in b :
180- print k ,"not in" ,b
182+ print ( k ,"not in" ,b )
181183 return False
182184 if v != b [k ]:
183- print v ,"not equal" ,b [k ]
185+ print ( v ,"not equal" ,b [k ])
184186 return False
185187 for k ,v in b .iteritems ():
186188 if k not in a :
187- print k ,"not in" ,a
189+ print ( k ,"not in" ,a )
188190 return False
189191 return True
190192
@@ -264,10 +266,10 @@ def check(filename, mode):
264266 fail ("returned string array info is incorrect" )
265267 if not (rawshape [0 ]== 5 and rawshape [1 ]== 4 and rawdtype == 'char' ):
266268 fail ("returned string array storage info is incorrect" )
267- print rawshape ,dtype
269+ print ( rawshape ,dtype )
268270 if not (get [0 ]== "abcd" and get [4 ]== "qrst" ):
269271 fail ("returned string is incorrect" )
270- print shape ,dtype
272+ print ( shape ,dtype )
271273
272274
273275 # Check reading from compressed datasets
@@ -281,7 +283,7 @@ def check(filename, mode):
281283 file .closegroup () #/entry/data
282284 if not (get == expected ).all ():
283285 fail ("compressed data differs" )
284- print get
286+ print ( get )
285287
286288 # Check strings
287289 file .opengroup ('sample' ,'NXsample' ) #/entry/sample
@@ -293,13 +295,13 @@ def check(filename, mode):
293295 file .closegroup () #/entry/sample
294296 if not (shape [0 ]== 12 and dtype == 'char' ):
295297 fail ("returned string info is incorrect" )
296- print shape ,dtype
298+ print ( shape ,dtype )
297299 if not (rawshape [0 ]== 20 and rawdtype == 'char' ):
298300 fail ("returned string storage info is incorrect" )
299- print shape ,dtype
301+ print ( shape ,dtype )
300302 if not (get == "NeXus sample" ):
301303 fail ("returned string is incorrect" )
302- print shape ,dtype
304+ print ( shape ,dtype )
303305
304306 file .closegroup () #/entry
305307
@@ -328,13 +330,13 @@ def check(filename, mode):
328330 expected = comp_array [4 :(4 + 5 ),4 :(4 + 3 )]
329331 if not (get == expected ).all ():
330332 fail ("retrieved compressed slabs differ" )
331- print get
333+ print ( get )
332334 file .openpath ('/entry/data/comp_data' )
333335 get = file .getslab ([4 ,4 ],[5 ,3 ])
334336 expected = comp_array [4 :(4 + 5 ),4 :(4 + 3 )]
335337 if not (get == expected ).all ():
336338 fail ("after reopen: retrieved compressed slabs differ" )
337- print get
339+ print ( get )
338340 file .openpath ('../r8_data' )
339341 for k ,v in file .attrs ():
340342 if k == 'target' and v != '/entry/r8_data' :
0 commit comments