Skip to content

Commit

Permalink
format, remove unused function
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma67 committed Apr 9, 2023
1 parent 9aa7103 commit 7cc08fa
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 24 deletions.
2 changes: 1 addition & 1 deletion spotify_to_ytmusic/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def all(args):
playlist_id = ytmusic.create_playlist(
p["name"],
p["description"],
"PUBLIC" if p['public'] else "PRIVATE",
"PUBLIC" if p["public"] else "PRIVATE",
videoIds,
)
print(playlist_id)
Expand Down
7 changes: 2 additions & 5 deletions spotify_to_ytmusic/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,9 @@ def get_args(args=None):
remove_parser.add_argument("pattern", help="regex pattern")

all_parser = subparsers.add_parser(
"all",
help="Transfer all public playlists of the specified user (Spotify User ID)."
)
all_parser.add_argument(
"user", type=str, help="Spotify userid of the specified user."
"all", help="Transfer all public playlists of the specified user (Spotify User ID)."
)
all_parser.add_argument("user", type=str, help="Spotify userid of the specified user.")
all_parser.set_defaults(func=controllers.all)

return parser.parse_args(args)
Expand Down
13 changes: 0 additions & 13 deletions spotify_to_ytmusic/spotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,6 @@ def getUserPlaylists(self, user):

return [p for p in pl if p["owner"]["id"] == user and p["tracks"]["total"] > 0]

def get_tracks(self, url):
tracks = []
url_parts = parse_url(url)
path = url_parts.path.split("/")
id = path[2]
if "album" == path[1]:
album = self.api.album(id)
tracks.extend(build_results(album["tracks"]["items"], album["name"]))
elif "track" == path[1]:
track = self.api.track(id)
tracks.extend(build_results([track]))
return tracks


def build_results(tracks, album=None):
results = []
Expand Down
20 changes: 15 additions & 5 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,37 @@ def test_create(self):
with mock.patch("sys.argv", ["", "all", "sigmatics"]):
main()

with mock.patch("sys.argv", ["", "create", TEST_PLAYLIST, "-n", "test", "-i", "test-playlist", "-d"]):
with mock.patch(
"sys.argv", ["", "create", TEST_PLAYLIST, "-n", "test", "-i", "test-playlist", "-d"]
):
main()

time.sleep(2)
with mock.patch("sys.argv", ["", "update", TEST_PLAYLIST, "test"]):
main()

with mock.patch("sys.argv", ["", "remove", "test"]), mock.patch('sys.stdout', new=StringIO()) as fakeOutput, mock.patch("builtins.input", side_effect="y"):
with mock.patch("sys.argv", ["", "remove", "test"]), mock.patch(
"sys.stdout", new=StringIO()
) as fakeOutput, mock.patch("builtins.input", side_effect="y"):
main()
assert int(fakeOutput.getvalue().splitlines()[-1][0]) >= 2 # assert number of lines deleted
assert (
int(fakeOutput.getvalue().splitlines()[-1][0]) >= 2
) # assert number of lines deleted

def test_setup(self):
tmp_path = Path(__file__).parent.joinpath("settings.tmp")
example_path = Settings.filepath.parent.joinpath("settings.ini.example")
shutil.copy(example_path, tmp_path)
with mock.patch("sys.argv", ["", "setup"]), mock.patch("builtins.input", return_value="3"), mock.patch("spotify_to_ytmusic.settings.Settings.filepath", tmp_path):
with mock.patch("sys.argv", ["", "setup"]), mock.patch(
"builtins.input", return_value="3"
), mock.patch("spotify_to_ytmusic.settings.Settings.filepath", tmp_path):
main()
assert tmp_path.is_file()
tmp_path.unlink()

with mock.patch("sys.argv", ["", "setup", "--file", example_path.as_posix()]), mock.patch("spotify_to_ytmusic.settings.Settings.filepath", tmp_path):
with mock.patch("sys.argv", ["", "setup", "--file", example_path.as_posix()]), mock.patch(
"spotify_to_ytmusic.settings.Settings.filepath", tmp_path
):
main()
assert tmp_path.is_file()
tmp_path.unlink()

0 comments on commit 7cc08fa

Please sign in to comment.