-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_recent_lines.py
More file actions
24 lines (18 loc) · 856 Bytes
/
test_recent_lines.py
File metadata and controls
24 lines (18 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import tempfile
import unittest
from pathlib import Path
from poly_strategy.recent_lines import read_recent_lines
class RecentLinesTests(unittest.TestCase):
def test_read_recent_lines_returns_tail_without_trailing_newline(self):
with tempfile.TemporaryDirectory() as tmp:
path = Path(tmp) / "rows.ndjson"
path.write_text("a\nb\nc")
self.assertEqual(read_recent_lines(path, max_lines=2, chunk_size=2), ["b", "c"])
def test_read_recent_lines_validates_limits(self):
with tempfile.TemporaryDirectory() as tmp:
path = Path(tmp) / "rows.ndjson"
path.write_text("a\n")
with self.assertRaises(ValueError):
read_recent_lines(path, max_lines=0)
with self.assertRaises(ValueError):
read_recent_lines(path, chunk_size=0)