Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Refactoring of tests #232

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 17 additions & 14 deletions tests/test_local.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,52 @@
# coding: utf-8
from .helpers.os_ops_descrs import OsOpsDescrs
from .helpers.os_ops_descrs import OsOperations

import os

import pytest
import re

from ..testgres import LocalOperations


class TestLocalOperations:
@pytest.fixture
def os_ops(self):
return OsOpsDescrs.sm_local_os_ops

@pytest.fixture(scope="function", autouse=True)
def setup(self):
self.operations = LocalOperations()

def test_read__unknown_file(self):
def test_read__unknown_file(self, os_ops: OsOperations):
"""
Test LocalOperations::read with unknown file.
"""

with pytest.raises(FileNotFoundError, match=re.escape("[Errno 2] No such file or directory: '/dummy'")):
self.operations.read("/dummy")
os_ops.read("/dummy")

def test_read_binary__spec__unk_file(self):
def test_read_binary__spec__unk_file(self, os_ops: OsOperations):
"""
Test LocalOperations::read_binary with unknown file.
"""

with pytest.raises(
FileNotFoundError,
match=re.escape("[Errno 2] No such file or directory: '/dummy'")):
self.operations.read_binary("/dummy", 0)
os_ops.read_binary("/dummy", 0)

def test_get_file_size__unk_file(self):
def test_get_file_size__unk_file(self, os_ops: OsOperations):
"""
Test LocalOperations::get_file_size.
"""
assert isinstance(os_ops, OsOperations)

with pytest.raises(FileNotFoundError, match=re.escape("[Errno 2] No such file or directory: '/dummy'")):
self.operations.get_file_size("/dummy")
os_ops.get_file_size("/dummy")

def test_cwd(self):
def test_cwd(self, os_ops: OsOperations):
"""
Test cwd.
"""
v = self.operations.cwd()
assert isinstance(os_ops, OsOperations)

v = os_ops.cwd()

assert v is not None
assert type(v) == str # noqa: E721
Expand Down
47 changes: 26 additions & 21 deletions tests/test_remote.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
# coding: utf-8
import os

import pytest
from .helpers.os_ops_descrs import OsOpsDescrs
from .helpers.os_ops_descrs import OsOperations

from ..testgres import ExecUtilException
from ..testgres import RemoteOperations
from ..testgres import ConnectionParams

import os
import pytest


class TestRemoteOperations:
@pytest.fixture
def os_ops(self):
return OsOpsDescrs.sm_remote_os_ops

@pytest.fixture(scope="function", autouse=True)
def setup(self):
conn_params = ConnectionParams(host=os.getenv('RDBMS_TESTPOOL1_HOST') or '127.0.0.1',
username=os.getenv('USER'),
ssh_key=os.getenv('RDBMS_TESTPOOL_SSHKEY'))
self.operations = RemoteOperations(conn_params)
def test_rmdirs__try_to_delete_nonexist_path(self, os_ops: OsOperations):
assert isinstance(os_ops, OsOperations)

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

assert self.operations.rmdirs(path, ignore_errors=False) is True
assert os_ops.rmdirs(path, ignore_errors=False) is True

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

def test_rmdirs__try_to_delete_file(self):
path = self.operations.mkstemp()
path = os_ops.mkstemp()
assert type(path) == str # noqa: E721
assert os.path.exists(path)

with pytest.raises(ExecUtilException) as x:
self.operations.rmdirs(path, ignore_errors=False)
os_ops.rmdirs(path, ignore_errors=False)

assert os.path.exists(path)
assert type(x.value) == ExecUtilException # noqa: E721
Expand All @@ -37,37 +39,40 @@ 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_read__unknown_file(self):
def test_read__unknown_file(self, os_ops: OsOperations):
"""
Test RemoteOperations::read with unknown file.
"""
assert isinstance(os_ops, OsOperations)

with pytest.raises(ExecUtilException) as x:
self.operations.read("/dummy")
os_ops.read("/dummy")

assert "Utility exited with non-zero code (1)." in str(x.value)
assert "No such file or directory" in str(x.value)
assert "/dummy" in str(x.value)

def test_read_binary__spec__unk_file(self):
def test_read_binary__spec__unk_file(self, os_ops: OsOperations):
"""
Test RemoteOperations::read_binary with unknown file.
"""
assert isinstance(os_ops, OsOperations)

with pytest.raises(ExecUtilException) as x:
self.operations.read_binary("/dummy", 0)
os_ops.read_binary("/dummy", 0)

assert "Utility exited with non-zero code (1)." in str(x.value)
assert "No such file or directory" in str(x.value)
assert "/dummy" in str(x.value)

def test_get_file_size__unk_file(self):
def test_get_file_size__unk_file(self, os_ops: OsOperations):
"""
Test RemoteOperations::get_file_size.
"""
assert isinstance(os_ops, OsOperations)

with pytest.raises(ExecUtilException) as x:
self.operations.get_file_size("/dummy")
os_ops.get_file_size("/dummy")

assert "Utility exited with non-zero code (1)." in str(x.value)
assert "No such file or directory" in str(x.value)
Expand Down