File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ import os
2
+ import tempfile
3
+ import unittest
4
+
5
+ import netCDF4
6
+
7
+ FILE_NAME = tempfile .NamedTemporaryFile (suffix = '.nc' , delete = False ).name
8
+
9
+
10
+ class TestNoIterNoContains (unittest .TestCase ):
11
+ def setUp (self ) -> None :
12
+ self .file = FILE_NAME
13
+ with netCDF4 .Dataset (self .file , "w" ) as dataset :
14
+ # just create a simple variable
15
+ dataset .createVariable ("var1" , int )
16
+
17
+ def tearDown (self ) -> None :
18
+ os .remove (self .file )
19
+
20
+ def test_no_iter (self ) -> None :
21
+ """Verify that iteration is explicitly not supported"""
22
+ with netCDF4 .Dataset (self .file , "r" ) as dataset :
23
+ with self .assertRaises (TypeError ):
24
+ for _ in dataset : # type: ignore # type checker catches that this doesn't work
25
+ pass
26
+
27
+ def test_no_contains (self ) -> None :
28
+ """Verify the membership operations are explicity not supported"""
29
+ with netCDF4 .Dataset (self .file , "r" ) as dataset :
30
+ with self .assertRaises (TypeError ):
31
+ _ = "var1" in dataset
32
+
33
+ if __name__ == "__main__" :
34
+ unittest .main (verbosity = 2 )
You can’t perform that action at this time.
0 commit comments