mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-10 06:04:15 +00:00
Update test_utils
This commit is contained in:
parent
29daf4c237
commit
2513eb0b6d
1 changed files with 38 additions and 31 deletions
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import pytest
|
||||
import pytest, time
|
||||
import plexapi.utils as utils
|
||||
from plexapi.exceptions import NotFound
|
||||
|
||||
|
@ -7,18 +7,24 @@ from plexapi.exceptions import NotFound
|
|||
def test_utils_toDatetime():
|
||||
assert str(utils.toDatetime('2006-03-03', format='%Y-%m-%d')) == '2006-03-03 00:00:00'
|
||||
assert str(utils.toDatetime('0'))[:-9] in ['1970-01-01', '1969-12-31']
|
||||
# should this handle args as '0' # no need element attrs are strings.
|
||||
|
||||
|
||||
def _test_utils_threaded():
|
||||
# TODO: Implement test_utils_threaded
|
||||
def test_utils_threaded():
|
||||
def _squared(num, results, i):
|
||||
time.sleep(0.5)
|
||||
results[i] = num * num
|
||||
starttime = time.time()
|
||||
results = utils.threaded(_squared, [[1], [2], [3], [4], [5]])
|
||||
assert results == [1, 4, 9, 16, 25]
|
||||
assert (time.time() - starttime) < 1
|
||||
|
||||
|
||||
@pytest.mark.req_client
|
||||
def test_utils_downloadSessionImages():
|
||||
# TODO: Implement test_utils_downloadSessionImages()
|
||||
pass
|
||||
|
||||
|
||||
def _downloadSessionImages():
|
||||
pass # TODO Add this when we got clients fixed.
|
||||
|
||||
|
||||
def test_utils_searchType():
|
||||
st = utils.searchType('movie')
|
||||
assert st == 1
|
||||
|
@ -34,29 +40,30 @@ def test_utils_joinArgs():
|
|||
|
||||
|
||||
def test_utils_cast():
|
||||
t_int_int = utils.cast(int, 1)
|
||||
t_int_str_int = utils.cast(int, '1')
|
||||
t_bool_str_int = utils.cast(bool, '1')
|
||||
t_bool_int = utils.cast(bool, 1)
|
||||
t_float_int = utils.cast(float, 1)
|
||||
t_float_float = utils.cast(float, 1)
|
||||
t_float_str = utils.cast(float, 'kek')
|
||||
assert t_int_int == 1 and isinstance(t_int_int, int)
|
||||
assert t_int_str_int == 1 and isinstance(t_int_str_int, int)
|
||||
assert t_bool_str_int is True
|
||||
assert t_bool_int is True
|
||||
assert t_float_float == 1.0 and isinstance(t_float_float, float)
|
||||
assert t_float_str != t_float_str # nan is never equal
|
||||
int_int = utils.cast(int, 1)
|
||||
int_str = utils.cast(int, '1')
|
||||
bool_str = utils.cast(bool, '1')
|
||||
bool_int = utils.cast(bool, 1)
|
||||
float_int = utils.cast(float, 1)
|
||||
float_float = utils.cast(float, 1.0)
|
||||
float_str = utils.cast(float, '1.2')
|
||||
float_nan = utils.cast(float, 'wut?')
|
||||
assert int_int == 1 and isinstance(int_int, int)
|
||||
assert int_str == 1 and isinstance(int_str, int)
|
||||
assert bool_str is True
|
||||
assert bool_int is True
|
||||
assert float_int == 1.0 and isinstance(float_int, float)
|
||||
assert float_float == 1.0 and isinstance(float_float, float)
|
||||
assert float_str == 1.2 and isinstance(float_str, float)
|
||||
assert float_nan != float_nan # nan is never equal
|
||||
with pytest.raises(ValueError):
|
||||
t_bool_str = utils.cast(bool, 'kek') # should we catch this in cast?
|
||||
bool_str = utils.cast(bool, 'kek')
|
||||
|
||||
|
||||
def test_utils_download(a_episode):
|
||||
without_session = utils.download(a_episode.getStreamURL(),
|
||||
filename=a_episode.locations[0], mocked=True)
|
||||
assert without_session
|
||||
with_session = utils.download(a_episode.getStreamURL(), filename=a_episode.locations[0],
|
||||
session=a_episode._server._session, mocked=True)
|
||||
assert with_session
|
||||
img = utils.download(a_episode.thumbUrl, filename=a_episode.title, mocked=True)
|
||||
assert img
|
||||
def test_utils_download(episode):
|
||||
url = episode.getStreamURL()
|
||||
locations = episode.locations[0]
|
||||
session = episode._server._session
|
||||
assert utils.download(url, filename=locations, mocked=True)
|
||||
assert utils.download(url, filename=locations, session=session, mocked=True)
|
||||
assert utils.download(episode.thumbUrl, filename=episode.title, mocked=True)
|
||||
|
|
Loading…
Reference in a new issue