Skip to content

Commit

Permalink
Python Wrapper: Fix reader iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
N-o-Z committed Dec 10, 2023
1 parent 0787698 commit 9b07c39
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
5 changes: 4 additions & 1 deletion clients/python-wrapper/lakefs/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ def writelines(self, lines: List[AnyStr]) -> None:
raise io.UnsupportedOperation

def __next__(self) -> AnyStr:
return self.readline()
line = self.readline()
if len(line) == 0:
raise StopIteration
return line

def __iter__(self) -> Iterator[AnyStr]:
return self
Expand Down
23 changes: 23 additions & 0 deletions clients/python-wrapper/tests/integration/test_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,26 @@ def test_readline_partial_line_buffer(setup_repo):
assert read == expected

assert reader.read() == ""


def test_write_read_csv(setup_repo):
_, repo = setup_repo
columns = ["ID", "Name", "Email"]
sample_data = [
['1', "Alice", "[email protected]"],
['2', "Bob", "[email protected]"],
['3', "Carol", "[email protected]"],
]
obj = repo.branch("main").object(path="csv/sample_data.csv")

with obj.writer(mode='w', pre_sign=False, content_type="text/csv") as fd:
writer = csv.writer(fd)
writer.writerow(columns)
for row in sample_data:
writer.writerow(row)

for i, row in enumerate(csv.reader(obj.reader(mode='r'))):
if i == 0:
assert row == columns
else:
assert row == sample_data[i - 1]

0 comments on commit 9b07c39

Please sign in to comment.