hbmartin commited on
Commit
cf801d3
·
1 Parent(s): fbfae95

added tests

Browse files
Files changed (2) hide show
  1. tests/test_cli.py +15 -0
  2. tests/test_helpers.py +13 -1
tests/test_cli.py CHANGED
@@ -153,12 +153,27 @@ def test_parse_args_truthy():
153
  "en",
154
  "-l",
155
  "--itag=10",
 
156
  ],
157
  )
158
  assert args.url == "http://youtube.com/watch?v=9bZkp7q19f0"
159
  assert args.build_playback_report is True
160
  assert args.itag == 10
161
  assert args.list is True
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
 
163
 
164
  @mock.patch("pytube.cli.YouTube", return_value=None)
 
153
  "en",
154
  "-l",
155
  "--itag=10",
156
+ "-vvv",
157
  ],
158
  )
159
  assert args.url == "http://youtube.com/watch?v=9bZkp7q19f0"
160
  assert args.build_playback_report is True
161
  assert args.itag == 10
162
  assert args.list is True
163
+ assert args.verbosity == 3
164
+
165
+
166
+ @mock.patch("pytube.cli.setup_logger", return_value=None)
167
+ def test_main_logging_setup(setup_logger):
168
+ # Given
169
+ parser = argparse.ArgumentParser()
170
+ args = parse_args(parser, ["http://fakeurl", "-v"])
171
+ cli._parse_args = MagicMock(return_value=args)
172
+ # When
173
+ with pytest.raises(SystemExit):
174
+ cli.main()
175
+ # Then
176
+ setup_logger.assert_called_with(40)
177
 
178
 
179
  @mock.patch("pytube.cli.YouTube", return_value=None)
tests/test_helpers.py CHANGED
@@ -5,7 +5,7 @@ import pytest
5
 
6
  from pytube import helpers
7
  from pytube.exceptions import RegexMatchError
8
- from pytube.helpers import deprecated, cache, target_directory
9
 
10
 
11
  def test_regex_search_no_match():
@@ -74,3 +74,15 @@ def test_target_directory_with_absolute_path(_, makedirs):
74
  def test_target_directory_with_no_path(_, makedirs):
75
  assert target_directory() == "/cwd"
76
  makedirs.assert_called()
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  from pytube import helpers
7
  from pytube.exceptions import RegexMatchError
8
+ from pytube.helpers import deprecated, cache, target_directory, setup_logger
9
 
10
 
11
  def test_regex_search_no_match():
 
74
  def test_target_directory_with_no_path(_, makedirs):
75
  assert target_directory() == "/cwd"
76
  makedirs.assert_called()
77
+
78
+
79
+ @mock.patch("pytube.helpers.logging")
80
+ def test_setup_logger(logging):
81
+ # Given
82
+ logger = logging.getLogger.return_value
83
+ # When
84
+ setup_logger(20)
85
+ # Then
86
+ logging.getLogger.assert_called_with("pytube")
87
+ logger.addHandler.assert_called()
88
+ logger.setLevel.assert_called_with(20)