File: test_open_mem.py

package info (click to toggle)
netcdf4-python 1.7.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,588 kB
  • sloc: python: 6,002; ansic: 854; makefile: 15; sh: 2
file content (31 lines) | stat: -rw-r--r-- 986 bytes parent folder | download
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
29
30
31
import os
import unittest
import netCDF4

CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))


class TestOpenMem(unittest.TestCase):
    def test_mem_open(self):
        fpath = os.path.join(CURRENT_DIR, "netcdf_dummy_file.nc")

        with open(fpath, 'rb') as f:
            nc_bytes = f.read()

            if not netCDF4.__has_nc_open_mem__:
                with self.assertRaises(ValueError):
                    netCDF4.Dataset('foo_bar', memory=nc_bytes)
                return

            # Needs: https://github.com/Unidata/netcdf-c/pull/400
            if netCDF4.__netcdf4libversion__ < '4.4.1.2':
                with self.assertRaises(OSError):
                    netCDF4.Dataset('foo_bar', memory=nc_bytes)
                return

            with netCDF4.Dataset('foo_bar', memory=nc_bytes) as nc:
                assert nc.filepath() == 'foo_bar'
                assert nc.project_summary == 'Dummy netCDF file'

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