Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

OsOps::read_binary is updated (offset)#173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletionstestgres/operations/local_ops.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -331,13 +331,15 @@ def readlines(self, filename, num_lines=0, binary=False, encoding=None):
buffers * max(2, int(num_lines / max(cur_lines, 1)))
) # Adjust buffer size

def read_binary(self, filename,start_pos):
def read_binary(self, filename,offset):
assert type(filename) == str # noqa: E721
assert type(start_pos) == int # noqa: E721
assert start_pos >= 0
assert type(offset) == int # noqa: E721

if offset < 0:
raise ValueError("Negative 'offset' is not supported.")

with open(filename, 'rb') as file: # open in a binary mode
file.seek(start_pos, os.SEEK_SET)
file.seek(offset, os.SEEK_SET)
r = file.read()
assert type(r) == bytes # noqa: E721
return r
Expand Down
6 changes: 3 additions & 3 deletionstestgres/operations/os_ops.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -98,10 +98,10 @@ def read(self, filename, encoding, binary):
def readlines(self, filename):
raise NotImplementedError()

def read_binary(self, filename,start_pos):
def read_binary(self, filename,offset):
assert type(filename) == str # noqa: E721
assert type(start_pos) == int # noqa: E721
assertstart_pos >= 0
assert type(offset) == int # noqa: E721
assertoffset >= 0
raise NotImplementedError()

def isfile(self, remote_file):
Expand Down
10 changes: 6 additions & 4 deletionstestgres/operations/remote_ops.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -370,12 +370,14 @@ def readlines(self, filename, num_lines=0, binary=False, encoding=None):

return lines

def read_binary(self, filename,start_pos):
def read_binary(self, filename,offset):
assert type(filename) == str # noqa: E721
assert type(start_pos) == int # noqa: E721
assert start_pos >= 0
assert type(offset) == int # noqa: E721

cmd = ["tail", "-c", "+{}".format(start_pos + 1), filename]
if offset < 0:
raise ValueError("Negative 'offset' is not supported.")

cmd = ["tail", "-c", "+{}".format(offset + 1), filename]
r = self.exec_command(cmd)
assert type(r) == bytes # noqa: E721
return r
Expand Down
10 changes: 10 additions & 0 deletionstests/test_local.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -162,6 +162,16 @@ def test_read_binary__spec__unk_file(self):
match=re.escape("[Errno 2] No such file or directory: '/dummy'")):
self.operations.read_binary("/dummy", 0)

def test_read_binary__spec__negative_offset(self):
"""
Test LocalOperations::read_binary with negative offset.
"""

with pytest.raises(
ValueError,
match=re.escape("Negative 'offset' is not supported.")):
self.operations.read_binary(__file__, -1)

def test_get_file_size(self):
"""
Test LocalOperations::get_file_size.
Expand Down
10 changes: 10 additions & 0 deletionstests/test_remote.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -288,6 +288,16 @@ def test_read_binary__spec__unk_file(self):
with pytest.raises(ExecUtilException, match=re.escape("tail: cannot open '/dummy' for reading: No such file or directory")):
self.operations.read_binary("/dummy", 0)

def test_read_binary__spec__negative_offset(self):
"""
Test RemoteOperations::read_binary with negative offset.
"""

with pytest.raises(
ValueError,
match=re.escape("Negative 'offset' is not supported.")):
self.operations.read_binary(__file__, -1)

def test_get_file_size(self):
"""
Test RemoteOperations::get_file_size.
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp