mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-08 19:32:15 +03:00
Move test & fixture into a class.
This is for then adding more tests.
This commit is contained in:
parent
c344d612ad
commit
7bd6e8ff58
@ -43,28 +43,30 @@ from config import config
|
|||||||
from journal_lock import JournalLock
|
from journal_lock import JournalLock
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
class TestJournalLock:
|
||||||
def mock_journaldir(monkeypatch: _pytest_monkeypatch, tmpdir: _pytest_tmpdir) -> py_path_local_LocalPath:
|
"""JournalLock test class."""
|
||||||
"""Fixture for mocking config.get_str('journaldir')."""
|
|
||||||
def get_str(key: str, *, default: str = None) -> str:
|
|
||||||
"""Mock config.*Config get_str to provide fake journaldir."""
|
|
||||||
if key == 'journaldir':
|
|
||||||
print(f'journaldir: using tmpdir: {tmpdir}')
|
|
||||||
return tmpdir
|
|
||||||
|
|
||||||
print('Other key, calling up ...')
|
@pytest.fixture
|
||||||
return config.get_str(key) # Call the non-mocked
|
def mock_journaldir(self, monkeypatch: _pytest_monkeypatch, tmpdir: _pytest_tmpdir) -> py_path_local_LocalPath:
|
||||||
|
"""Fixture for mocking config.get_str('journaldir')."""
|
||||||
|
def get_str(key: str, *, default: str = None) -> str:
|
||||||
|
"""Mock config.*Config get_str to provide fake journaldir."""
|
||||||
|
if key == 'journaldir':
|
||||||
|
print(f'journaldir: using tmpdir: {tmpdir}')
|
||||||
|
return tmpdir
|
||||||
|
|
||||||
with monkeypatch.context() as m:
|
print('Other key, calling up ...')
|
||||||
m.setattr(config, "get_str", get_str)
|
return config.get_str(key) # Call the non-mocked
|
||||||
yield tmpdir
|
|
||||||
|
|
||||||
|
with monkeypatch.context() as m:
|
||||||
|
m.setattr(config, "get_str", get_str)
|
||||||
|
yield tmpdir
|
||||||
|
|
||||||
def test_journal_lock_init(mock_journaldir: py_path_local_LocalPath):
|
def test_journal_lock_init(self, mock_journaldir: py_path_local_LocalPath):
|
||||||
"""Test JournalLock instantiation."""
|
"""Test JournalLock instantiation."""
|
||||||
tmpdir = mock_journaldir
|
tmpdir = mock_journaldir
|
||||||
|
|
||||||
jlock = JournalLock()
|
jlock = JournalLock()
|
||||||
assert jlock.journal_dir == tmpdir
|
assert jlock.journal_dir == tmpdir
|
||||||
assert jlock.journal_dir_path is not None
|
assert jlock.journal_dir_path is not None
|
||||||
assert jlock.journal_dir_lockfile_name is None
|
assert jlock.journal_dir_lockfile_name is None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user