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
Changes from 1 commit
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
Next Next commit
TestLocalOperations is refactored
- [del] setup
- [add] fixture: os_ops
  • Loading branch information
dmitry-lipetsk committed Apr 2, 2025
commit e5be783f430880286f408927bd9aacbd30651069
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