Skip to content

Commit 2e4ce6b

Browse files
committed
add docstrings
1 parent b917be6 commit 2e4ce6b

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

tests/commands/test_video_info.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,26 @@
88

99
@pytest.fixture
1010
def youtube_mock(mocker, mock_video_info):
11+
"""Fixture to mock the YouTube instance and its videos_infos method."""
1112
mock = mocker.patch("youtool.commands.video_info.YouTube")
1213
mock_instance = mock.return_value
1314
mock_instance.videos_infos = Mock(return_value=mock_video_info)
1415
return mock_instance
1516

1617
@pytest.fixture
1718
def mock_video_info():
19+
"""Fixture to return mock video information."""
1820
return [
1921
{"id": "tmrhPou85HQ", "title": "Title 1", "description": "Description 1", "published_at": "2021-01-01", "view_count": 100, "like_count": 10, "comment_count": 5},
2022
{"id": "qoI_x9fylaw", "title": "Title 2", "description": "Description 2", "published_at": "2021-02-01", "view_count": 200, "like_count": 20, "comment_count": 10}
2123
]
2224

2325
def test_execute_with_ids_and_urls(youtube_mock, mocker, tmp_path, mock_video_info):
26+
"""Test the execute method with provided video IDs and URLs.
27+
28+
This test verifies that the execute method can handle both video IDs and URLs,
29+
and correctly writes the video information to the output CSV file.
30+
"""
2431
ids = ["tmrhPou85HQ", "qoI_x9fylaw"]
2532
urls = ["https://www.youtube.com/watch?v=tmrhPou85HQ&ab_channel=Turicas", "https://www.youtube.com/watch?v=qoI_x9fylaw&ab_channel=PythonicCaf%C3%A9"]
2633
output_file_path = tmp_path / "output.csv"
@@ -36,12 +43,25 @@ def test_execute_with_ids_and_urls(youtube_mock, mocker, tmp_path, mock_video_in
3643
assert csv_data[1]["id"] == "qoI_x9fylaw"
3744

3845
def test_execute_missing_arguments():
46+
"""Test the execute method raises an exception when missing required arguments.
47+
48+
This test verifies that the execute method raises an exception if neither
49+
video IDs nor URLs are provided.
50+
51+
Raises:
52+
Exception: If neither 'ids' nor 'urls' is provided.
53+
"""
3954
with pytest.raises(Exception) as exc_info:
4055
VideoInfo.execute(api_key="test_api_key")
4156

4257
assert str(exc_info.value) == "Either 'ids' or 'urls' must be provided for the video-info command"
4358

4459
def test_execute_with_input_file_path(youtube_mock, mocker, tmp_path, mock_video_info):
60+
"""Test the execute method with an input CSV file containing video URLs and IDs.
61+
62+
This test verifies that the execute method can read video URLs and IDs from
63+
an input CSV file and correctly writes the video information to the output CSV file.
64+
"""
4565
input_csv_content = """video_id,video_url
4666
tmrhPou85HQ,https://www.youtube.com/watch?v=tmrhPou85HQ&ab_channel=Turicas
4767
qoI_x9fylaw,https://www.youtube.com/watch?v=qoI_x9fylaw&ab_channel=PythonicCaf%C3%A9
@@ -64,6 +84,12 @@ def test_execute_with_input_file_path(youtube_mock, mocker, tmp_path, mock_video
6484

6585

6686
def test_execute_with_info_columns(youtube_mock, mocker, tmp_path, mock_video_info):
87+
"""Test the execute method with specified info columns.
88+
89+
This test verifies that the execute method can filter the video information
90+
based on specified columns and correctly writes the filtered information
91+
to the output CSV file.
92+
"""
6793
ids = ["tmrhPou85HQ", "qoI_x9fylaw"]
6894
output_file_path = tmp_path / "output.csv"
6995

youtool/commands/video_info.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,24 @@ def execute(cls: Self, **kwargs) -> str:
3232
Args:
3333
ids (list[str], optional): A list of YouTube video IDs. If not provided, input_file_path must be specified.
3434
urls (list[str], optional): A list of YouTube video URLs. If not provided, input_file_path must be specified.
35-
urls_file_path (str, optional): Path to a CSV file containing YouTube channel URLs.
36-
ids_file_path (str, optional): Path to a CSV file containing YouTube channel IDs.
3735
input_file_path (str, optional): Path to a CSV file containing YouTube video URLs or IDs.
3836
output_file_path (str, optional): Path to the output CSV file where video information will be saved.
3937
api_key (str): The API key to authenticate with the YouTube Data API.
4038
url_column_name (str, optional): The name of the column in the input_file_path CSV file that contains the URLs.
41-
Default is "video_url".
39+
Default is "video_url".
4240
id_column_name (str, optional): The name of the column in the input_file_path CSV file that contains the IDs.
4341
Default is "video_id".
44-
info_columns (str, optional): Comma-separated list of columns to include in the output CSV. Default is the class attribute INFO_COLUMNS.
42+
info_columns (str, optional): Comma-separated list of columns to include in the output CSV.
43+
Default is the class attribute INFO_COLUMNS.
4544
4645
Returns:
47-
A message indicating the result of the command. If output_file_path is specified,
48-
the message will include the path to the generated CSV file.
49-
Otherwise, it will return the result as a string.
46+
str: A message indicating the result of the command. If output_file_path is specified, the message will
47+
include the path to the generated CSV file. Otherwise, it will return the result as a string.
5048
5149
Raises:
5250
Exception: If neither ids, urls, nor input_file_path is provided.
5351
"""
52+
5453
ids = kwargs.get("ids", [])
5554
urls = kwargs.get("urls", [])
5655
input_file_path = kwargs.get("input_file_path")

0 commit comments

Comments
 (0)