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_listdir
- test_path_exists_true__directory
- test_path_exists_true__file
- test_path_exists_false__directory
- test_path_exists_false__file
- test_write_text_file
- test_write_binary_file
- test_read_text_file
- test_read_binary_file
  • Loading branch information
dmitry-lipetsk committed Apr 2, 2025
commit 6e45c150ad5b5e3fe832d274faef5029e97d84d2
11 changes: 0 additions & 11 deletions tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,6 @@ def test_exec_command_failure__expect_error(self):
assert b"nonexistent_command" in error
assert b"not found" in error

def test_listdir(self):
"""
Test listdir for listing directory contents.
"""
path = "/etc"
files = self.operations.listdir(path)
assert isinstance(files, list)
for f in files:
assert f is not None
assert type(f) == str # noqa: E721

def test_read__unknown_file(self):
"""
Test LocalOperations::read with unknown file.
Expand Down
119 changes: 119 additions & 0 deletions tests/test_os_ops_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .helpers.os_ops_descrs import OsOpsDescr
from .helpers.os_ops_descrs import OsOpsDescrs
from .helpers.os_ops_descrs import OsOperations
from .helpers.run_conditions import RunConditions

import os

Expand All @@ -27,6 +28,124 @@ def os_ops(self, request: pytest.FixtureRequest) -> OsOperations:
assert isinstance(request.param, OsOperations)
return request.param

def test_listdir(self, os_ops: OsOperations):
"""
Test listdir for listing directory contents.
"""
assert isinstance(os_ops, OsOperations)

RunConditions.skip_if_windows()

path = "/etc"
files = os_ops.listdir(path)
assert isinstance(files, list)
for f in files:
assert f is not None
assert type(f) == str # noqa: E721

def test_path_exists_true__directory(self, os_ops: OsOperations):
"""
Test path_exists for an existing directory.
"""
assert isinstance(os_ops, OsOperations)

RunConditions.skip_if_windows()

assert os_ops.path_exists("/etc") is True

def test_path_exists_true__file(self, os_ops: OsOperations):
"""
Test path_exists for an existing file.
"""
assert isinstance(os_ops, OsOperations)

RunConditions.skip_if_windows()

assert os_ops.path_exists(__file__) is True

def test_path_exists_false__directory(self, os_ops: OsOperations):
"""
Test path_exists for a non-existing directory.
"""
assert isinstance(os_ops, OsOperations)

RunConditions.skip_if_windows()

assert os_ops.path_exists("/nonexistent_path") is False

def test_path_exists_false__file(self, os_ops: OsOperations):
"""
Test path_exists for a non-existing file.
"""
assert isinstance(os_ops, OsOperations)

RunConditions.skip_if_windows()

assert os_ops.path_exists("/etc/nonexistent_path.txt") is False

def test_write_text_file(self, os_ops: OsOperations):
"""
Test write for writing data to a text file.
"""
assert isinstance(os_ops, OsOperations)

RunConditions.skip_if_windows()

filename = "/tmp/test_file.txt"
data = "Hello, world!"

os_ops.write(filename, data, truncate=True)
os_ops.write(filename, data)

response = os_ops.read(filename)

assert response == data + data

def test_write_binary_file(self, os_ops: OsOperations):
"""
Test write for writing data to a binary file.
"""
assert isinstance(os_ops, OsOperations)

RunConditions.skip_if_windows()

filename = "/tmp/test_file.bin"
data = b"\x00\x01\x02\x03"

os_ops.write(filename, data, binary=True, truncate=True)

response = os_ops.read(filename, binary=True)

assert response == data

def test_read_text_file(self, os_ops: OsOperations):
"""
Test read for reading data from a text file.
"""
assert isinstance(os_ops, OsOperations)

RunConditions.skip_if_windows()

filename = "/etc/hosts"

response = os_ops.read(filename)

assert isinstance(response, str)

def test_read_binary_file(self, os_ops: OsOperations):
"""
Test read for reading data from a binary file.
"""
assert isinstance(os_ops, OsOperations)

RunConditions.skip_if_windows()

filename = "/usr/bin/python3"

response = os_ops.read(filename, binary=True)

assert isinstance(response, bytes)

def test_read__text(self, os_ops: OsOperations):
"""
Test OsOperations::read for text data.
Expand Down
83 changes: 0 additions & 83 deletions tests/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os

import pytest
import re
import logging

from ..testgres import ExecUtilException
Expand Down Expand Up @@ -214,88 +213,6 @@ def test_rmdirs__try_to_delete_file(self):
assert type(x.value.exit_code) == int # noqa: E721
assert x.value.exit_code == 20

def test_listdir(self):
"""
Test listdir for listing directory contents.
"""
path = "/etc"
files = self.operations.listdir(path)
assert isinstance(files, list)
for f in files:
assert f is not None
assert type(f) == str # noqa: E721

def test_path_exists_true__directory(self):
"""
Test path_exists for an existing directory.
"""
assert self.operations.path_exists("/etc") is True

def test_path_exists_true__file(self):
"""
Test path_exists for an existing file.
"""
assert self.operations.path_exists(__file__) is True

def test_path_exists_false__directory(self):
"""
Test path_exists for a non-existing directory.
"""
assert self.operations.path_exists("/nonexistent_path") is False

def test_path_exists_false__file(self):
"""
Test path_exists for a non-existing file.
"""
assert self.operations.path_exists("/etc/nonexistent_path.txt") is False

def test_write_text_file(self):
"""
Test write for writing data to a text file.
"""
filename = "/tmp/test_file.txt"
data = "Hello, world!"

self.operations.write(filename, data, truncate=True)
self.operations.write(filename, data)

response = self.operations.read(filename)

assert response == data + data

def test_write_binary_file(self):
"""
Test write for writing data to a binary file.
"""
filename = "/tmp/test_file.bin"
data = b"\x00\x01\x02\x03"

self.operations.write(filename, data, binary=True, truncate=True)

response = self.operations.read(filename, binary=True)

assert response == data

def test_read_text_file(self):
"""
Test read for reading data from a text file.
"""
filename = "/etc/hosts"

response = self.operations.read(filename)

assert isinstance(response, str)

def test_read_binary_file(self):
"""
Test read for reading data from a binary file.
"""
filename = "/usr/bin/python3"

response = self.operations.read(filename, binary=True)

assert isinstance(response, bytes)

def test_read__unknown_file(self):
"""
Test RemoteOperations::read with unknown file.
Expand Down
0