File: test_no_iter_contains.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 (34 lines) | stat: -rw-r--r-- 1,095 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
32
33
34
import os
import tempfile
import unittest

import netCDF4

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


class TestNoIterNoContains(unittest.TestCase):
    def setUp(self) -> None:
        self.file = FILE_NAME
        with netCDF4.Dataset(self.file, "w") as dataset:
            # just create a simple variable
            dataset.createVariable("var1", int)

    def tearDown(self) -> None:
        os.remove(self.file)

    def test_no_iter(self) -> None:
        """Verify that iteration is explicitly not supported"""
        with netCDF4.Dataset(self.file, "r") as dataset:
            with self.assertRaises(TypeError):
                for _ in dataset:  # type: ignore  # type checker catches that this doesn't work
                    pass

    def test_no_contains(self) -> None:
        """Verify the membership operations are explicity not supported"""
        with netCDF4.Dataset(self.file, "r") as dataset:
            with self.assertRaises(TypeError):
                _ = "var1" in dataset

if __name__ == "__main__":
    unittest.main(verbosity=2)