From 82084fd06c783d5bc71a4792614842743dcd74fe Mon Sep 17 00:00:00 2001 From: Nina Di Cara Date: Wed, 21 Apr 2021 10:20:52 +0100 Subject: [PATCH] Test coverage improvements --- src/spotifyrehydrator/utils.py | 6 +----- tests/test_functions.py | 25 +++++++++++-------------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/spotifyrehydrator/utils.py b/src/spotifyrehydrator/utils.py index 6b1cd8b..93fc2a1 100644 --- a/src/spotifyrehydrator/utils.py +++ b/src/spotifyrehydrator/utils.py @@ -89,9 +89,6 @@ def _person_ids(input_path): # If it has split into 2 parts, take the first part if len(name_split) > 1: ids.add(file.split(sep="_")[0]) - # If there are no files with ids then pass - else: - pass if ids: return list(ids) @@ -560,8 +557,7 @@ def search_results(self, remove_char=None) -> dict: track = self.name results = self.sp_auth.search( - q="artist:" + artist + " track:" + track, - type="track", + q="artist:" + artist + " track:" + track, type="track", ) # Return the first result from this search return results diff --git a/tests/test_functions.py b/tests/test_functions.py index af97982..0cda22e 100644 --- a/tests/test_functions.py +++ b/tests/test_functions.py @@ -9,10 +9,11 @@ import logging import shutil import math - import simplejson as json import pandas as pd +from spotipy.exceptions import SpotifyException + from src.spotifyrehydrator.utils import Track, Tracks, Rehydrator LOGGER = logging.getLogger(__name__) @@ -34,6 +35,13 @@ def setup_method(self): client_secret=os.getenv("SPOTIFY_CLIENT_SECRET"), ) + self.wrong_track = Track( + artist="Not a name of an artist", + name="Not a name of a track", + client_id=os.getenv("SPOTIFY_CLIENT_ID"), + client_secret=os.getenv("SPOTIFY_CLIENT_SECRET"), + ) + def test_search_results(self): results = self.test_track.search_results() assert results["tracks"]["items"][0]["id"] # Make sure ID exists @@ -79,12 +87,7 @@ def setup_method(self): def test_incorrect_input_columns(self): """Try to give Tracks obj a df with incorrect columns.""" - df = pd.DataFrame( - { - "col1": [2, 1, 9, 8, 7, 4], - "col2": [0, 1, 9, 4, 2, 3], - } - ) + df = pd.DataFrame({"col1": [2, 1, 9, 8, 7, 4], "col2": [0, 1, 9, 4, 2, 3],}) with pytest.raises(KeyError): tracks = Tracks( df, @@ -180,10 +183,7 @@ def test_read_data(self, person, input, expected): @pytest.mark.parametrize( "person, input, expected", - [ - ("Person002", INPUT_PEOPLE, 9), - (None, INPUT_NO_PEOPLE, 65), - ], + [("Person002", INPUT_PEOPLE, 9), (None, INPUT_NO_PEOPLE, 65),], ) def test_rehydrate(self, person, input, expected): data = Rehydrator( @@ -246,9 +246,6 @@ class TestIntegrationNoPeople: """Class to check the whole rehydrator behaves as expected when there are no people.""" def setup_method(self): - # Delete the current output folder - if os.path.exists(OUTPUT): - shutil.rmtree(OUTPUT) # Run the rehydrator Rehydrator( INPUT_NO_PEOPLE,