Skip to content

Commit

Permalink
Test coverage improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ninadicara committed Apr 21, 2021
1 parent 2b7b29a commit 82084fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
6 changes: 1 addition & 5 deletions src/spotifyrehydrator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
25 changes: 11 additions & 14 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 82084fd

Please sign in to comment.