Skip to content

Commit

Permalink
Init tests (spotDL#992)
Browse files Browse the repository at this point in the history
  • Loading branch information
aklajnert committed Jan 6, 2021
1 parent f3c4cf6 commit 48d97b6
Show file tree
Hide file tree
Showing 13 changed files with 62,819 additions and 5 deletions.
13 changes: 13 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@
'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"
],
"dev": [
"tox"
]
},

description="Downloads Spotify music from Youtube with metadata and album art",
long_description=long_desc,
long_description_content_type='text/markdown',
Expand Down
10 changes: 5 additions & 5 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
Expand Down Expand Up @@ -75,20 +75,20 @@ 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

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:
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 48d97b6

Please sign in to comment.