Ejemplo n.º 1
0
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"]
Ejemplo n.º 2
0
    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"])
Ejemplo n.º 3
0
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"]
Ejemplo n.º 4
0
    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"])
Ejemplo n.º 5
0
def split_file(file, n_splits):
    for i in range(n_splits):
        yield jsonql.SplitFile(file, i, n_splits)