Tests beginning for playlist.plex.server

Signed-off-by: Cliff Hill <xlorep@darkhelm.org>
This commit is contained in:
2021-09-30 16:05:27 -04:00
parent 1e4744a7cb
commit 96641858ef
3 changed files with 40 additions and 13 deletions

23
poetry.lock generated
View File

@@ -211,7 +211,7 @@ python-versions = ">=2.7"
[[package]]
name = "filelock"
version = "3.1.0"
version = "3.2.0"
description = "A platform independent file lock."
category = "dev"
optional = false
@@ -219,7 +219,7 @@ python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7"
[package.extras]
docs = ["furo (>=2021.8.17b43)", "sphinx (>=4.1)", "sphinx-autodoc-typehints (>=1.12)"]
testing = ["coverage (>=4)", "pytest (>=4)", "pytest-cov"]
testing = ["coverage (>=4)", "pytest (>=4)", "pytest-cov", "pytest-timeout (>=1.4.2)"]
[[package]]
name = "greenlet"
@@ -371,20 +371,19 @@ i18n = ["Babel (>=2.7)"]
[[package]]
name = "jsonschema"
version = "3.2.0"
version = "4.0.1"
description = "An implementation of JSON Schema validation for Python"
category = "dev"
optional = false
python-versions = "*"
python-versions = ">=3.7"
[package.dependencies]
attrs = ">=17.4.0"
pyrsistent = ">=0.14.0"
six = ">=1.11.0"
pyrsistent = ">=0.14.0,<0.17.0 || >0.17.0,<0.17.1 || >0.17.1,<0.17.2 || >0.17.2"
[package.extras]
format = ["idna", "jsonpointer (>1.13)", "rfc3987", "strict-rfc3339", "webcolors"]
format_nongpl = ["idna", "jsonpointer (>1.13)", "webcolors", "rfc3986-validator (>0.1.0)", "rfc3339-validator"]
format = ["fqdn", "idna", "isoduration", "jsonpointer (>1.13)", "rfc3339-validator", "rfc3987", "uri-template", "webcolors (>=1.11)"]
format_nongpl = ["fqdn", "idna", "isoduration", "jsonpointer (>1.13)", "rfc3339-validator", "rfc3986-validator (>0.1.0)", "uri-template", "webcolors (>=1.11)"]
[[package]]
name = "jupyter"
@@ -1374,8 +1373,8 @@ entrypoints = [
{file = "entrypoints-0.3.tar.gz", hash = "sha256:c70dd71abe5a8c85e55e12c19bd91ccfeec11a6e99044204511f9ed547d48451"},
]
filelock = [
{file = "filelock-3.1.0-py2.py3-none-any.whl", hash = "sha256:d9e9c7d8191e915339843c81c90d3e44f7c84e5fb03bdc6b1b4d019025cf953b"},
{file = "filelock-3.1.0.tar.gz", hash = "sha256:78925788ce8c8945fac28a68c1d05cf33a6a6c4fba14fe02835122c53268ceef"},
{file = "filelock-3.2.0-py2.py3-none-any.whl", hash = "sha256:61a99e9b12b47b685d1389f4cf969c1eba0efd2348a8471f86e01e8c622267af"},
{file = "filelock-3.2.0.tar.gz", hash = "sha256:85ecb30757aa19d06bfcdad29cc332b9a3e4851bf59976aea1e8dadcbd9ef883"},
]
greenlet = [
{file = "greenlet-1.1.2-cp27-cp27m-macosx_10_14_x86_64.whl", hash = "sha256:58df5c2a0e293bf665a51f8a100d3e9956febfbf1d9aaf8c0677cf70218910c6"},
@@ -1466,8 +1465,8 @@ jinja2 = [
{file = "Jinja2-3.0.1.tar.gz", hash = "sha256:703f484b47a6af502e743c9122595cc812b0271f661722403114f71a79d0f5a4"},
]
jsonschema = [
{file = "jsonschema-3.2.0-py2.py3-none-any.whl", hash = "sha256:4e5b3cf8216f577bee9ce139cbe72eca3ea4f292ec60928ff24758ce626cd163"},
{file = "jsonschema-3.2.0.tar.gz", hash = "sha256:c8a85b28d377cc7737e46e2d9f2b4f44ee3c0e1deac6bf46ddefc7187d30797a"},
{file = "jsonschema-4.0.1-py3-none-any.whl", hash = "sha256:9938802041347f2c62cad2aef59e9a0826cd34584f3609db950efacb4dbf6518"},
{file = "jsonschema-4.0.1.tar.gz", hash = "sha256:48f4e74f8bec0c2f75e9fcfffa264e78342873e1b57e2cfeae54864cc5e9e4dd"},
]
jupyter = [
{file = "jupyter-1.0.0-py2.py3-none-any.whl", hash = "sha256:5b290f93b98ffbc21c0c7e749f054b3267782166d72fa5e3ed1ed4eaf34a2b78"},

View File

@@ -41,7 +41,7 @@ def calc_duration(durations: list[int]) -> None:
with settings.modify() as s:
avg_track_duration = statistics.geometric_mean(durations)
s.track.duration = round(avg_track_duration, ndigits=6)
playtime_seconds = settings.get().playlist.playtime.total_seconds()
playtime_seconds = s.playlist.playtime.total_seconds()
s.playlist.max_tracks = int(playtime_seconds / avg_track_duration)

28
tests/plex/test_server.py Normal file
View File

@@ -0,0 +1,28 @@
"""Tests for the playlist.plex.server module."""
import pytest # type: ignore [import]
from playlist.plex import server # type: ignore [import]
def test_calc_delay(mocker: pytest.fixture) -> None:
"""Test the calc_delay function."""
mock_settings = mocker.patch("playlist.plex.server.settings")
mock_const = mocker.patch("playlist.plex.server.const")
times = [100, 100, 100]
weights = [100, 100, 100]
mock_const.MAX_PROCESSES = 1
server.calc_delay(times, weights)
mock_s = mock_settings.modify.return_value.__enter__.return_value
result = mock_s.download.process_delay
assert result == 100
def test_calc_duration(mocker: pytest.fixture) -> None:
"""Test the calc_duration function."""
mock_settings = mocker.patch("playlist.plex.server.settings")
durations = [100, 100, 100]
mock_s = mock_settings.modify.return_value.__enter__.return_value
mock_s.playlist.playtime.total_seconds.return_value = 300
server.calc_duration(durations)
result = mock_s.playlist.max_tracks
assert result == 2