add test for downloading caption with target directory
Browse files- tests/test_captions.py +16 -2
tests/test_captions.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
from unittest import mock
|
2 |
-
from unittest.mock import patch, mock_open
|
3 |
|
4 |
-
from pytube import Caption, CaptionQuery
|
5 |
|
6 |
|
7 |
def test_float_to_srt_time_format():
|
@@ -68,6 +68,20 @@ def test_download_with_prefix(srt):
|
|
68 |
assert open_mock.call_args_list[0][0][0].split("/")[-1] == "1 title (en).srt"
|
69 |
|
70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
@mock.patch("pytube.captions.Caption.xml_captions")
|
72 |
def test_download_xml_and_trim_extension(xml):
|
73 |
open_mock = mock_open()
|
|
|
1 |
from unittest import mock
|
2 |
+
from unittest.mock import patch, mock_open, MagicMock
|
3 |
|
4 |
+
from pytube import Caption, CaptionQuery, captions
|
5 |
|
6 |
|
7 |
def test_float_to_srt_time_format():
|
|
|
68 |
assert open_mock.call_args_list[0][0][0].split("/")[-1] == "1 title (en).srt"
|
69 |
|
70 |
|
71 |
+
@mock.patch("pytube.captions.Caption.generate_srt_captions")
|
72 |
+
def test_download_with_output_path(srt):
|
73 |
+
open_mock = mock_open()
|
74 |
+
captions.target_directory = MagicMock(return_value="/target")
|
75 |
+
with patch("builtins.open", open_mock):
|
76 |
+
srt.return_value = ""
|
77 |
+
caption = Caption(
|
78 |
+
{"url": "url1", "name": {"simpleText": "name1"}, "languageCode": "en"}
|
79 |
+
)
|
80 |
+
file_path = caption.download("title", output_path="blah")
|
81 |
+
assert file_path == "/target/title (en).srt"
|
82 |
+
captions.target_directory.assert_called_with("blah")
|
83 |
+
|
84 |
+
|
85 |
@mock.patch("pytube.captions.Caption.xml_captions")
|
86 |
def test_download_xml_and_trim_extension(xml):
|
87 |
open_mock = mock_open()
|