Skip to content

Commit 607d7d5

Browse files
Add test case for explicitly disallowed __iter__ and __contains__
1 parent 561b9e9 commit 607d7d5

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/test_no_iter_contains.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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)

0 commit comments

Comments
 (0)