def test_blocks(): source = Source(path.join(here, 'files/1234')) with source: for (read, expected) in zip(source.blocks(2), (b'\x01\x02', b'\x03\x04')): assert read == expected with source: generator = source.blocks(2) assert next(generator) == b'\x01\x02' assert next(generator) == b'\x03\x04' with pytest.raises(StopIteration): next(generator) raise AssertionError('StopIteration should have been raised')