From 0aa74b87557fd59f9ed10d19d661ecdc44f019a1 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 29 Oct 2022 16:01:39 +0100 Subject: [PATCH] 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. --- tests/journal_lock.py/test_journal_lock.py | 25 +++++++++++----------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/tests/journal_lock.py/test_journal_lock.py b/tests/journal_lock.py/test_journal_lock.py index 016a8f1b..72252e9f 100644 --- a/tests/journal_lock.py/test_journal_lock.py +++ b/tests/journal_lock.py/test_journal_lock.py @@ -8,7 +8,6 @@ import pytest # Import as other names else they get picked up when used as fixtures from _pytest import monkeypatch as _pytest_monkeypatch from _pytest import tmpdir as _pytest_tmpdir -from py._path.local import LocalPath as py_path_local_LocalPath from config import config from journal_lock import JournalLock, JournalLockResult @@ -120,7 +119,7 @@ class TestJournalLock: def mock_journaldir( self, monkeypatch: _pytest_monkeypatch, tmp_path_factory: _pytest_tmpdir.TempPathFactory - ) -> py_path_local_LocalPath: + ) -> _pytest_tmpdir.TempPathFactory: """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.""" @@ -139,7 +138,7 @@ class TestJournalLock: self, monkeypatch: _pytest_monkeypatch, tmp_path_factory: _pytest_tmpdir.TempPathFactory - ) -> py_path_local_LocalPath: + ) -> _pytest_tmpdir.TempPathFactory: """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.""" @@ -155,7 +154,7 @@ class TestJournalLock: ########################################################################### # 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.""" print(f'{type(mock_journaldir)=}') tmpdir = str(mock_journaldir.getbasetemp()) @@ -177,7 +176,7 @@ class TestJournalLock: jlock.set_path_from_journaldir() 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.""" tmpdir = mock_journaldir @@ -201,7 +200,7 @@ class TestJournalLock: locked = jlock.obtain_lock() 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.""" jlock = JournalLock() @@ -214,7 +213,7 @@ class TestJournalLock: assert jlock.release_lock() 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.""" tmpdir = str(mock_journaldir.getbasetemp()) print(f'{tmpdir=}') @@ -281,7 +280,7 @@ class TestJournalLock: 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.""" continue_q: mp.Queue = mp.Queue() exit_q: mp.Queue = mp.Queue() @@ -313,7 +312,7 @@ class TestJournalLock: ########################################################################### # 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().""" # First actually obtain the lock, and check it worked jlock = JournalLock() @@ -331,12 +330,12 @@ class TestJournalLock: # Cleanup, to avoid side-effect on other tests 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.""" jlock = JournalLock() 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.""" jlock = JournalLock() jlock.locked = True @@ -346,7 +345,7 @@ class TestJournalLock: # Tests against JournalLock.update_lock() def test_update_lock( self, - mock_journaldir_changing: py_path_local_LocalPath): + mock_journaldir_changing: _pytest_tmpdir.TempPathFactory): """ Test JournalLock.update_lock(). @@ -374,7 +373,7 @@ class TestJournalLock: # And the old_journaldir's lockfile too 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().