unittesting, removed key_code from audio features, batch audio features for retrieval

This commit is contained in:
aj 2021-02-05 21:44:59 +00:00
parent bbcbbc7890
commit 9312ff0763
6 changed files with 121 additions and 3 deletions

View File

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "spotframework" name = "spotframework"
version = "1.0.0" version = "1.0.1"
description = "Spotify HTTP wrapper library" description = "Spotify HTTP wrapper library"
authors = ["andy <andy@sarsoo.xyz>"] authors = ["andy <andy@sarsoo.xyz>"]
repository = "https://github.com/Sarsoo/spotframework" repository = "https://github.com/Sarsoo/spotframework"
@ -14,6 +14,10 @@ click = "^7.1.2"
[tool.poetry.dev-dependencies] [tool.poetry.dev-dependencies]
pylint = "2.5.3" pylint = "2.5.3"
[tool.poetry.scripts]
test = 'scripts:test'
testv = 'scripts:testv'
[build-system] [build-system]
requires = ["poetry-core>=1.0.0"] requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api" build-backend = "poetry.core.masonry.api"

17
scripts.py Normal file
View File

@ -0,0 +1,17 @@
import subprocess
def test():
"""
Run all unittests.
"""
subprocess.run(
['python', '-u', '-m', 'unittest', 'discover', "-s", "tests"]
)
def testv():
"""
Run all unittests with verbose.
"""
subprocess.run(
['python', '-u', '-m', 'unittest', 'discover', "-v", "-s", "tests"]
)

View File

@ -204,7 +204,6 @@ class AudioFeatures:
'uri': str(self.uri) if self.uri is not None else None, 'uri': str(self.uri) if self.uri is not None else None,
'instrumentalness': self.instrumentalness, 'instrumentalness': self.instrumentalness,
'key': self.key, 'key': self.key,
'key_code': self._key,
'liveness': self.liveness, 'liveness': self.liveness,
'loudness': self.loudness, 'loudness': self.loudness,
'mode': self.mode.value, 'mode': self.mode.value,

View File

@ -774,7 +774,10 @@ class Network:
elif isinstance(tracks, List): elif isinstance(tracks, List):
if all(isinstance(i, SimplifiedTrack) for i in tracks): if all(isinstance(i, SimplifiedTrack) for i in tracks):
audio_features = self.track_audio_features(uris=[i.uri for i in tracks])
audio_features = list()
for chunk in self.chunk(tracks, 100):
audio_features += self.track_audio_features(uris=[i.uri for i in chunk])
if audio_features: if audio_features:
if len(audio_features) != len(tracks): if len(audio_features) != len(tracks):

39
tests/test_decorators.py Normal file
View File

@ -0,0 +1,39 @@
import unittest
from unittest.mock import Mock
from spotframework.model.uri import Uri
from spotframework.util.decorators import inject_uri
class TestInjectURI(unittest.TestCase):
def test_one_uri(self):
func = Mock()
decorated = inject_uri(func, uris=False)
result = decorated(uri="spotify:track:test")
self.assertIsInstance(func.call_args.kwargs["uri"], Uri)
func.assert_called_once()
def test_uris(self):
func = Mock()
decorated = inject_uri(func, uri=False)
result = decorated(uris=["spotify:track:test",
"spotify:album:test"])
for arg in func.call_args.kwargs["uris"]:
self.assertIsInstance(arg, Uri)
func.assert_called_once()
def test_uri_optional(self):
func = Mock()
decorated = inject_uri(func, uri_optional=True, uris=False)
result = decorated()
func.assert_called_once()
if __name__ == '__main__':
unittest.main()

56
tests/test_uri.py Normal file
View File

@ -0,0 +1,56 @@
import unittest
from spotframework.model.uri import Uri
class TestURI(unittest.TestCase):
def test_input_not_string(self):
with self.assertRaises(AttributeError):
Uri(7)
def test_start_spotify(self):
with self.assertRaises(ValueError):
# all uris start with spotify
# spotify:track:3EHhS6B2qJWup1nqUVQy1H
Uri("_potify:track:3EHhS6B2qJWup1nqUVQy1H")
# test 5 component scenario or remove from source
def test_6_components_is_local_uri(self):
with self.assertRaises(ValueError):
# all uris start with spotify
# spotify:local:{artist}:{album_title}:{track_title}:{duration_in_seconds}
Uri("spotify:_ocal:{artist}:{album_title}:{track_title}:{duration_in_seconds}")
def test_too_many_components(self):
with self.assertRaises(ValueError):
# all uris start with spotifys
Uri("spotify:test:test:test:test:test:test")
def test_equals(self):
uri_one = Uri("spotify:track:test")
uri_two = Uri("spotify:track:test")
self.assertEqual(uri_one, uri_two)
def test_equal_different_type(self):
uri_one = Uri("spotify:track:test")
uri_two = 7
self.assertNotEqual(uri_one, uri_two)
def test_equal_object_type(self):
uri_one = Uri("spotify:album:test")
uri_two = Uri("spotify:track:test")
self.assertNotEqual(uri_one, uri_two)
def test_equal_object_id(self):
uri_one = Uri("spotify:track:test")
uri_two = Uri("spotify:track:tester")
self.assertNotEqual(uri_one, uri_two)
if __name__ == '__main__':
unittest.main()