Taylor Fox Dahlin commited on
Fix test to no longer make web requests. (#1048)
Browse files* Update mock so that stream raises HTTPError, rather than head, and simplified some other mocks.
* pep8-naming updated, adding a new ignore
- .flake8 +1 -1
- tests/test_streams.py +9 -9
.flake8
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
[flake8]
|
| 2 |
-
ignore = E231,E203,W503,Q000,WPS111,WPS305,WPS348,WPS602,D400,DAR201,S101,DAR101,C812,D104,I001,WPS306,WPS214,D401,WPS229,WPS420,WPS230,WPS414,WPS114,WPS226,WPS442,C819,WPS601,T001,RST304,WPS410,WPS428,A003,A002,I003,WPS221,WPS326,WPS201,S405,DAR301,WPS210,WPS202,WPS213,WPS301,P103,WPS407,WPS432,WPS211,S314,S310,S001,IF100,PT001,PT019,R504
|
| 3 |
max-line-length = 95
|
| 4 |
|
| 5 |
[isort]
|
|
|
|
| 1 |
[flake8]
|
| 2 |
+
ignore = E231,E203,W503,Q000,WPS111,WPS305,WPS348,WPS602,D400,DAR201,S101,DAR101,C812,D104,I001,WPS306,WPS214,D401,WPS229,WPS420,WPS230,WPS414,WPS114,WPS226,WPS442,C819,WPS601,T001,RST304,WPS410,WPS428,A003,A002,I003,WPS221,WPS326,WPS201,S405,DAR301,WPS210,WPS202,WPS213,WPS301,P103,WPS407,WPS432,WPS211,S314,S310,S001,IF100,PT001,PT019,R504,N818
|
| 3 |
max-line-length = 95
|
| 4 |
|
| 5 |
[isort]
|
tests/test_streams.py
CHANGED
|
@@ -114,7 +114,7 @@ def test_views(cipher_signature):
|
|
| 114 |
"pytube.streams.request.head", MagicMock(return_value={"content-length": "6796391"})
|
| 115 |
)
|
| 116 |
@mock.patch(
|
| 117 |
-
"pytube.
|
| 118 |
MagicMock(return_value=iter([str(random.getrandbits(8 * 1024))])),
|
| 119 |
)
|
| 120 |
def test_download(cipher_signature):
|
|
@@ -127,7 +127,7 @@ def test_download(cipher_signature):
|
|
| 127 |
"pytube.streams.request.head", MagicMock(return_value={"content-length": "16384"})
|
| 128 |
)
|
| 129 |
@mock.patch(
|
| 130 |
-
"pytube.
|
| 131 |
MagicMock(return_value=iter([str(random.getrandbits(8 * 1024))])),
|
| 132 |
)
|
| 133 |
@mock.patch("pytube.streams.target_directory", MagicMock(return_value="/target"))
|
|
@@ -145,7 +145,7 @@ def test_download_with_prefix(cipher_signature):
|
|
| 145 |
"pytube.streams.request.head", MagicMock(return_value={"content-length": "16384"})
|
| 146 |
)
|
| 147 |
@mock.patch(
|
| 148 |
-
"pytube.
|
| 149 |
MagicMock(return_value=iter([str(random.getrandbits(8 * 1024))])),
|
| 150 |
)
|
| 151 |
@mock.patch("pytube.streams.target_directory", MagicMock(return_value="/target"))
|
|
@@ -163,7 +163,7 @@ def test_download_with_filename(cipher_signature):
|
|
| 163 |
"pytube.streams.request.head", MagicMock(return_value={"content-length": "16384"})
|
| 164 |
)
|
| 165 |
@mock.patch(
|
| 166 |
-
"pytube.
|
| 167 |
MagicMock(return_value=iter([str(random.getrandbits(8 * 1024))])),
|
| 168 |
)
|
| 169 |
@mock.patch("pytube.streams.target_directory", MagicMock(return_value="/target"))
|
|
@@ -184,7 +184,7 @@ def test_download_with_existing(cipher_signature):
|
|
| 184 |
"pytube.streams.request.head", MagicMock(return_value={"content-length": "16384"})
|
| 185 |
)
|
| 186 |
@mock.patch(
|
| 187 |
-
"pytube.
|
| 188 |
MagicMock(return_value=iter([str(random.getrandbits(8 * 1024))])),
|
| 189 |
)
|
| 190 |
@mock.patch("pytube.streams.target_directory", MagicMock(return_value="/target"))
|
|
@@ -215,7 +215,7 @@ def test_progressive_streams_return_includes_video_track(cipher_signature):
|
|
| 215 |
"pytube.streams.request.head", MagicMock(return_value={"content-length": "16384"})
|
| 216 |
)
|
| 217 |
@mock.patch(
|
| 218 |
-
"pytube.
|
| 219 |
MagicMock(return_value=iter([str(random.getrandbits(8 * 1024))])),
|
| 220 |
)
|
| 221 |
def test_on_progress_hook(cipher_signature):
|
|
@@ -236,7 +236,7 @@ def test_on_progress_hook(cipher_signature):
|
|
| 236 |
"pytube.streams.request.head", MagicMock(return_value={"content-length": "16384"})
|
| 237 |
)
|
| 238 |
@mock.patch(
|
| 239 |
-
"pytube.
|
| 240 |
MagicMock(return_value=iter([str(random.getrandbits(8 * 1024))])),
|
| 241 |
)
|
| 242 |
def test_on_complete_hook(cipher_signature):
|
|
@@ -382,8 +382,8 @@ def test_segmented_stream_on_404(cipher_signature):
|
|
| 382 |
|
| 383 |
def test_segmented_only_catches_404(cipher_signature):
|
| 384 |
stream = cipher_signature.streams.filter(adaptive=True)[0]
|
| 385 |
-
with mock.patch('pytube.request.
|
| 386 |
-
|
| 387 |
with mock.patch("pytube.streams.open", mock.mock_open(), create=True):
|
| 388 |
with pytest.raises(HTTPError):
|
| 389 |
stream.download()
|
|
|
|
| 114 |
"pytube.streams.request.head", MagicMock(return_value={"content-length": "6796391"})
|
| 115 |
)
|
| 116 |
@mock.patch(
|
| 117 |
+
"pytube.request.stream",
|
| 118 |
MagicMock(return_value=iter([str(random.getrandbits(8 * 1024))])),
|
| 119 |
)
|
| 120 |
def test_download(cipher_signature):
|
|
|
|
| 127 |
"pytube.streams.request.head", MagicMock(return_value={"content-length": "16384"})
|
| 128 |
)
|
| 129 |
@mock.patch(
|
| 130 |
+
"pytube.request.stream",
|
| 131 |
MagicMock(return_value=iter([str(random.getrandbits(8 * 1024))])),
|
| 132 |
)
|
| 133 |
@mock.patch("pytube.streams.target_directory", MagicMock(return_value="/target"))
|
|
|
|
| 145 |
"pytube.streams.request.head", MagicMock(return_value={"content-length": "16384"})
|
| 146 |
)
|
| 147 |
@mock.patch(
|
| 148 |
+
"pytube.request.stream",
|
| 149 |
MagicMock(return_value=iter([str(random.getrandbits(8 * 1024))])),
|
| 150 |
)
|
| 151 |
@mock.patch("pytube.streams.target_directory", MagicMock(return_value="/target"))
|
|
|
|
| 163 |
"pytube.streams.request.head", MagicMock(return_value={"content-length": "16384"})
|
| 164 |
)
|
| 165 |
@mock.patch(
|
| 166 |
+
"pytube.request.stream",
|
| 167 |
MagicMock(return_value=iter([str(random.getrandbits(8 * 1024))])),
|
| 168 |
)
|
| 169 |
@mock.patch("pytube.streams.target_directory", MagicMock(return_value="/target"))
|
|
|
|
| 184 |
"pytube.streams.request.head", MagicMock(return_value={"content-length": "16384"})
|
| 185 |
)
|
| 186 |
@mock.patch(
|
| 187 |
+
"pytube.request.stream",
|
| 188 |
MagicMock(return_value=iter([str(random.getrandbits(8 * 1024))])),
|
| 189 |
)
|
| 190 |
@mock.patch("pytube.streams.target_directory", MagicMock(return_value="/target"))
|
|
|
|
| 215 |
"pytube.streams.request.head", MagicMock(return_value={"content-length": "16384"})
|
| 216 |
)
|
| 217 |
@mock.patch(
|
| 218 |
+
"pytube.request.stream",
|
| 219 |
MagicMock(return_value=iter([str(random.getrandbits(8 * 1024))])),
|
| 220 |
)
|
| 221 |
def test_on_progress_hook(cipher_signature):
|
|
|
|
| 236 |
"pytube.streams.request.head", MagicMock(return_value={"content-length": "16384"})
|
| 237 |
)
|
| 238 |
@mock.patch(
|
| 239 |
+
"pytube.request.stream",
|
| 240 |
MagicMock(return_value=iter([str(random.getrandbits(8 * 1024))])),
|
| 241 |
)
|
| 242 |
def test_on_complete_hook(cipher_signature):
|
|
|
|
| 382 |
|
| 383 |
def test_segmented_only_catches_404(cipher_signature):
|
| 384 |
stream = cipher_signature.streams.filter(adaptive=True)[0]
|
| 385 |
+
with mock.patch('pytube.request.stream') as mock_stream:
|
| 386 |
+
mock_stream.side_effect = HTTPError('', 403, 'Forbidden', '', '')
|
| 387 |
with mock.patch("pytube.streams.open", mock.mock_open(), create=True):
|
| 388 |
with pytest.raises(HTTPError):
|
| 389 |
stream.download()
|