import tempfile
from pathlib import Path

import layercake.jsonl as jsonl


def test_readlines():
    with tempfile.NamedTemporaryFile() as fp:
        fp.writelines([b'{}\n' for _ in range(4)])
        fp.seek(0)

        with jsonl.readlines(fp.name) as lines:
            assert sum(1 for _ in lines) == 4

    with jsonl.readlines(Path('notfound.jsonl')) as lines:
        assert sum(1 for _ in lines) == 0

    with jsonl.readlines(Path('notfound.jsonl')) as lines:
        assert list(lines) == []
