Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
11 commits
Select commitHold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext 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
dmitry-lipetsk committedApr 2, 2025
commit6e45c150ad5b5e3fe832d274faef5029e97d84d2
11 changes: 0 additions & 11 deletionstests/test_local.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionstests/test_os_ops_common.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionstests/test_remote.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,6 @@
import os

import pytest
import re
import logging

from ..testgres import ExecUtilException
Expand DownExpand 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

[8]ページ先頭

©2009-2025 Movatter.jp