Changeset 4977
- Timestamp:
- Jan 28, 2008, 10:46:34 AM (16 years ago)
- Location:
- anuga_core/source/anuga/utilities
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/utilities/system_tools.py
r4963 r4977 185 185 fid = open(filename) 186 186 crcval = crc32(fid.read(max_length)) 187 fid.close() 187 188 return crcval -
anuga_core/source/anuga/utilities/test_system_tools.py
r4961 r4977 34 34 35 35 import zlib 36 from tempfile import NamedTemporaryFile, mktemp36 from tempfile import mkstemp, mktemp 37 37 38 38 # Generate a text file 39 fid = NamedTemporaryFile(mode='w', 40 suffix='.tmp', 41 dir='.') 39 tmp_fd , tmp_name = mkstemp(suffix='.tmp',dir='.') 40 fid = os.fdopen(tmp_fd,'w') 42 41 string = 'My temp file with textual content. AAAABBBBCCCC1234' 43 42 fid.write(string) … … 46 45 47 46 ref_crc = zlib.crc32(string) 48 checksum = compute_checksum(fid.name) 47 48 49 50 checksum = compute_checksum(tmp_name) 49 51 50 52 assert checksum == ref_crc 51 53 52 # Close and remove temporary file53 54 fid.close() 55 os.remove(tmp_name) 56 54 57 55 58 56 59 57 60 # Binary file 58 fid = NamedTemporaryFile(mode='w+b', 59 suffix='.tmp', 60 dir='.') 61 tmp_fd , tmp_name = mkstemp(suffix='.tmp',dir='.') 62 fid = os.fdopen(tmp_fd,'w+b') 63 64 61 65 string = 'My temp file with binary content. AAAABBBBCCCC1234' 62 66 fid.write(string) … … 65 69 66 70 ref_crc = zlib.crc32(string) 67 checksum = compute_checksum( fid.name)71 checksum = compute_checksum(tmp_name) 68 72 69 73 assert checksum == ref_crc … … 71 75 # Close and remove temporary file 72 76 fid.close() 73 77 os.remove(tmp_name) 74 78 75 79 # Binary NetCDF File X 2 (use mktemp's name)
Note: See TracChangeset
for help on using the changeset viewer.