[lang-ref] ( example_file_line_count ) ( python )
def test_example_file_line_count(tmp_path):
# sum(1 for _ in f)
lines = ['test message %03d\n' % x for x in range(5)]
text = ''.join(lines)
p = tmp_path / 'a.txt'
with p.open('w') as f:
f.write(text)
with p.open(encoding="utf-8") as f:
ct = sum(1 for _ in f)
assert ct == 5