Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Format according to pycodestyle guidelines #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 35 additions & 37 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import os

try:
from setuptools import setup, find_packages
from setuptools import setup, find_packages
except ImportError:
from distutils.core import setup
from distutils.core import setup

from xkcd_dl.version import VERSION
__version__ = VERSION
Expand All @@ -25,38 +25,36 @@
readme.close()

setup(
name = 'xkcd-dl',
version = __version__,
author = 'Tasdik Rahman',
author_email = '[email protected]',
description = "Download all the XKCD's uploaded, ever from the command line",
long_description=long_description,
url = 'https://github.com/tasdikrahman/xkcd-dl',
license = 'MIT',
install_requires = [
"beautifulsoup4==4.4.1",
"python-magic==0.4.10",
"requests==2.8.1",
],
### adding package data to it
packages=find_packages(exclude=['contrib', 'docs', 'tests']),
###
download_url = 'https://github.com/tasdikrahman/xkcd-dl/tarball/'+__version__,
classifiers = [
'Intended Audience :: Developers',
'Topic :: Software Development :: Build Tools',
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
],
keywords = ['xkcd', 'cli', 'commandline','download', 'api', 'comic'],
entry_points = {
'console_scripts': [
'xkcd-dl = xkcd_dl.cli:main'
],
}
)
name='xkcd-dl',
version=__version__,
author='Tasdik Rahman',
author_email='[email protected]',
description="Download all the XKCD's uploaded, ever from the command line",
long_description=long_description,
url='https://github.com/tasdikrahman/xkcd-dl',
license='MIT',
install_requires=[
"beautifulsoup4==4.4.1",
"python-magic==0.4.10",
"requests==2.8.1",
],
### adding package data to it
packages=find_packages(exclude=['contrib', 'docs', 'tests']),
###
download_url='https://github.com/tasdikrahman/xkcd-dl/tarball/' +
__version__,
classifiers=[
'Intended Audience :: Developers',
'Topic :: Software Development :: Build Tools',
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
],
keywords=['xkcd', 'cli', 'commandline', 'download', 'api', 'comic'],
entry_points={
'console_scripts': ['xkcd-dl = xkcd_dl.cli:main'],
})
58 changes: 52 additions & 6 deletions tests/inputs.py

Large diffs are not rendered by default.

34 changes: 22 additions & 12 deletions tests/unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import shutil



def get_fake_xkcd_json_dict():
from tests.inputs import XKCD_ARCHIVE_JSON
return json.loads(XKCD_ARCHIVE_JSON)
Expand Down Expand Up @@ -44,7 +43,7 @@ def test_update_dict(self, mock_api_call):
mock_api_call.return_value.content = res

update_dict()

with open(tmp_file.name) as json_file:
data = json.load(json_file)
assert len(data) == 1849
Expand All @@ -59,22 +58,26 @@ def test_download_all(self, download_one_stub, fake_dict):
@mock.patch('xkcd_dl.cli.is_valid_comic', return_value=True)
@mock.patch('xkcd_dl.cli.read_dict', side_effect=get_fake_xkcd_json_dict)
@mock.patch('xkcd_dl.cli.download_one')
def test_download_xkcd_range_normal(self, download_one_stub, fake_dict, is_valid_comic_stub):
def test_download_xkcd_range_normal(self, download_one_stub, fake_dict,
is_valid_comic_stub):
download_xkcd_range(233, 236)
assert download_one_stub.call_count == 4

@mock.patch('xkcd_dl.cli.is_valid_comic', return_value=True)
@mock.patch('xkcd_dl.cli.read_dict', side_effect=get_fake_xkcd_json_dict)
@mock.patch('xkcd_dl.cli.download_one')
def test_download_xkcd_range_with_404(self, download_one_stub, fake_dict, is_valid_comic_stub):
def test_download_xkcd_range_with_404(self, download_one_stub, fake_dict,
is_valid_comic_stub):
download_xkcd_range(400, 405)
assert download_one_stub.call_count == 5

@mock.patch('xkcd_dl.cli.read_dict', side_effect=get_fake_xkcd_json_dict)
@mock.patch('xkcd_dl.cli.download_one')
def test_download_xkcd_range_wrong_range(self, download_one_stub, fake_dict):
def test_download_xkcd_range_wrong_range(self, download_one_stub,
fake_dict):
download_xkcd_range(405, 400)
assert sys.stdout.getvalue().strip() == "Start must be smaller than End."
assert sys.stdout.getvalue().strip(
) == "Start must be smaller than End."

@mock.patch('xkcd_dl.cli.requests.get')
def test_valid_comic(self, mock_api_call):
Expand Down Expand Up @@ -114,7 +117,9 @@ def test_download_one(self, mock_call, fake_copyfileobj):
mock_image_content_call.raw = MagicMock(spec=HTTPResponse)
mock_image_content_call.status_code = 200

mock_call.side_effect = [mock_info_call, mock_image_call, mock_image_content_call]
mock_call.side_effect = [
mock_info_call, mock_image_call, mock_image_content_call
]
xkcd_dl.cli.WORKING_DIRECTORY = tempfile.mkdtemp()
download_one(get_fake_xkcd_json_dict(), 1550)
xkcd_download_folder = xkcd_dl.cli.WORKING_DIRECTORY + "/xkcd_archive/1550/"
Expand Down Expand Up @@ -148,22 +153,27 @@ def test_download_duplicate(self, mock_call, fake_copyfileobj):
mock_image_content_call.raw = MagicMock(spec=HTTPResponse)
mock_image_content_call.status_code = 200

mock_call.side_effect = [mock_info_call, mock_image_call, mock_image_content_call, mock_info_call,
mock_image_call, mock_image_content_call]
mock_call.side_effect = [
mock_info_call, mock_image_call, mock_image_content_call,
mock_info_call, mock_image_call, mock_image_content_call
]
xkcd_dl.cli.WORKING_DIRECTORY = tempfile.mkdtemp()
download_one(get_fake_xkcd_json_dict(), 1550)
download_one(get_fake_xkcd_json_dict(), 1550)

assert sys.stdout.getvalue().split('\n')[-2] == "xkcd number '1550' has already been downloaded!"
assert sys.stdout.getvalue().split('\n')[
-2] == "xkcd number '1550' has already been downloaded!"

shutil.rmtree(xkcd_dl.cli.WORKING_DIRECTORY, ignore_errors=True)

@mock.patch('xkcd_dl.cli.requests.get')
def test_download_one_invalid(self, mock_api_call):
download_one(get_fake_xkcd_json_dict(), 11)
assert sys.stdout.getvalue().strip() == "11 does not exist! Please try with a different option"
assert sys.stdout.getvalue().strip(
) == "11 does not exist! Please try with a different option"

@mock.patch('xkcd_dl.cli.requests.get')
def test_download_exclusion_list(self, mock_api_call):
download_one(get_fake_xkcd_json_dict(), 1525)
assert "1525 is special. It does not have an image." in sys.stdout.getvalue()
assert "1525 is special. It does not have an image." in sys.stdout.getvalue(
)
Loading