Changeset 4961


Ignore:
Timestamp:
Jan 21, 2008, 10:24:47 AM (17 years ago)
Author:
ole
Message:

Rewrote CRC test using NamedTemporaryFile?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/utilities/test_system_tools.py

    r4956 r4961  
    3434
    3535        import zlib
    36         from tempfile import NamedTemporaryFile, mkstemp, mktemp
     36        from tempfile import NamedTemporaryFile, mktemp
    3737
    3838        # Generate a text file
    39         fid = open(mktemp(suffix='.tmp',
    40                           dir='.'), 'w')
     39        fid = NamedTemporaryFile(mode='w',
     40                                 suffix='.tmp',
     41                                 dir='.')
    4142        string = 'My temp file with textual content. AAAABBBBCCCC1234'
    4243        fid.write(string)
    43         fid.close()
     44        fid.flush()
    4445
    4546
     
    4950        assert checksum == ref_crc
    5051
    51         os.remove(fid.name)
     52        # Close and remove temporary file
     53        fid.close()
     54
     55
    5256
    5357        # Binary file
    54         fid = open(mktemp(suffix='.tmp',
    55                           dir='.'), 'wb')
    56         string = 'My temp file with textual content. AAAABBBBCCCC1234'
     58        fid = NamedTemporaryFile(mode='w+b',
     59                                 suffix='.tmp',
     60                                 dir='.')
     61        string = 'My temp file with binary content. AAAABBBBCCCC1234'
    5762        fid.write(string)
    58         fid.close()
     63        fid.flush()
     64
    5965
    6066        ref_crc = zlib.crc32(string)
     
    6268
    6369        assert checksum == ref_crc
    64         os.remove(fid.name)
     70
     71        # Close and remove temporary file
     72        fid.close()
    6573       
    66         # Binary NetCDF File X 2
     74       
     75        # Binary NetCDF File X 2 (use mktemp's name)
    6776
    6877        test_array = array([[7.0, 3.14], [-31.333, 0.0]])
Note: See TracChangeset for help on using the changeset viewer.