Changeset 4956
- Timestamp:
- Jan 18, 2008, 3:58:24 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/utilities/test_system_tools.py
r4955 r4956 3 3 4 4 import unittest 5 from Numeric import zeros, array, allclose 5 from Numeric import zeros, array, allclose, Float 6 from Scientific.IO.NetCDF import NetCDFFile 6 7 7 8 from system_tools import * … … 25 26 # print host 26 27 assert isinstance(host, basestring), 'User name should be a string' 28 27 29 def test_compute_checksum(self): 28 30 """test_compute_checksum(self): … … 30 32 Check that checksums on files are OK 31 33 """ 32 # FIXME: Not Done Yet33 34 34 from tempfile import mkstemp 35 import zlib 36 from tempfile import NamedTemporaryFile, mkstemp, mktemp 35 37 36 38 # Generate a text file 37 fd, pathname = mkstemp('.tmp', '', '.', '') 39 fid = open(mktemp(suffix='.tmp', 40 dir='.'), 'w') 41 string = 'My temp file with textual content. AAAABBBBCCCC1234' 42 fid.write(string) 43 fid.close() 44 45 46 ref_crc = zlib.crc32(string) 47 checksum = compute_checksum(fid.name) 48 49 assert checksum == ref_crc 50 51 os.remove(fid.name) 52 53 # Binary file 54 fid = open(mktemp(suffix='.tmp', 55 dir='.'), 'wb') 56 string = 'My temp file with textual content. AAAABBBBCCCC1234' 57 fid.write(string) 58 fid.close() 59 60 ref_crc = zlib.crc32(string) 61 checksum = compute_checksum(fid.name) 62 63 assert checksum == ref_crc 64 os.remove(fid.name) 65 66 # Binary NetCDF File X 2 67 68 test_array = array([[7.0, 3.14], [-31.333, 0.0]]) 69 70 # First file 71 filename1 = mktemp(suffix='.nc', dir='.') 72 fid = NetCDFFile(filename1, 'w') 73 fid.createDimension('two', 2) 74 fid.createVariable('test_array', Float, 75 ('two', 'two')) 76 fid.variables['test_array'][:] = test_array 77 fid.close() 78 79 # Second file 80 filename2 = mktemp(suffix='.nc', dir='.') 81 fid = NetCDFFile(filename2, 'w') 82 fid.createDimension('two', 2) 83 fid.createVariable('test_array', Float, 84 ('two', 'two')) 85 fid.variables['test_array'][:] = test_array 86 fid.close() 38 87 39 88 40 89 checksum1 = compute_checksum(filename1) 90 checksum2 = compute_checksum(filename2) 91 assert checksum1 == checksum2 92 93 94 os.remove(filename1) 95 os.remove(filename2) 41 96 42 97
Note: See TracChangeset
for help on using the changeset viewer.