1import pytest
2
3from .common import TestCase
4from h5py import File
5
6
7class SampleException(Exception):
8    pass
9
10def throwing(name, obj):
11    print(name, obj)
12    raise SampleException("throwing exception")
13
14class TestVisit(TestCase):
15    def test_visit(self):
16        fname = self.mktemp()
17        fid = File(fname, 'w')
18        fid.create_dataset('foo', (100,), dtype='uint8')
19        with pytest.raises(SampleException, match='throwing exception'):
20            fid.visititems(throwing)
21        fid.close()
22