Skip to content

Commit

Permalink
raise test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgineer85 committed May 18, 2024
1 parent 62ac38e commit 4012d17
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
6 changes: 0 additions & 6 deletions photobooth/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,9 @@ async def lifespan(_: FastAPI):

def terminate_now(signum: int, frame: FrameType = None):
logger.info("shutting down app via signal handler")

logger.info("stopping services")
container.stop()

logger.debug("invoking default_sigint_handler")
default_sigint_handler(signum, frame)

logger.debug(f"threads remaining after stopping container: {[thread.name for thread in threading.enumerate()]}")

if threading.current_thread() is not threading.main_thread():
# https://github.com/encode/uvicorn/pull/871
# Signals can only be listened to from the main thread.
Expand Down
1 change: 1 addition & 0 deletions photobooth/services/mediacollectionservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def delete_mediaitem_files(self, mediaitem: MediaItem):

try:
os.remove(mediaitem.path_original)
os.remove(mediaitem.metadata_filename)
os.remove(mediaitem.path_full_unprocessed)
os.remove(mediaitem.path_full)
os.remove(mediaitem.path_preview_unprocessed)
Expand Down
29 changes: 29 additions & 0 deletions tests/tests/test_mediacollection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import logging

import pytest

from photobooth.container import Container, container
from photobooth.services.mediacollectionservice import MediaItem

logger = logging.getLogger(name=None)


# need fixture on module scope otherwise tests fail because GPIO lib gets messed up
@pytest.fixture(scope="module")
def _container() -> Container:
container.start()
yield container
container.stop()


def test_ensure_scaled_repr_created(_container: Container):
"""this function processes single images (in contrast to collages or videos)"""

# get the newest image id
mediaitem_from_collection = _container.mediacollection_service.db_get_most_recent_mediaitem()

# create new instance and check against old one that metadata is avail.
mediaitem_new_instance = MediaItem(mediaitem_from_collection.filename, None) # load metadata from disk for exisiting element.

# should just run without any exceptions.
assert mediaitem_new_instance._config == mediaitem_from_collection._config
23 changes: 23 additions & 0 deletions tests/tests/test_mediaprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import pytest

from photobooth.container import Container, container
from photobooth.services.config import appconfig
from photobooth.services.config.models.models import PilgramFilter, SinglePictureDefinition

logger = logging.getLogger(name=None)

Expand All @@ -29,6 +31,27 @@ def test_ensure_scaled_repr_created(_container: Container):
raise AssertionError(f"'ensure_scaled_repr_created' raised an exception :( {exc}") from exc


def test_all_singleimage_processes(_container: Container):
"""this function processes single images (in contrast to collages or videos)"""

# get a new image
container.processing_service.trigger_action("image", 0)
container.processing_service.wait_until_job_finished()
mediaitem = _container.mediacollection_service.db_get_most_recent_mediaitem()

appconfig.mediaprocessing.removechromakey_enable = True
_config = SinglePictureDefinition(
filter=PilgramFilter.aden,
fill_background_enable=True,
img_background_enable=True,
img_frame_enable=True,
texts_enable=True,
)
mediaitem._config = _config.model_dump(mode="json") # if config is updated, it is automatically persisted to disk

container.mediaprocessing_service.process_image_collageimage_animationimage(mediaitem)


def test_ensure_scaled_repr_created_processed(_container: Container):
"""this function processes single images (in contrast to collages or videos)"""

Expand Down

0 comments on commit 4012d17

Please sign in to comment.