Skip to content

Commit

Permalink
Fixed unittests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudius Röhl committed Oct 21, 2024
1 parent 1e2c007 commit a694636
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 89 deletions.
9 changes: 3 additions & 6 deletions modules/general/medialocalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from typing import List
import polars as pl
import gpxpy
from zoneinfo import ZoneInfo, available_timezones
from zoneinfo import ZoneInfo
import zoneinfo
import datetime
import folium

Expand Down Expand Up @@ -85,7 +86,6 @@ def __init__(
# TODO: add logic for inserting gps data to mediafiles based on given tracks
class MediaLocalizer(MediaTransitioner):
def __init__(self, input: LocalizerInput):

input.mediaFileFactory = createAnyValidMediaFile
super().__init__(input)
self.gps_time_tolerance = input.gps_time_tolerance
Expand All @@ -95,7 +95,7 @@ def __init__(self, input: LocalizerInput):
self.transition_even_if_no_gps_data = input.transition_even_if_no_gps_data
self.suppress_map_open = input.suppress_map_open

if self.mediafile_timezone not in available_timezones():
if self.mediafile_timezone not in zoneinfo.available_timezones():
self.print_info(
f"Timezone {self.mediafile_timezone} is an invalid time zone! Do nothing."
)
Expand Down Expand Up @@ -259,7 +259,6 @@ def getGpsDataForTime(
self,
mediafile_time: datetime.datetime,
) -> GpsData:

mediafile_time_in_gps_time = self.getNormalizedMediaFileTime(mediafile_time)

before_position, after_position = self.getBeforeAfterGpsData(
Expand All @@ -280,7 +279,6 @@ def getGpsDataForTime(
def getInterpolatedGpsData(
self, mediafile_time_in_gps_time, before: GpsData, after: GpsData
) -> GpsData:

if after.time == before.time:
return before

Expand Down Expand Up @@ -311,7 +309,6 @@ def getNormalizedMediaFileTime(self, mediafile_time) -> datetime.datetime:
def getBeforeAfterGpsData(
self, gps_time_tolerance, mediafile_time_in_gps_time
) -> tuple[pl.DataFrame, pl.DataFrame]:

before = self.positions.filter(
pl.col("time") < mediafile_time_in_gps_time,
pl.col("time") >= mediafile_time_in_gps_time - gps_time_tolerance,
Expand Down
2 changes: 1 addition & 1 deletion modules/image/imageaggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def treatTaskBasedOnRating(self, task: TransitionTask, rating: int):
self.deleteMediaFile(mfile)

task.skip = True
task.skipReason = "deleted file based on rating."
task.skipReason = "deleted file based on ratist_correctImageIsTransitiong."
case 2 | 3:
rawfile = mfile.getRaw()
if rawfile is None:
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ dependencies = [
"pillow>=11.0.0",
"polars>=1.10.0",
"pyexiftool>=0.5.6",
"pytest-cov>=5.0.0",
"pytest>=8.3.3",
"pyyaml>=6.0.2",
"rich>=13.9.2",
"tzdata>=2024.2",
]

[project.scripts]
Expand Down
64 changes: 31 additions & 33 deletions tests/test_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ def jpgWasDeleted(jpgname):

def rawWasDeleted(jpgname):
return exists(
join(src, DELETE_FOLDER_NAME, str(Path(jpgname.replace("jpg", "ORF")).relative_to(src)))
join(
src,
DELETE_FOLDER_NAME,
str(Path(jpgname.replace("jpg", "ORF")).relative_to(src)),
)
)


Expand All @@ -138,7 +142,7 @@ def test_correctImageIsTransitioned():
prepareTest(srcname=fullname)
assert bothFilesAreInSRC(fullname)

ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False, verbose=True))()
ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False))()

assert transitionTookPlace(fullname)

Expand All @@ -150,7 +154,7 @@ def test_wrongTimestampOfFileIsRecognized():

