def test_bz2_stream(): text = '\n'.join(map(str, range(10000))) compressed = bz2.compress(text.encode()) assert (list(take(100, bz2_stream(compressed))) == list(map(lambda x: str(x) + '\n', range(100))))