From 2f3fc40d39562ffa62e77863df8316becd353dee Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Wed, 18 Dec 2024 21:54:32 +0300 Subject: [PATCH 1/3] OsOperations.isdir is added It a correction of base interface - OsOperations. It seems we forgot to add a declaration of the "abstract" method "isdir". --- testgres/operations/os_ops.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/testgres/operations/os_ops.py b/testgres/operations/os_ops.py index 2ab41246..d644509a 100644 --- a/testgres/operations/os_ops.py +++ b/testgres/operations/os_ops.py @@ -107,6 +107,9 @@ def read_binary(self, filename, start_pos): def isfile(self, remote_file): raise NotImplementedError() + def isdir(self, dirname): + raise NotImplementedError() + def get_file_size(self, filename): raise NotImplementedError() From 9f527435b28b3c9655d66ef7a2b5a120d767786d Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Wed, 18 Dec 2024 21:57:37 +0300 Subject: [PATCH 2/3] Tests for LocalOperations methods isdir and isfile are added --- tests/test_local.py | 64 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/tests/test_local.py b/tests/test_local.py index a8a0bde0..e223b090 100644 --- a/tests/test_local.py +++ b/tests/test_local.py @@ -118,3 +118,67 @@ def test_get_file_size__unk_file(self): with pytest.raises(FileNotFoundError, match=re.escape("[Errno 2] No such file or directory: '/dummy'")): self.operations.get_file_size("/dummy") + + def test_isfile_true(self): + """ + Test isfile for an existing file. + """ + filename = __file__ + + response = self.operations.isfile(filename) + + assert response is True + + def test_isfile_false__not_exist(self): + """ + Test isfile for a non-existing file. + """ + filename = os.path.join(os.path.dirname(__file__), "nonexistent_file.txt") + + response = self.operations.isfile(filename) + + assert response is False + + def test_isfile_false__directory(self): + """ + Test isfile for a firectory. + """ + name = os.path.dirname(__file__) + + assert self.operations.isdir(name) + + response = self.operations.isfile(name) + + assert response is False + + def test_isdir_true(self): + """ + Test isdir for an existing directory. + """ + name = os.path.dirname(__file__) + + response = self.operations.isdir(name) + + assert response is True + + def test_isdir_false__not_exist(self): + """ + Test isdir for a non-existing directory. + """ + name = os.path.join(os.path.dirname(__file__), "it_is_nonexistent_directory") + + response = self.operations.isdir(name) + + assert response is False + + def test_isdir_false__file(self): + """ + Test isdir for a file. + """ + name = __file__ + + assert self.operations.isfile(name) + + response = self.operations.isdir(name) + + assert response is False From 38ce127ec63189d4a35d1f73232435538329ef93 Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Wed, 18 Dec 2024 21:58:30 +0300 Subject: [PATCH 3/3] Tests for RemoteOperations methods isdir and isfile are updated --- tests/test_remote.py | 50 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/tests/test_remote.py b/tests/test_remote.py index be1a56bb..67d66549 100755 --- a/tests/test_remote.py +++ b/tests/test_remote.py @@ -259,18 +259,62 @@ def test_isfile_true(self): """ Test isfile for an existing file. """ - filename = "/etc/hosts" + filename = __file__ response = self.operations.isfile(filename) assert response is True - def test_isfile_false(self): + def test_isfile_false__not_exist(self): """ Test isfile for a non-existing file. """ - filename = "/nonexistent_file.txt" + filename = os.path.join(os.path.dirname(__file__), "nonexistent_file.txt") response = self.operations.isfile(filename) assert response is False + + def test_isfile_false__directory(self): + """ + Test isfile for a firectory. + """ + name = os.path.dirname(__file__) + + assert self.operations.isdir(name) + + response = self.operations.isfile(name) + + assert response is False + + def test_isdir_true(self): + """ + Test isdir for an existing directory. + """ + name = os.path.dirname(__file__) + + response = self.operations.isdir(name) + + assert response is True + + def test_isdir_false__not_exist(self): + """ + Test isdir for a non-existing directory. + """ + name = os.path.join(os.path.dirname(__file__), "it_is_nonexistent_directory") + + response = self.operations.isdir(name) + + assert response is False + + def test_isdir_false__file(self): + """ + Test isdir for a file. + """ + name = __file__ + + assert self.operations.isfile(name) + + response = self.operations.isdir(name) + + assert response is False