Skip to content

Commit

Permalink
Merge pull request #194 from ltm/fix-log-level
Browse files Browse the repository at this point in the history
Fix log-level option
  • Loading branch information
menkej authored Oct 30, 2020
2 parents faf439b + 0ec1af0 commit 988788f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- fix: --log-level option [#194](https://github.com/icloud-photos-downloader/icloud_photos_downloader/pull/194)
- feature: Folder structure can be set to 'none' instead of a date pattern,
so all photos will be placed directly into the download directory.
- fix: Empty directory structure being created #185
Expand Down
5 changes: 2 additions & 3 deletions icloudpd/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import sys
import logging
from logging import DEBUG, INFO
from logging import INFO


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


def setup_logger(loglevel=DEBUG):
def setup_logger():
"""Set up logger and add stdout handler"""
logging.setLoggerClass(IPDLogger)
logger = logging.getLogger("icloudpd")
logger.setLevel(loglevel)
has_stdout_handler = False
for handler in logger.handlers:
if handler.name == "stdoutLogger":
Expand Down
74 changes: 37 additions & 37 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
import os
import shutil
from vcr import VCR
import pytest
from click.testing import CliRunner
from icloudpd.base import main

vcr = VCR(decode_compressed_response=True)


class CliTestCase(TestCase):
@pytest.fixture(autouse=True)
def inject_fixtures(self, caplog):
self._caplog = caplog

def test_cli(self):
runner = CliRunner()
result = runner.invoke(main, ["--help"])
Expand All @@ -18,43 +23,38 @@ def test_cli(self):
def test_log_levels(self):
if not os.path.exists("tests/fixtures/Photos"):
os.makedirs("tests/fixtures/Photos")
with vcr.use_cassette("tests/vcr_cassettes/listing_photos.yml"):
# Pass fixed client ID via environment variable
os.environ["CLIENT_ID"] = "DE309E26-942E-11E8-92F5-14109FE0B321"
runner = CliRunner()
result = runner.invoke(
main,
[
"--username",
"[email protected]",
"--password",
"password1",
"--recent",
"0",
"--log-level",
"info",
"-d"
"tests/fixtures/Photos",
],
)
assert result.exit_code == 0
with vcr.use_cassette("tests/vcr_cassettes/listing_photos.yml"):
result = runner.invoke(
main,
[
"--username",
"[email protected]",
"--password",
"password1",
"--recent",
"0",
"--log-level",
"error",
"-d",
"tests/fixtures/Photos",
],
)
assert result.exit_code == 0

parameters = [
("debug", ["DEBUG", "INFO"], []),
("info", ["INFO"], ["DEBUG"]),
("error", [], ["DEBUG", "INFO"]),
]
for log_level, expected, not_expected in parameters:
self._caplog.clear()
with vcr.use_cassette("tests/vcr_cassettes/listing_photos.yml"):
# Pass fixed client ID via environment variable
os.environ["CLIENT_ID"] = "DE309E26-942E-11E8-92F5-14109FE0B321"
runner = CliRunner()
result = runner.invoke(
main,
[
"--username",
"[email protected]",
"--password",
"password1",
"--recent",
"0",
"--log-level",
log_level,
"-d"
"tests/fixtures/Photos",
],
)
assert result.exit_code == 0
for text in expected:
self.assertIn(text, self._caplog.text)
for text in not_expected:
self.assertNotIn(text, self._caplog.text)

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

0 comments on commit 988788f

Please sign in to comment.