8000 TestOsOpsCommon is added [generic os_ops tests] by dmitry-lipetsk · Pull Request #231 · postgrespro/testgres · GitHub
[go: up one dir, main page]

Skip to content

TestOsOpsCommon is added [generic os_ops tests] #231

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prev Previous commit
Next Next commit
TestOsOpsCommon is updated
New tests:
- test_rmdirs
- test_rmdirs__01_with_subfolder
- test_rmdirs__02_with_file
- test_rmdirs__03_with_subfolder_and_file
  • Loading branch information
dmitry-lipetsk committed Apr 2, 2025
commit 9f60705c6090defbc24a24240f32b161ab535ec8
67 changes: 67 additions & 0 deletions tests/test_os_ops_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,73 @@ def test_mkdtemp__custom(self, os_ops: OsOperations):
os.rmdir(path)
assert not os.path.exists(path)

def test_rmdirs(self, os_ops: OsOperations):
assert isinstance(os_ops, OsOperations)

path = os_ops.mkdtemp()
assert os.path.exists(path)

assert os_ops.rmdirs(path, ignore_errors=False) is True
assert not os.path.exists(path)

def test_rmdirs__01_with_subfolder(self, os_ops: OsOperations):
assert isinstance(os_ops, OsOperations)

# folder with subfolder
path = os_ops.mkdtemp()
assert os.path.exists(path)

dir1 = os.path.join(path, "dir1")
assert not os.path.exists(dir1)

os_ops.makedirs(dir1)
assert os.path.exists(dir1)

assert os_ops.rmdirs(path, ignore_errors=False) is True
assert not os.path.exists(path)
assert not os.path.exists(dir1)

def test_rmdirs__02_with_file(self, os_ops: OsOperations):
assert isinstance(os_ops, OsOperations)

# folder with file
path = os_ops.mkdtemp()
assert os.path.exists(path)

file1 = os.path.join(path, "file1.txt")
assert not os.path.exists(file1)

os_ops.touch(file1)
assert os.path.exists(file1)

assert os_ops.rmdirs(path, ignore_errors=False) is True
assert not os.path.exists(path)
assert not os.path.exists(file1)

def test_rmdirs__03_with_subfolder_and_file(self, os_ops: OsOperations):
assert isinstance(os_ops, OsOperations)

# folder with subfolder and file
path = os_ops.mkdtemp()
assert os.path.exists(path)

dir1 = os.path.join(path, "dir1")
assert not os.path.exists(dir1)

os_ops.makedirs(dir1)
assert os.path.exists(dir1)

file1 = os.path.join(dir1, "file1.txt")
assert not os.path.exists(file1)

os_ops.touch(file1)
assert os.path.exists(file1)

assert os_ops.rmdirs(path, ignore_errors=False) is True
assert not os.path.exists(path)
assert not os.path.exists(dir1)
assert not os.path.exists(file1)

def test_write_text_file(self, os_ops: OsOperations):
"""
Test write for writing data to a text file.
Expand Down
59 changes: 0 additions & 59 deletions tests/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,65 +17,6 @@ def setup(self):
ssh_key=os.getenv('RDBMS_TESTPOOL_SSHKEY'))
self.operations = RemoteOperations(conn_params)

def test_rmdirs(self):
path = self.operations.mkdtemp()
assert os.path.exists(path)

assert self.operations.rmdirs(path, ignore_errors=False) is True
assert not os.path.exists(path)

def test_rmdirs__01_with_subfolder(self):
# folder with subfolder
path = self.operations.mkdtemp()
assert os.path.exists(path)

dir1 = os.path.join(path, "dir1")
assert not os.path.exists(dir1)

self.operations.makedirs(dir1)
assert os.path.exists(dir1)

assert self.operations.rmdirs(path, ignore_errors=False) is True
assert not os.path.exists(path)
assert not os.path.exists(dir1)

def test_rmdirs__02_with_file(self):
# folder with file
path = self.operations.mkdtemp()
assert os.path.exists(path)

file1 = os.path.join(path, "file1.txt")
assert not os.path.exists(file1)

self.operations.touch(file1)
assert os.path.exists(file1)

assert self.operations.rmdirs(path, ignore_errors=False) is True
assert not os.path.exists(path)
assert not os.path.exists(file1)

def test_rmdirs__03_with_subfolder_and_file(self):
# folder with subfolder and file
path = self.operations.mkdtemp()
assert os.path.exists(path)

dir1 = os.path.join(path, "dir1")
assert not os.path.exists(dir1)

self.operations.makedirs(dir1)
assert os.path.exists(dir1)

file1 = os.path.join(dir1, "file1.txt")
assert not os.path.exists(file1)

self.operations.touch(file1)
assert os.path.exists(file1)

assert self.operations.rmdirs(path, ignore_errors=False) is True
assert not os.path.exists(path)
assert not os.path.exists(dir1)
assert not os.path.exists(file1)

def test_rmdirs__try_to_delete_nonexist_path(self):
path = "/root/test_dir"

Expand Down
0