def test_split_file(tmp_path: Path): file = tmp_path / "test.txt" content = "Hello\nWorld\n" with open(file, "w") as o: o.write(content) with jsonql.SplitFile(file, chunk=0, n_chunks=2) as f: assert f.readlines() == ["Hello\n"] with jsonql.SplitFile(file, chunk=1, n_chunks=2) as f: assert f.readlines() == ["World\n"]
def test_split_file(self): tmp = self.get_tmpdir() file = tmp("test.txt") content = "Hello\nWorld\n" with open(file, "w") as o: o.write(content) with jsonql.SplitFile(file, chunk=0, n_chunks=2) as f: self.assertEqual(f.readlines(), ["Hello\n"]) with jsonql.SplitFile(file, chunk=1, n_chunks=2) as f: self.assertEqual(f.readlines(), ["World\n"])
def test_split_file_middle_of_char(tmp_path: Path): file = tmp_path / "test.txt" content = "Hello\U0001F40D\nWorld\n" # split is here ^^ with open(file, "w") as o: o.write(content) with jsonql.SplitFile(file, chunk=0, n_chunks=2) as f: assert f.readlines() == ["Hello🐍\n"] with jsonql.SplitFile(file, chunk=1, n_chunks=2) as f: assert f.readlines() == ["World\n"]
def test_split_file_middle_of_char(self): tmp = self.get_tmpdir() file = tmp("test.txt") content = "Hello\U0001F40D\nWorld\n" # split is here ^^ with open(file, "w") as o: o.write(content) with jsonql.SplitFile(file, chunk=0, n_chunks=2) as f: self.assertEqual(f.readlines(), ["Hello🐍\n"]) with jsonql.SplitFile(file, chunk=1, n_chunks=2) as f: self.assertEqual(f.readlines(), ["World\n"])
def split_file(file, n_splits): for i in range(n_splits): yield jsonql.SplitFile(file, i, n_splits)