Skip to content

Commit

Permalink
Solve issues after functionality extraction from cartuli
Browse files Browse the repository at this point in the history
  • Loading branch information
pablerass committed Sep 21, 2023
1 parent fab0981 commit e3b84e6
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 48 deletions.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
reportlab==4.*
opencv-python==4.*
pillow==10.*
pyyaml==6.*
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpver]
current_version = "v0.1.0b1"
current_version = "v0.1.0b0"
version_pattern = "vMAJOR.MINOR.PATCH[PYTAGNUM]"
commit_message = "bump version {old_version} -> {new_version}"
commit = True
Expand All @@ -19,7 +19,7 @@ source = .
omit = conftest.py,setup.py,build/*,dist/*,docs/*,tests/*,.tox/*

[coverage:report]
fail_under = 70
fail_under = 50

[flake8]
exclude = conftest.py,setup.py,build/*,dist/*,docs/*,.tox/*
Expand Down
15 changes: 3 additions & 12 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
import shutil
import tempfile

from collections import namedtuple
from pathlib import Path
from PIL import Image


from carpeta.card import CardImage
from carpeta.measure import Size, STANDARD

Size = namedtuple("Size", "width height")


TEST_PATH = Path(__file__).resolve().parent
Expand Down Expand Up @@ -62,12 +61,4 @@ def create_temp_file(subpath: Path = None, /, size: Size = None):
yield create_temp_file

if temp_dir.exists():
shutil.rmtree(temp_dir)


@pytest.fixture
def random_card_image(random_image) -> CardImage:
def create_temp_card_image(subpath: Path = None, /, size: Size = STANDARD):
return CardImage(random_image(subpath), size=size)

return create_temp_card_image
shutil.rmtree(temp_dir)
33 changes: 33 additions & 0 deletions tests/test_logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import logging

from PIL import Image

from carpeta import Tracer, ImageHandler


def logger_process_image(image: Image.Image):
logger = logging.getLogger('logger_process_image')
logger.info("", extra={'trace': image})
bw_image = image.convert("L")
logger.info("", extra={'trace': bw_image})
return bw_image


# TUNE: This probably could be implemented as parametrization of test_trace.py::test_trace
def test_logging(random_image_file):
tracer = Tracer()
handler = ImageHandler(tracer, logging.INFO)
logger = logging.getLogger('logger_process_image')
logger.setLevel(logging.INFO)
logger.addHandler(handler)

image = Image.open(random_image_file())
processed_image = logger_process_image(image)

assert tracer[0][0].image == image
assert tracer[0][0].function_name == 'logger_process_image'
assert tracer[0][0].line_number == 10
assert tracer[0][1].image == processed_image
assert tracer[0][1].function_name == 'logger_process_image'
assert tracer[0][1].line_number == 12
assert tracer[0][0].timestamp < tracer[0][1].timestamp
Empty file added tests/test_output.py
Empty file.
36 changes: 3 additions & 33 deletions tests/test_tracing.py → tests/test_trace.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import logging

from PIL import Image, ImageOps

from carpeta.tracing import Tracer, ImageHandler
from carpeta import Tracer


def tracer_process_image(image: Image.Image, tracer: Tracer):
Expand All @@ -19,14 +17,6 @@ def tracer_reprocess_image(image: Image.Image, tracer: Tracer):
return inverted_image


def logger_process_image(image: Image.Image):
logger = logging.getLogger('logger_process_image')
logger.info("", extra={'trace': image})
bw_image = image.convert("L")
logger.info("", extra={'trace': bw_image})
return bw_image


def test_tracer(random_image_file):
tracer = Tracer()

Expand All @@ -35,10 +25,10 @@ def test_tracer(random_image_file):

assert tracer[0][0].image == image
assert tracer[0][0].function_name == 'tracer_process_image'
assert tracer[0][0].line_number == 9
assert tracer[0][0].line_number == 7
assert tracer[0][1].image == processed_image
assert tracer[0][1].function_name == 'tracer_process_image'
assert tracer[0][1].line_number == 11
assert tracer[0][1].line_number == 9
assert tracer[0][0].timestamp < tracer[0][1].timestamp

assert len(tracer) == 1
Expand All @@ -56,26 +46,6 @@ def test_tracer(random_image_file):
assert tracer[1][3].previous == tracer[1][2]


# TUNE: This probably could be implemented as parametrization of the previous test
def test_logging(random_image_file):
tracer = Tracer()
handler = ImageHandler(tracer, logging.INFO)
logger = logging.getLogger('logger_process_image')
logger.setLevel(logging.INFO)
logger.addHandler(handler)

image = Image.open(random_image_file())
processed_image = logger_process_image(image)

assert tracer[0][0].image == image
assert tracer[0][0].function_name == 'logger_process_image'
assert tracer[0][0].line_number == 24
assert tracer[0][1].image == processed_image
assert tracer[0][1].function_name == 'logger_process_image'
assert tracer[0][1].line_number == 26
assert tracer[0][0].timestamp < tracer[0][1].timestamp


def test_trace_image_file(random_image_file):
tracer = Tracer()

Expand Down

0 comments on commit e3b84e6

Please sign in to comment.