Skip to content

Commit

Permalink
Add initial test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
aklajnert committed Dec 5, 2020
1 parent c22ae36 commit 58d3e06
Show file tree
Hide file tree
Showing 12 changed files with 62,818 additions and 15 deletions.
24 changes: 17 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

setup(
# 'spotify-downloader' was already taken (>﹏<)
name = "spotdl",
packages = [
name="spotdl",

packages=[
'spotdl',
'spotdl.search',
'spotdl.download',
'spotdl.patches'
],

version = '3.2.0-pre',
version='3.2.0-pre',

install_requires = [
install_requires=[
'spotipy',
'pytube3',
'tqdm',
Expand All @@ -22,8 +22,18 @@
'mutagen',
],

extras_require={
"test": [
"pytest>=6.0",
"pytest-mock==3.3.1",
"pytest-vcr==1.0.2",
"pyfakefs==4.3.0",
"pytest-cov==2.10.1"
],
},

description="Downloads Spotify music from Youtube with metadata and album art",

author="Ritiek Malhotra",
author_email="ritiekmalhotra123@gmail.com",

Expand Down Expand Up @@ -59,7 +69,7 @@
"Topic :: Utilities",
],

entry_points = {
entry_points={
"console_scripts": ["spotdl = spotdl.__main__:console_entry_point"]
}
)
15 changes: 7 additions & 8 deletions spotdl/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! Basic necessities to get the CLI running
from spotdl.search.spotifyClient import initialize
from sys import argv as cliArgs
from spotdl.search import spotifyClient
import sys

#! Song Search from different start points
from spotdl.search.utils import get_playlist_tracks, get_album_tracks, search_for_song, get_artist_tracks
Expand All @@ -14,7 +14,6 @@

#! used to quiet the output
from io import StringIO as quiet
import sys

#! Script Help
help_notice = '''
Expand Down Expand Up @@ -59,27 +58,27 @@ def console_entry_point():
Its super simple, rudimentary even but, it's dead simple & it works.
'''

if '--help' in cliArgs or '-h' in cliArgs:
if '--help' in sys.argv or '-h' in sys.argv or len(sys.argv) == 1:
print(help_notice)

#! We use 'return None' as a convenient exit/break from the function
return None

if '--quiet' in cliArgs:
if '--quiet' in sys.argv:
#! removing --quiet so it doesnt mess up with the download
cliArgs.remove('--quiet')
sys.argv.remove('--quiet')
#! make stdout & stderr silent
sys.stdout = quiet()
sys.stderr = quiet()

initialize(
spotifyClient.initialize(
clientId = '4fe3fecfe5334023a1472516cc99d805',
clientSecret = '0f02b7c483c04257984695007a4a8d5c'
)

downloader = DownloadManager()

for request in cliArgs[1:]:
for request in sys.argv[1:]:
if ('open.spotify.com' in request and 'track' in request) or 'spotify:track:' in request:
print('Fetching Song...')
song = SongObj.from_url(request)
Expand Down
40 changes: 40 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Running tests

## Installing dependencies

All the required dependencies can be installed via `pip`, by using the following command:

```shell
pip install -e .[test]
```

## Executing tests

After installing all the required modules, just call the following command from the root directory:

```shell
pytest
```

To see code coverage use:

```shell
pytest --cov=spotdl
```

## Enable network communication

To speed up the test execution, the network requests are mocked. That means that each HTTP
request does not reach the server, and the response is faked by the [vcrpy](https://vcrpy.readthedocs.io/en/latest/index.html)
module. This greatly increases the test performance - in my case <3 seconds vs ~50 seconds, but also
may cause a problem whenever something changes in the real server response. It is recommended to run
the test suite without mocked network from time to time (preferably on CI).

To run tests with a real network communication use this command:

```shell
pytest --disable-vcr
```

Whenever the server response will change and affect the tests behavior, the stored responses can be updated
by wiping the [tests/cassetes](tests/cassetes) directory and running `pytest` again (without `--disable-vcr`).
Empty file added tests/__init__.py
Empty file.

0 comments on commit 58d3e06

Please sign in to comment.