mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-14 16:27:13 +03:00
JournalLock: Fix update_lock() with an extra mock
* update_lock() wants to, potentially, invoke JournalLock.JournalAlreadyLocked() instance for a tkinter pop-up. We do *not* want to mock all of that, so monkeypatch a mock so that in the 'test PASSED' case this just works.
This commit is contained in:
parent
8c74d46368
commit
baca42f06e
@ -120,7 +120,7 @@ class TestJournalLock:
|
||||
def get_str(key: str, *, default: str = None) -> str:
|
||||
"""Mock config.*Config get_str to provide fake journaldir."""
|
||||
if key == 'journaldir':
|
||||
return tmpdir_factory.mktemp()
|
||||
return tmpdir_factory.mktemp("changing")
|
||||
|
||||
print('Other key, calling up ...')
|
||||
return config.get_str(key) # Call the non-mocked
|
||||
@ -129,6 +129,17 @@ class TestJournalLock:
|
||||
m.setattr(config, "get_str", get_str)
|
||||
yield tmpdir_factory
|
||||
|
||||
@pytest.fixture
|
||||
def mock_journalalreadylocked(self, monkeypatch: _pytest_monkeypatch) -> JournalLock:
|
||||
"""Fixture to mock JournalAlreadyLocked in JournalLock instance."""
|
||||
class MockJournalAlreadyLocked:
|
||||
def __init__(self, parent, callback) -> None:
|
||||
pass
|
||||
|
||||
with monkeypatch.context() as m:
|
||||
m.setattr(JournalLock, "JournalAlreadyLocked", MockJournalAlreadyLocked)
|
||||
yield
|
||||
|
||||
###########################################################################
|
||||
# Tests against JournalLock.__init__()
|
||||
def test_journal_lock_init(self, mock_journaldir: py_path_local_LocalPath):
|
||||
@ -295,7 +306,10 @@ class TestJournalLock:
|
||||
|
||||
###########################################################################
|
||||
# Tests against JournalLock.update_lock()
|
||||
def test_update_lock(self, mock_journaldir_changing: py_path_local_LocalPath):
|
||||
def test_update_lock(
|
||||
self,
|
||||
mock_journaldir_changing: py_path_local_LocalPath,
|
||||
mock_journalalreadylocked):
|
||||
"""
|
||||
Test JournalLock.update_lock().
|
||||
|
||||
@ -312,6 +326,6 @@ class TestJournalLock:
|
||||
# Now store the 'current' journaldir for reference and attempt
|
||||
# to update to a new one.
|
||||
old_journaldir = jlock.journal_dir
|
||||
jlock.update_lock()
|
||||
assert jlock.journaldir != old_journaldir
|
||||
jlock.update_lock(None)
|
||||
assert jlock.journal_dir != old_journaldir
|
||||
assert jlock.locked is True
|
||||
|
Loading…
x
Reference in New Issue
Block a user