Skip to content

Commit 0ec1af0

Browse files
committed
Fix log-level option
1 parent faf439b commit 0ec1af0

File tree

3 files changed

+40
-40
lines changed

3 files changed

+40
-40
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

5+
- fix: --log-level option [#194](https://github.com/icloud-photos-downloader/icloud_photos_downloader/pull/194)
56
- feature: Folder structure can be set to 'none' instead of a date pattern,
67
so all photos will be placed directly into the download directory.
78
- fix: Empty directory structure being created #185

icloudpd/logger.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import sys
44
import logging
5-
from logging import DEBUG, INFO
5+
from logging import INFO
66

77

88
class IPDLogger(logging.Logger):
@@ -32,11 +32,10 @@ def tqdm_write(self, message, loglevel=INFO):
3232
self.tqdm.write(message)
3333

3434

35-
def setup_logger(loglevel=DEBUG):
35+
def setup_logger():
3636
"""Set up logger and add stdout handler"""
3737
logging.setLoggerClass(IPDLogger)
3838
logger = logging.getLogger("icloudpd")
39-
logger.setLevel(loglevel)
4039
has_stdout_handler = False
4140
for handler in logger.handlers:
4241
if handler.name == "stdoutLogger":

tests/test_cli.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@
33
import os
44
import shutil
55
from vcr import VCR
6+
import pytest
67
from click.testing import CliRunner
78
from icloudpd.base import main
89

910
vcr = VCR(decode_compressed_response=True)
1011

1112

1213
class CliTestCase(TestCase):
14+
@pytest.fixture(autouse=True)
15+
def inject_fixtures(self, caplog):
16+
self._caplog = caplog
17+
1318
def test_cli(self):
1419
runner = CliRunner()
1520
result = runner.invoke(main, ["--help"])
@@ -18,43 +23,38 @@ def test_cli(self):
1823
def test_log_levels(self):
1924
if not os.path.exists("tests/fixtures/Photos"):
2025
os.makedirs("tests/fixtures/Photos")
21-
with vcr.use_cassette("tests/vcr_cassettes/listing_photos.yml"):
22-
# Pass fixed client ID via environment variable
23-
os.environ["CLIENT_ID"] = "DE309E26-942E-11E8-92F5-14109FE0B321"
24-
runner = CliRunner()
25-
result = runner.invoke(
26-
main,
27-
[
28-
"--username",
29-
"jdoe@gmail.com",
30-
"--password",
31-
"password1",
32-
"--recent",
33-
"0",
34-
"--log-level",
35-
"info",
36-
"-d"
37-
"tests/fixtures/Photos",
38-
],
39-
)
40-
assert result.exit_code == 0
41-
with vcr.use_cassette("tests/vcr_cassettes/listing_photos.yml"):
42-
result = runner.invoke(
43-
main,
44-
[
45-
"--username",
46-
"jdoe@gmail.com",
47-
"--password",
48-
"password1",
49-
"--recent",
50-
"0",
51-
"--log-level",
52-
"error",
53-
"-d",
54-
"tests/fixtures/Photos",
55-
],
56-
)
57-
assert result.exit_code == 0
26+
27+
parameters = [
28+
("debug", ["DEBUG", "INFO"], []),
29+
("info", ["INFO"], ["DEBUG"]),
30+
("error", [], ["DEBUG", "INFO"]),
31+
]
32+
for log_level, expected, not_expected in parameters:
33+
self._caplog.clear()
34+
with vcr.use_cassette("tests/vcr_cassettes/listing_photos.yml"):
35+
# Pass fixed client ID via environment variable
36+
os.environ["CLIENT_ID"] = "DE309E26-942E-11E8-92F5-14109FE0B321"
37+
runner = CliRunner()
38+
result = runner.invoke(
39+
main,
40+
[
41+
"--username",
42+
"jdoe@gmail.com",
43+
"--password",
44+
"password1",
45+
"--recent",
46+
"0",
47+
"--log-level",
48+
log_level,
49+
"-d"
50+
"tests/fixtures/Photos",
51+
],
52+
)
53+
assert result.exit_code == 0
54+
for text in expected:
55+
self.assertIn(text, self._caplog.text)
56+
for text in not_expected:
57+
self.assertNotIn(text, self._caplog.text)
5858

5959
def test_tqdm(self):
6060
if not os.path.exists("tests/fixtures/Photos"):

0 commit comments

Comments
 (0)