remove dead code, add pidfile tests
This commit is contained in:
parent
205177dca3
commit
a5cf97870b
|
@ -10,20 +10,19 @@ import typer
|
|||
from dotenv import load_dotenv
|
||||
from typing_extensions import Annotated
|
||||
|
||||
import croaker.path
|
||||
from croaker.exceptions import ConfigurationError
|
||||
from croaker import path
|
||||
from croaker.playlist import Playlist
|
||||
from croaker.server import server
|
||||
|
||||
SETUP_HELP = """
|
||||
SETUP_HELP = f"""
|
||||
# Root directory for croaker configuration and logs. See also croaker --root.
|
||||
CROAKER_ROOT=~/.dnd/croaker
|
||||
CROAKER_ROOT={path.root()}
|
||||
|
||||
# where to store playlist sources
|
||||
#PLAYLIST_ROOT=$CROAKER_ROOT/playlists
|
||||
#PLAYLIST_ROOT={path.root()}/playlists
|
||||
|
||||
# Where the record the daemon's PID
|
||||
#PIDFILE=$CROAKER_ROOT/croaker.pid
|
||||
#PIDFILE={path.root()}/croaker.pid
|
||||
|
||||
# Command and Control TCP Server bind address
|
||||
HOST=0.0.0.0
|
||||
|
@ -68,20 +67,17 @@ def main(
|
|||
level=logging.DEBUG if debug else logging.INFO,
|
||||
)
|
||||
|
||||
try:
|
||||
croaker.path.root()
|
||||
croaker.path.playlist_root()
|
||||
except ConfigurationError as e:
|
||||
sys.stderr.write(f"{e}\n\n{SETUP_HELP}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@app.command()
|
||||
def setup(context: typer.Context):
|
||||
"""
|
||||
(Re)Initialize Croaker.
|
||||
"""
|
||||
sys.stderr.write("Interactive setup is not yet available. Sorry!\n")
|
||||
|
||||
sys.stderr.write(
|
||||
"Interactive setup is not available, but you can redirect "
|
||||
"this command's output to a defaults file of your choice.\n"
|
||||
)
|
||||
print(dedent(SETUP_HELP))
|
||||
|
||||
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
class APIHandlingException(Exception):
|
||||
"""
|
||||
An API reqeust could not be encoded or decoded.
|
||||
"""
|
||||
|
||||
|
||||
class ConfigurationError(Exception):
|
||||
"""
|
||||
An error was discovered with the Groove on Demand configuration.
|
||||
"""
|
||||
|
||||
|
||||
class InvalidPathError(Exception):
|
||||
"""
|
||||
The specified path was invalid -- either it was not the expected type or wasn't accessible.
|
||||
"""
|
|
@ -9,11 +9,6 @@ def root():
|
|||
return Path(os.environ.get("CROAKER_ROOT", "~/.dnd/croaker")).expanduser()
|
||||
|
||||
|
||||
def cache_root():
|
||||
path = Path(os.environ.get("CACHE_ROOT", root() / "cache")).expanduser()
|
||||
return path
|
||||
|
||||
|
||||
def playlist_root():
|
||||
path = Path(os.environ.get("PLAYLIST_ROOT", root() / "playlists")).expanduser()
|
||||
return path
|
||||
|
|
24
test/test_pidfile.py
Normal file
24
test/test_pidfile.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
from pathlib import Path
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from croaker import pidfile
|
||||
|
||||
|
||||
@pytest.mark.parametrize('pid,terminate,kill_result,broken', [
|
||||
('pid', False, None, False), # running proc, no terminate
|
||||
('pid', True, True, False), # running proc, terminate
|
||||
('pid', True, ProcessLookupError, True), # stale pid
|
||||
(None, None, None, False), # no running proc
|
||||
])
|
||||
def test_pidfile(monkeypatch, pid, terminate, kill_result, broken):
|
||||
monkeypatch.setattr(pidfile._pidfile, 'TimeoutPIDLockFile', MagicMock(**{
|
||||
'return_value.read_pid.return_value': pid,
|
||||
}))
|
||||
monkeypatch.setattr(pidfile.os, 'kill', MagicMock(**{
|
||||
'side_effect': kill_result if type(kill_result) is Exception else [kill_result]
|
||||
}))
|
||||
|
||||
ret = pidfile.pidfile(pidfile_path=Path('/dev/null'), terminate_if_running=terminate)
|
||||
assert ret.break_lock.called == broken
|
Loading…
Reference in New Issue
Block a user