Skip to content

Commit

Permalink
Chore: Improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Apr 15, 2024
1 parent 5035451 commit 51df865
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
7 changes: 7 additions & 0 deletions imagecast/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
# (c) 2020-2021 Andreas Motl <andreas@hiveeyes.org>
# License: GNU Affero General Public License, Version 3
import io
import logging
import tempfile

import requests
from PIL import Image
from requests_cache import CachedSession


logger = logging.getLogger(__name__)


class ImageEngine:

http = None
Expand Down Expand Up @@ -98,6 +102,9 @@ def to_buffer(self, format, dpi):

def process(options):
ie = ImageEngine(cache_ttl=options.cache_ttl)

logger.info(f"Acquiring image from {options.uri}")

ie.acquire(options.uri, options.element)
ie.read()

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
minversion = "2.0"
addopts = "-rsfEX -p pytester --strict-markers --verbosity=3"
log_level = "DEBUG"
log_cli_level = "DEBUG"
testpaths = ["test"]
xfail_strict = true
markers = [
Expand Down
14 changes: 12 additions & 2 deletions test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_api_index():
assert re.match(r".*<title>imagecast [\d.]+</title>.*", response.text, re.DOTALL)


def test_api_unsplash_converge():
def test_api_unsplash_converge(caplog):
"""
Verify image management works.
"""
Expand All @@ -37,11 +37,16 @@ def test_api_unsplash_converge():
"width": "640",
}
response = client.get("/", params=query_params)

# Verify log output.
assert "Acquiring image from https://unsplash.com/photos/WvdKljW55rM/download?force=true" in caplog.messages

# Verify content output.
assert response.status_code == 200
assert response.content.startswith(b"\xff\xd8\xff\xe0\x00\x10JFIF")


def test_api_html_acquire():
def test_api_html_acquire(caplog):
"""
Verify HTML DOM element acquisition works.
"""
Expand All @@ -50,5 +55,10 @@ def test_api_html_acquire():
"element": "#logo",
}
response = client.get("/", params=query_params)

# Verify log output.
assert "Acquiring image from https://www.iana.org/help/example-domains" in caplog.messages

# Verify content output.
assert response.status_code == 200
assert response.content.startswith(b"\x89PNG\r\n\x1a")
4 changes: 2 additions & 2 deletions test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_cli_unsplash_converge(tmp_path, caplog):
imagecast.cli.run()

# Verify log output.
assert "Starting new HTTPS connection (1): unsplash.com:443" in caplog.messages
assert "Acquiring image from https://unsplash.com/photos/WvdKljW55rM/download?force=true" in caplog.messages

# Verify content output.
payload = output_file.read_bytes()
Expand All @@ -52,7 +52,7 @@ def test_cli_html_acquire(tmp_path, caplog):
imagecast.cli.run()

# Verify log output.
assert "Starting new HTTPS connection (1): www.iana.org:443" in caplog.messages
assert "Acquiring image from https://www.iana.org/help/example-domains" in caplog.messages

# Verify content output.
payload = output_file.read_bytes()
Expand Down

0 comments on commit 51df865

Please sign in to comment.