File: test_refcount.py

package info (click to toggle)
netcdf4-python 1.7.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,604 kB
  • sloc: python: 6,057; ansic: 854; makefile: 15; sh: 2
file content (28 lines) | stat: -rw-r--r-- 978 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import unittest, netCDF4, tempfile, os

file_name = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name

class RefCountTestCase(unittest.TestCase):

    def setUp(self):
        nc = netCDF4.Dataset(file_name, mode='w', keepweakref=True, format='NETCDF4')
        d = nc.createDimension('fred', 2000)
        v = nc.createVariable('frank','f',('fred',))
        self.file = file_name
        self.nc = nc

    def tearDown(self):
        # Remove the temporary files
        os.remove(self.file)

    def runTest(self):
        """testing garbage collection (issue 218)"""
        # this should trigger garbage collection (__dealloc__ method)
        del self.nc
        # if __dealloc__ not called to close file, then this
        # will fail with "Permission denied" error (since you can't
        # open a file 'w' that is already open for writing).
        nc = netCDF4.Dataset(self.file, mode='w', format='NETCDF4')

if __name__ == '__main__':
    unittest.main()