assert bothFilesAreInSRC(fullname)

ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False, verbose=True))()
ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False))()

assertTransitionTookNOTPlace(fullname)

Expand All @@ -162,7 +166,7 @@ def test_wrongTimestampOfGroupIsRecognized():

assert bothFilesAreInSRC(fullname)

ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False, verbose=True))()
ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False))()

assertTransitionTookNOTPlace(fullname)

Expand All @@ -174,7 +178,7 @@ def test_wrongDescriptionTagIsRecognized():

assert bothFilesAreInSRC(fullname)

ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False, verbose=True))()
ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False))()

assertTransitionTookNOTPlace(fullname)

Expand All @@ -186,7 +190,7 @@ def test_tooshortGroupnameIsRecognized():

assert bothFilesAreInSRC(fullname)

ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False, verbose=True))()
ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False))()

assertTransitionTookNOTPlace(fullname)

Expand All @@ -205,7 +209,7 @@ def test_differentXMPTagsBetweenJPGandRawAreRecognized():

assert bothFilesAreInSRC(fullname)

ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False, verbose=True))()
ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False))()

assertTransitionTookNOTPlace(fullname)

Expand All @@ -225,9 +229,7 @@ def test_jpgSingleSourceOfTruthWorks():
assert bothFilesAreInSRC(fullname)

ImageAggregator(
input=AggregatorInput(
src=src, dst=dst, dry=False, verbose=True, jpgSingleSourceOfTruth=True
)
input=AggregatorInput(src=src, dst=dst, dry=False, jpgSingleSourceOfTruth=True)
)()

assert transitionTookPlace(fullname)
Expand All @@ -244,9 +246,7 @@ def test_missingXMPTagSourceInRawIsCopiedFromJpg():
assert bothFilesAreInSRC(fullname)

ImageAggregator(
input=AggregatorInput(
src=src, dst=dst, dry=False, verbose=True, writeMetaTags=True
)
input=AggregatorInput(src=src, dst=dst, dry=False, writeMetaTags=True)
)()

assert bothFilesAreNOTinSRC(fullname)
Expand All @@ -269,7 +269,7 @@ def test_missingXMPTagSourceInJpgIsCopiedFromRaw():

assert bothFilesAreInSRC(fullname)

ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False, verbose=True))()
ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False))()

assert bothFilesAreNOTinSRC(fullname)
assert bothFilesAreInDST(fullname)
Expand All @@ -293,7 +293,7 @@ def test_missingXMPTagDescriptionIsCopiedFromRaw():

assert bothFilesAreInSRC(fullname)

ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False, verbose=True))()
ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False))()

assert bothFilesAreNOTinSRC(fullname)
assert bothFilesAreInDST(fullname)
Expand All @@ -319,7 +319,7 @@ def test_completelyMissingXMPTagDescriptionIsRecognized():

assert bothFilesAreInSRC(fullname)

ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False, verbose=True))()
ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False))()

assertTransitionTookNOTPlace(fullname)

Expand All @@ -335,7 +335,7 @@ def test_completelyMissingXMPTagDateIsRecognized():

assert bothFilesAreInSRC(fullname)

ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False, verbose=True))()
ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False))()

assertTransitionTookNOTPlace(fullname)

Expand All @@ -351,7 +351,7 @@ def test_missingXMPTagDateIsCopiedFromRaw():

assert bothFilesAreInSRC(fullname)

ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False, verbose=True))()
ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False))()

assert bothFilesAreNOTinSRC(fullname)
assert bothFilesAreInDST(fullname)
Expand All @@ -375,7 +375,7 @@ def test_completelyMissingXMPTagRatingIsRecognized():

assert bothFilesAreInSRC(fullname)

ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False, verbose=True))()
ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False))()

assertTransitionTookNOTPlace(fullname)

Expand All @@ -391,7 +391,7 @@ def test_missingXMPTagRatingIsCopiedFromRaw():

assert bothFilesAreInSRC(fullname)

ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False, verbose=True))()
ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False))()

assert bothFilesAreNOTinSRC(fullname)
assert bothFilesAreInDST(fullname)
Expand All @@ -417,7 +417,7 @@ def test_optionalXMPTagLabelIsCopiedFromJpg():

assert bothFilesAreInSRC(fullname)

ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False, verbose=True))()
ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False))()

assert bothFilesAreNOTinSRC(fullname)
assert bothFilesAreInDST(fullname)
Expand All @@ -440,7 +440,7 @@ def test_optionalXMPTagSubjectIsCopiedFromJpg():

assert bothFilesAreInSRC(fullname)

ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False, verbose=True))()
ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False))()

assert bothFilesAreNOTinSRC(fullname)
assert bothFilesAreInDST(fullname)
Expand Down Expand Up @@ -468,7 +468,7 @@ def test_optionalXMPTagHierarchicalSubjectIsCopiedFromJpg():

assert bothFilesAreInSRC(fullname)

ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False, verbose=True))()
ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False))()

assert bothFilesAreNOTinSRC(fullname)
assert bothFilesAreInDST(fullname)
Expand Down Expand Up @@ -503,7 +503,7 @@ def test_multipleHSubjectsAreNoProblem():

assert bothFilesAreInSRC(fullname)

ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False, verbose=True))()
ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False))()

assert bothFilesAreNOTinSRC(fullname)
assert bothFilesAreInDST(fullname)
Expand Down Expand Up @@ -540,7 +540,7 @@ def test_multipleHierarchicalSubjectsAreNoProblem():

assert bothFilesAreInSRC(fullname)

ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False, verbose=True))()
ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False))()

assert bothFilesAreNOTinSRC(fullname)
assert bothFilesAreInDST(fullname)
Expand Down Expand Up @@ -571,7 +571,7 @@ def test_rating1ImageIsMovedIntoDeleteFolder():

assert bothFilesAreInSRC(fullname)

ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False, verbose=True))()
ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False))()

assert bothFilesAreNOTinSRC(fullname)
assert bothFilesAreNOTInDST(fullname)
Expand All @@ -591,9 +591,7 @@ def test_rating1Rawrating5jpgAndJPGSingleSourceOfTruthDoesNotDelete():
assert bothFilesAreInSRC(fullname)

ImageAggregator(
input=AggregatorInput(
src=src, dst=dst, dry=False, verbose=True, jpgSingleSourceOfTruth=True
)
input=AggregatorInput(src=src, dst=dst, dry=False, jpgSingleSourceOfTruth=True)
)()

assert transitionTookPlace(fullname)
Expand All @@ -614,7 +612,7 @@ def test_rating2ImagesRawIsMovedIntoDeleteFolderJpgTransitioned():

assert bothFilesAreInSRC(fullname)

ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False, verbose=True))()
ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False))()

assert bothFilesAreNOTinSRC(fullname)

Expand All @@ -639,7 +637,7 @@ def test_rating3ImagesRawIsMovedIntoDeleteFolderJpgTransitioned():

assert bothFilesAreInSRC(fullname)

ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False, verbose=True))()
ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False))()

assert bothFilesAreNOTinSRC(fullname)

Expand All @@ -664,7 +662,7 @@ def test_rating4BothImagefilesAreTransitioned():

assert bothFilesAreInSRC(fullname)

ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False, verbose=True))()
ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False))()

assert transitionTookPlace(fullname)
assert not jpgWasDeleted(fullname) and not rawWasDeleted(fullname)
Expand All @@ -689,7 +687,7 @@ def test_rating5BothImagefilesAreTransitioned():

assert bothFilesAreInSRC(fullname)

ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False, verbose=True))()
ImageAggregator(input=AggregatorInput(src=src, dst=dst, dry=False))()

assert transitionTookPlace(fullname)
assert not jpgWasDeleted(fullname) and not rawWasDeleted(fullname)
Loading

0 comments on commit a694636

Please sign in to comment.