Merge branch 'nosetests'
Browse files* nosetests:
made all tests deterministic.
mocked all the html and js with local fixtures
added mock to test requirements
updated description/how files are read
changes for nose test, added mock data
- setup.py +8 -11
- tests/mock_video.html +0 -0
- tests/mock_video.js +0 -0
- tests/test_pytube.py +63 -52
- tests/test_requirements.txt +1 -0
setup.py
CHANGED
@@ -1,19 +1,17 @@
|
|
1 |
#!/usr/bin/env python
|
2 |
# -*- coding: utf-8 -*-
|
3 |
-
|
4 |
from pytube import __version__
|
5 |
-
import os
|
6 |
-
|
7 |
|
8 |
try:
|
9 |
from setuptools import setup
|
10 |
except ImportError:
|
11 |
from distutils.core import setup
|
12 |
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
|
18 |
setup(
|
19 |
name="pytube",
|
@@ -21,8 +19,7 @@ setup(
|
|
21 |
author="Nick Ficano",
|
22 |
author_email="nficano@gmail.com",
|
23 |
packages=['pytube'],
|
24 |
-
|
25 |
-
license=open_file('LICENSE.txt').read(),
|
26 |
scripts=['scripts/pytube'],
|
27 |
classifiers=[
|
28 |
"Development Status :: 4 - Beta",
|
@@ -40,8 +37,8 @@ setup(
|
|
40 |
"Topic :: Internet",
|
41 |
"Topic :: Multimedia :: Video"
|
42 |
],
|
43 |
-
description="A simple, yet versatile
|
44 |
-
|
45 |
-
long_description=
|
46 |
zip_safe=True,
|
47 |
)
|
|
|
1 |
#!/usr/bin/env python
|
2 |
# -*- coding: utf-8 -*-
|
|
|
3 |
from pytube import __version__
|
|
|
|
|
4 |
|
5 |
try:
|
6 |
from setuptools import setup
|
7 |
except ImportError:
|
8 |
from distutils.core import setup
|
9 |
|
10 |
+
with open('README.rst') as readme_file:
|
11 |
+
readme = readme_file.read()
|
12 |
|
13 |
+
with open('LICENSE.txt') as readme_file:
|
14 |
+
license = readme_file.read()
|
|
|
15 |
|
16 |
setup(
|
17 |
name="pytube",
|
|
|
19 |
author="Nick Ficano",
|
20 |
author_email="nficano@gmail.com",
|
21 |
packages=['pytube'],
|
22 |
+
license=license,
|
|
|
23 |
scripts=['scripts/pytube'],
|
24 |
classifiers=[
|
25 |
"Development Status :: 4 - Beta",
|
|
|
37 |
"Topic :: Internet",
|
38 |
"Topic :: Multimedia :: Video"
|
39 |
],
|
40 |
+
description=("A simple, yet versatile Python library (and command-line) "
|
41 |
+
"for downloading YouTube videos."),
|
42 |
+
long_description=readme,
|
43 |
zip_safe=True,
|
44 |
)
|
tests/mock_video.html
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tests/mock_video.js
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tests/test_pytube.py
CHANGED
@@ -1,60 +1,71 @@
|
|
1 |
#!/usr/bin/env/python
|
2 |
# -*- coding: utf-8 -*-
|
3 |
|
4 |
-
import
|
5 |
-
from
|
|
|
6 |
from pytube.exceptions import MultipleObjectsReturned
|
7 |
|
8 |
-
SHOW_ERROR_MESSAGES = True
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
|
12 |
-
|
|
|
13 |
|
14 |
-
def
|
15 |
-
"""
|
16 |
-
|
17 |
-
|
18 |
-
self.
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
def
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
1 |
#!/usr/bin/env/python
|
2 |
# -*- coding: utf-8 -*-
|
3 |
|
4 |
+
import mock
|
5 |
+
from nose.tools import eq_, raises
|
6 |
+
from pytube import api
|
7 |
from pytube.exceptions import MultipleObjectsReturned
|
8 |
|
|
|
9 |
|
10 |
+
class TestPytube(object):
|
11 |
+
def setUp(self):
|
12 |
+
url = 'http://www.youtube.com/watch?v=9bZkp7q19f0'
|
13 |
+
self.mock_js = open('tests/mock_video.js').read()
|
14 |
+
self.mock_html = open('tests/mock_video.html').read()
|
15 |
+
with mock.patch('pytube.api.urlopen') as urlopen:
|
16 |
+
urlopen.return_value.read.return_value = self.mock_html
|
17 |
+
self.yt = api.YouTube()
|
18 |
+
self.yt._js_code = self.mock_js
|
19 |
+
self.yt.from_url(url)
|
20 |
|
21 |
+
def test_get_video_id(self):
|
22 |
+
"""Resolve the video id from url"""
|
23 |
+
eq_(self.yt.video_id, '9bZkp7q19f0')
|
24 |
|
25 |
+
def test_auto_filename(self):
|
26 |
+
"""Generate safe filename based on video title"""
|
27 |
+
expected = u'PSY - GANGNAM STYLE(\uac15\ub0a8\uc2a4\ud0c0\uc77c) MV'
|
28 |
+
|
29 |
+
eq_(self.yt.filename, expected)
|
30 |
+
|
31 |
+
def test_manual_filename(self):
|
32 |
+
"""Manually set a filename"""
|
33 |
+
expected = u'PSY - Gangnam Style'
|
34 |
+
|
35 |
+
self.yt.set_filename(expected)
|
36 |
+
eq_(self.yt.filename, expected)
|
37 |
+
|
38 |
+
def test_get_all_videos(self):
|
39 |
+
"""Get all videos"""
|
40 |
+
eq_(len(self.yt.get_videos()), 6)
|
41 |
+
|
42 |
+
def test_filter_video_by_extension(self):
|
43 |
+
"""Filter videos by filetype"""
|
44 |
+
eq_(len(self.yt.filter('mp4')), 2)
|
45 |
+
eq_(len(self.yt.filter('3gp')), 2)
|
46 |
+
eq_(len(self.yt.filter('webm')), 1)
|
47 |
+
eq_(len(self.yt.filter('flv')), 1)
|
48 |
+
|
49 |
+
def test_filter_video_by_extension_and_resolution(self):
|
50 |
+
"""Filter videos by file extension and resolution"""
|
51 |
+
eq_(len(self.yt.filter('mp4', '720p')), 1)
|
52 |
+
eq_(len(self.yt.filter('mp4', '1080p')), 0)
|
53 |
+
|
54 |
+
def test_filter_video_by_extension_resolution_profile(self):
|
55 |
+
"""Filter videos by file extension, resolution, and profile"""
|
56 |
+
eq_(len(self.yt.filter('mp4', '360p', 'Baseline')), 1)
|
57 |
+
|
58 |
+
def test_filter_video_by_profile(self):
|
59 |
+
"""Filter videos by file profile"""
|
60 |
+
eq_(len(self.yt.filter(profile='Simple')), 2)
|
61 |
+
|
62 |
+
def test_filter_video_by_resolution(self):
|
63 |
+
"""Filter videos by resolution"""
|
64 |
+
eq_(len(self.yt.filter(resolution='360p')), 2)
|
65 |
+
|
66 |
+
@raises(MultipleObjectsReturned)
|
67 |
+
def test_get_multiple_itmes(self):
|
68 |
+
""".get(...) cannot return more than one video"""
|
69 |
+
self.yt.get(profile='Simple')
|
70 |
+
self.yt.get('mp4')
|
71 |
+
self.yt.get(resolution='240p')
|
tests/test_requirements.txt
CHANGED
@@ -1 +1,2 @@
|
|
|
|
1 |
nose==1.3.7
|
|
|
1 |
+
mock==1.3.0
|
2 |
nose==1.3.7
|