From 6590507de5ecce564ff66f0fb4c7be55e09af73c Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Tue, 18 Feb 2025 14:42:23 +0300 Subject: [PATCH 1/2] OsOperations::cwd() is corrected This patch fixes the following problems: - It does not work on Windows - It always returns LOCAL path --- testgres/operations/local_ops.py | 3 +++ testgres/operations/os_ops.py | 7 +------ testgres/operations/remote_ops.py | 5 +++++ tests/test_local.py | 17 +++++++++++++++++ tests/test_remote.py | 10 ++++++++++ 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/testgres/operations/local_ops.py b/testgres/operations/local_ops.py index 8bdb22cd..fc3e3954 100644 --- a/testgres/operations/local_ops.py +++ b/testgres/operations/local_ops.py @@ -152,6 +152,9 @@ def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False, def environ(self, var_name): return os.environ.get(var_name) + def cwd(self): + return os.getcwd() + def find_executable(self, executable): return find_executable(executable) diff --git a/testgres/operations/os_ops.py b/testgres/operations/os_ops.py index 35525b3c..00880863 100644 --- a/testgres/operations/os_ops.py +++ b/testgres/operations/os_ops.py @@ -1,6 +1,5 @@ import getpass import locale -import sys try: import psycopg2 as pglib # noqa: F401 @@ -39,11 +38,7 @@ def environ(self, var_name): raise NotImplementedError() def cwd(self): - if sys.platform == 'linux': - cmd = 'pwd' - elif sys.platform == 'win32': - cmd = 'cd' - return self.exec_command(cmd).decode().rstrip() + raise NotImplementedError() def find_executable(self, executable): raise NotImplementedError() diff --git a/testgres/operations/remote_ops.py b/testgres/operations/remote_ops.py index 2f34ecec..5af6f1cd 100644 --- a/testgres/operations/remote_ops.py +++ b/testgres/operations/remote_ops.py @@ -138,6 +138,11 @@ def environ(self, var_name: str) -> str: cmd = "echo ${}".format(var_name) return self.exec_command(cmd, encoding=get_default_encoding()).strip() + def cwd(self): + assert platform.system().lower() == "linux" + cmd = 'pwd' + return self.exec_command(cmd, encoding=get_default_encoding()).rstrip() + def find_executable(self, executable): search_paths = self.environ("PATH") if not search_paths: diff --git a/tests/test_local.py b/tests/test_local.py index d7adce17..568a4bc5 100644 --- a/tests/test_local.py +++ b/tests/test_local.py @@ -256,3 +256,20 @@ def test_isdir_false__file(self): response = self.operations.isdir(name) assert response is False + + def test_cwd(self): + """ + Test cwd. + """ + v = self.operations.cwd() + + assert v is not None + assert type(v) == str # noqa: E721 + + expectedValue = os.getcwd() + assert expectedValue is not None + assert type(expectedValue) == str # noqa: E721 + assert expectedValue != "" # research + + # Comp result + assert v == expectedValue diff --git a/tests/test_remote.py b/tests/test_remote.py index 7071a9d9..30c5d348 100755 --- a/tests/test_remote.py +++ b/tests/test_remote.py @@ -392,3 +392,13 @@ def test_isdir_false__file(self): response = self.operations.isdir(name) assert response is False + + def test_cwd(self): + """ + Test cwd. + """ + v = self.operations.cwd() + + assert v is not None + assert type(v) == str # noqa: E721 + assert v != "" From b2655b85bd3a2d08996ec1ce9ab921819fba0997 Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Wed, 19 Feb 2025 08:32:40 +0300 Subject: [PATCH 2/2] RemoteOperations::cwd(self) is updated (cleanup) Ok. This class for linux only. Additional internal debug checks are not required. Copy&Paste code from this class at your risk. --- testgres/operations/remote_ops.py | 1 - 1 file changed, 1 deletion(-) diff --git a/testgres/operations/remote_ops.py b/testgres/operations/remote_ops.py index 5af6f1cd..3ebc2e60 100644 --- a/testgres/operations/remote_ops.py +++ b/testgres/operations/remote_ops.py @@ -139,7 +139,6 @@ def environ(self, var_name: str) -> str: return self.exec_command(cmd, encoding=get_default_encoding()).strip() def cwd(self): - assert platform.system().lower() == "linux" cmd = 'pwd' return self.exec_command(cmd, encoding=get_default_encoding()).rstrip()