Content-Length: 4948 | pFad | http://github.com/postgrespro/testgres/pull/173.patch
thub.com
From 2c1dd97fac0053e0b61ab917838e5f88ecaead6b Mon Sep 17 00:00:00 2001
From: "d.kovalenko"
Date: Wed, 25 Dec 2024 18:11:09 +0300
Subject: [PATCH] OsOps::read_binary is updated (offset)
- the parameter 'start_pos' is renamed with 'offset'
- we raise a runtime-error when 'offset' is negative
Tests are added.
---
testgres/operations/local_ops.py | 10 ++++++----
testgres/operations/os_ops.py | 6 +++---
testgres/operations/remote_ops.py | 10 ++++++----
tests/test_local.py | 10 ++++++++++
tests/test_remote.py | 10 ++++++++++
5 files changed, 35 insertions(+), 11 deletions(-)
diff --git a/testgres/operations/local_ops.py b/testgres/operations/local_ops.py
index c88c16ca..8bdb22cd 100644
--- a/testgres/operations/local_ops.py
+++ b/testgres/operations/local_ops.py
@@ -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
diff --git a/testgres/operations/os_ops.py b/testgres/operations/os_ops.py
index d644509a..35525b3c 100644
--- a/testgres/operations/os_ops.py
+++ b/testgres/operations/os_ops.py
@@ -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
- assert start_pos >= 0
+ assert type(offset) == int # noqa: E721
+ assert offset >= 0
raise NotImplementedError()
def isfile(self, remote_file):
diff --git a/testgres/operations/remote_ops.py b/testgres/operations/remote_ops.py
index c0307195..2f34ecec 100644
--- a/testgres/operations/remote_ops.py
+++ b/testgres/operations/remote_ops.py
@@ -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
diff --git a/tests/test_local.py b/tests/test_local.py
index 47a63994..d7adce17 100644
--- a/tests/test_local.py
+++ b/tests/test_local.py
@@ -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.
diff --git a/tests/test_remote.py b/tests/test_remote.py
index 7421ca3a..7071a9d9 100755
--- a/tests/test_remote.py
+++ b/tests/test_remote.py
@@ -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.
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/postgrespro/testgres/pull/173.patch
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy