mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-15 06:55:48 +00:00
constistent classmethod and staticmethod usage
General idea is to use classmethod for every constructor and statismethod otherwise. Also use self and cls whenever it's possible to call static and class methods
This commit is contained in:
@ -15,14 +15,14 @@ def test_enter(lock: Lock, mocker: MockerFixture) -> None:
|
||||
must process with context manager
|
||||
"""
|
||||
check_user_mock = mocker.patch("ahriman.application.lock.Lock.check_user")
|
||||
remove_mock = mocker.patch("ahriman.application.lock.Lock.remove")
|
||||
clear_mock = mocker.patch("ahriman.application.lock.Lock.clear")
|
||||
create_mock = mocker.patch("ahriman.application.lock.Lock.create")
|
||||
update_status_mock = mocker.patch("ahriman.core.status.client.Client.update_self")
|
||||
|
||||
with lock:
|
||||
pass
|
||||
check_user_mock.assert_called_once()
|
||||
remove_mock.assert_called_once()
|
||||
clear_mock.assert_called_once()
|
||||
create_mock.assert_called_once()
|
||||
update_status_mock.assert_has_calls([
|
||||
mock.call(BuildStatusEnum.Building),
|
||||
@ -35,7 +35,7 @@ def test_exit_with_exception(lock: Lock, mocker: MockerFixture) -> None:
|
||||
must process with context manager in case if exception raised
|
||||
"""
|
||||
mocker.patch("ahriman.application.lock.Lock.check_user")
|
||||
mocker.patch("ahriman.application.lock.Lock.remove")
|
||||
mocker.patch("ahriman.application.lock.Lock.clear")
|
||||
mocker.patch("ahriman.application.lock.Lock.create")
|
||||
update_status_mock = mocker.patch("ahriman.core.status.client.Client.update_self")
|
||||
|
||||
@ -79,6 +79,34 @@ def test_check_user_unsafe(lock: Lock) -> None:
|
||||
lock.check_user()
|
||||
|
||||
|
||||
def test_clear(lock: Lock) -> None:
|
||||
"""
|
||||
must remove lock file
|
||||
"""
|
||||
lock.path = Path(tempfile.mktemp())
|
||||
lock.path.touch()
|
||||
|
||||
lock.clear()
|
||||
assert not lock.path.is_file()
|
||||
|
||||
|
||||
def test_clear_missing(lock: Lock) -> None:
|
||||
"""
|
||||
must not fail on lock removal if file is missing
|
||||
"""
|
||||
lock.path = Path(tempfile.mktemp())
|
||||
lock.clear()
|
||||
|
||||
|
||||
def test_clear_skip(lock: Lock, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip removal if no file set
|
||||
"""
|
||||
unlink_mock = mocker.patch("pathlib.Path.unlink")
|
||||
lock.clear()
|
||||
unlink_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_create(lock: Lock) -> None:
|
||||
"""
|
||||
must create lock
|
||||
@ -121,31 +149,3 @@ def test_create_unsafe(lock: Lock) -> None:
|
||||
|
||||
lock.create()
|
||||
lock.path.unlink()
|
||||
|
||||
|
||||
def test_remove(lock: Lock) -> None:
|
||||
"""
|
||||
must remove lock file
|
||||
"""
|
||||
lock.path = Path(tempfile.mktemp())
|
||||
lock.path.touch()
|
||||
|
||||
lock.remove()
|
||||
assert not lock.path.is_file()
|
||||
|
||||
|
||||
def test_remove_missing(lock: Lock) -> None:
|
||||
"""
|
||||
must not fail on lock removal if file is missing
|
||||
"""
|
||||
lock.path = Path(tempfile.mktemp())
|
||||
lock.remove()
|
||||
|
||||
|
||||
def test_remove_skip(lock: Lock, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip removal if no file set
|
||||
"""
|
||||
unlink_mock = mocker.patch("pathlib.Path.unlink")
|
||||
lock.remove()
|
||||
unlink_mock.assert_not_called()
|
||||
|
Reference in New Issue
Block a user