mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-17 17:42:20 +03:00
tests: journal: Change py
LocalPath type to be _pytest.tmpdir.TempPathFactory
This is more correct, and means we don't need the `py` module, which wasn't in requirements-dev.txt, causing GitHub workflow `pytest` runs to fail.
This commit is contained in:
parent
05a4922219
commit
0aa74b8755
@ -8,7 +8,6 @@ import pytest
|
|||||||
# Import as other names else they get picked up when used as fixtures
|
# Import as other names else they get picked up when used as fixtures
|
||||||
from _pytest import monkeypatch as _pytest_monkeypatch
|
from _pytest import monkeypatch as _pytest_monkeypatch
|
||||||
from _pytest import tmpdir as _pytest_tmpdir
|
from _pytest import tmpdir as _pytest_tmpdir
|
||||||
from py._path.local import LocalPath as py_path_local_LocalPath
|
|
||||||
|
|
||||||
from config import config
|
from config import config
|
||||||
from journal_lock import JournalLock, JournalLockResult
|
from journal_lock import JournalLock, JournalLockResult
|
||||||
@ -120,7 +119,7 @@ class TestJournalLock:
|
|||||||
def mock_journaldir(
|
def mock_journaldir(
|
||||||
self, monkeypatch: _pytest_monkeypatch,
|
self, monkeypatch: _pytest_monkeypatch,
|
||||||
tmp_path_factory: _pytest_tmpdir.TempPathFactory
|
tmp_path_factory: _pytest_tmpdir.TempPathFactory
|
||||||
) -> py_path_local_LocalPath:
|
) -> _pytest_tmpdir.TempPathFactory:
|
||||||
"""Fixture for mocking config.get_str('journaldir')."""
|
"""Fixture for mocking config.get_str('journaldir')."""
|
||||||
def get_str(key: str, *, default: str = None) -> str:
|
def get_str(key: str, *, default: str = None) -> str:
|
||||||
"""Mock config.*Config get_str to provide fake journaldir."""
|
"""Mock config.*Config get_str to provide fake journaldir."""
|
||||||
@ -139,7 +138,7 @@ class TestJournalLock:
|
|||||||
self,
|
self,
|
||||||
monkeypatch: _pytest_monkeypatch,
|
monkeypatch: _pytest_monkeypatch,
|
||||||
tmp_path_factory: _pytest_tmpdir.TempPathFactory
|
tmp_path_factory: _pytest_tmpdir.TempPathFactory
|
||||||
) -> py_path_local_LocalPath:
|
) -> _pytest_tmpdir.TempPathFactory:
|
||||||
"""Fixture for mocking config.get_str('journaldir')."""
|
"""Fixture for mocking config.get_str('journaldir')."""
|
||||||
def get_str(key: str, *, default: str = None) -> str:
|
def get_str(key: str, *, default: str = None) -> str:
|
||||||
"""Mock config.*Config get_str to provide fake journaldir."""
|
"""Mock config.*Config get_str to provide fake journaldir."""
|
||||||
@ -155,7 +154,7 @@ class TestJournalLock:
|
|||||||
|
|
||||||
###########################################################################
|
###########################################################################
|
||||||
# Tests against JournalLock.__init__()
|
# Tests against JournalLock.__init__()
|
||||||
def test_journal_lock_init(self, mock_journaldir: py_path_local_LocalPath):
|
def test_journal_lock_init(self, mock_journaldir: _pytest_tmpdir.TempPathFactory):
|
||||||
"""Test JournalLock instantiation."""
|
"""Test JournalLock instantiation."""
|
||||||
print(f'{type(mock_journaldir)=}')
|
print(f'{type(mock_journaldir)=}')
|
||||||
tmpdir = str(mock_journaldir.getbasetemp())
|
tmpdir = str(mock_journaldir.getbasetemp())
|
||||||
@ -177,7 +176,7 @@ class TestJournalLock:
|
|||||||
jlock.set_path_from_journaldir()
|
jlock.set_path_from_journaldir()
|
||||||
assert jlock.journal_dir_path is None
|
assert jlock.journal_dir_path is None
|
||||||
|
|
||||||
def test_path_from_journaldir_with_tmpdir(self, mock_journaldir: py_path_local_LocalPath):
|
def test_path_from_journaldir_with_tmpdir(self, mock_journaldir: _pytest_tmpdir.TempPathFactory):
|
||||||
"""Test JournalLock.set_path_from_journaldir() with tmpdir."""
|
"""Test JournalLock.set_path_from_journaldir() with tmpdir."""
|
||||||
tmpdir = mock_journaldir
|
tmpdir = mock_journaldir
|
||||||
|
|
||||||
@ -201,7 +200,7 @@ class TestJournalLock:
|
|||||||
locked = jlock.obtain_lock()
|
locked = jlock.obtain_lock()
|
||||||
assert locked == JournalLockResult.JOURNALDIR_IS_NONE
|
assert locked == JournalLockResult.JOURNALDIR_IS_NONE
|
||||||
|
|
||||||
def test_obtain_lock_with_tmpdir(self, mock_journaldir: py_path_local_LocalPath):
|
def test_obtain_lock_with_tmpdir(self, mock_journaldir: _pytest_tmpdir.TempPathFactory):
|
||||||
"""Test JournalLock.obtain_lock() with tmpdir."""
|
"""Test JournalLock.obtain_lock() with tmpdir."""
|
||||||
jlock = JournalLock()
|
jlock = JournalLock()
|
||||||
|
|
||||||
@ -214,7 +213,7 @@ class TestJournalLock:
|
|||||||
assert jlock.release_lock()
|
assert jlock.release_lock()
|
||||||
os.unlink(str(jlock.journal_dir_lockfile_name))
|
os.unlink(str(jlock.journal_dir_lockfile_name))
|
||||||
|
|
||||||
def test_obtain_lock_with_tmpdir_ro(self, mock_journaldir: py_path_local_LocalPath):
|
def test_obtain_lock_with_tmpdir_ro(self, mock_journaldir: _pytest_tmpdir.TempPathFactory):
|
||||||
"""Test JournalLock.obtain_lock() with read-only tmpdir."""
|
"""Test JournalLock.obtain_lock() with read-only tmpdir."""
|
||||||
tmpdir = str(mock_journaldir.getbasetemp())
|
tmpdir = str(mock_journaldir.getbasetemp())
|
||||||
print(f'{tmpdir=}')
|
print(f'{tmpdir=}')
|
||||||
@ -281,7 +280,7 @@ class TestJournalLock:
|
|||||||
|
|
||||||
assert locked == JournalLockResult.JOURNALDIR_READONLY
|
assert locked == JournalLockResult.JOURNALDIR_READONLY
|
||||||
|
|
||||||
def test_obtain_lock_already_locked(self, mock_journaldir: py_path_local_LocalPath):
|
def test_obtain_lock_already_locked(self, mock_journaldir: _pytest_tmpdir.TempPathFactory):
|
||||||
"""Test JournalLock.obtain_lock() with tmpdir."""
|
"""Test JournalLock.obtain_lock() with tmpdir."""
|
||||||
continue_q: mp.Queue = mp.Queue()
|
continue_q: mp.Queue = mp.Queue()
|
||||||
exit_q: mp.Queue = mp.Queue()
|
exit_q: mp.Queue = mp.Queue()
|
||||||
@ -313,7 +312,7 @@ class TestJournalLock:
|
|||||||
|
|
||||||
###########################################################################
|
###########################################################################
|
||||||
# Tests against JournalLock.release_lock()
|
# Tests against JournalLock.release_lock()
|
||||||
def test_release_lock(self, mock_journaldir: py_path_local_LocalPath):
|
def test_release_lock(self, mock_journaldir: _pytest_tmpdir.TempPathFactory):
|
||||||
"""Test JournalLock.release_lock()."""
|
"""Test JournalLock.release_lock()."""
|
||||||
# First actually obtain the lock, and check it worked
|
# First actually obtain the lock, and check it worked
|
||||||
jlock = JournalLock()
|
jlock = JournalLock()
|
||||||
@ -331,12 +330,12 @@ class TestJournalLock:
|
|||||||
# Cleanup, to avoid side-effect on other tests
|
# Cleanup, to avoid side-effect on other tests
|
||||||
os.unlink(str(jlock.journal_dir_lockfile_name))
|
os.unlink(str(jlock.journal_dir_lockfile_name))
|
||||||
|
|
||||||
def test_release_lock_not_locked(self, mock_journaldir: py_path_local_LocalPath):
|
def test_release_lock_not_locked(self, mock_journaldir: _pytest_tmpdir.TempPathFactory):
|
||||||
"""Test JournalLock.release_lock() when not locked."""
|
"""Test JournalLock.release_lock() when not locked."""
|
||||||
jlock = JournalLock()
|
jlock = JournalLock()
|
||||||
assert jlock.release_lock()
|
assert jlock.release_lock()
|
||||||
|
|
||||||
def test_release_lock_lie_locked(self, mock_journaldir: py_path_local_LocalPath):
|
def test_release_lock_lie_locked(self, mock_journaldir: _pytest_tmpdir.TempPathFactory):
|
||||||
"""Test JournalLock.release_lock() when not locked, but lie we are."""
|
"""Test JournalLock.release_lock() when not locked, but lie we are."""
|
||||||
jlock = JournalLock()
|
jlock = JournalLock()
|
||||||
jlock.locked = True
|
jlock.locked = True
|
||||||
@ -346,7 +345,7 @@ class TestJournalLock:
|
|||||||
# Tests against JournalLock.update_lock()
|
# Tests against JournalLock.update_lock()
|
||||||
def test_update_lock(
|
def test_update_lock(
|
||||||
self,
|
self,
|
||||||
mock_journaldir_changing: py_path_local_LocalPath):
|
mock_journaldir_changing: _pytest_tmpdir.TempPathFactory):
|
||||||
"""
|
"""
|
||||||
Test JournalLock.update_lock().
|
Test JournalLock.update_lock().
|
||||||
|
|
||||||
@ -374,7 +373,7 @@ class TestJournalLock:
|
|||||||
# And the old_journaldir's lockfile too
|
# And the old_journaldir's lockfile too
|
||||||
os.unlink(str(old_journaldir_lockfile_name))
|
os.unlink(str(old_journaldir_lockfile_name))
|
||||||
|
|
||||||
def test_update_lock_same(self, mock_journaldir: py_path_local_LocalPath):
|
def test_update_lock_same(self, mock_journaldir: _pytest_tmpdir.TempPathFactory):
|
||||||
"""
|
"""
|
||||||
Test JournalLock.update_lock().
|
Test JournalLock.update_lock().
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user