From 1a0a5f4482c89a88033fa36891b90c1cc33fba7d Mon Sep 17 00:00:00 2001 From: Maveno Date: Mon, 4 Nov 2024 12:54:22 +0100 Subject: [PATCH] Fix test pattern, Test-Limit --- bin/ffx/file_properties.py | 31 ++++++++++++++++++------------- bin/ffx/media_details_screen.py | 6 ++---- bin/ffx/pattern_details_screen.py | 10 +++++----- bin/ffx/test/scenario_1.py | 13 ++++++++----- bin/ffx/test/scenario_2.py | 16 ++++++++++++---- bin/ffx/test/scenario_4.py | 31 ++++++++++++++++++++----------- bin/ffx_tests.py | 6 ++++-- 7 files changed, 69 insertions(+), 44 deletions(-) diff --git a/bin/ffx/file_properties.py b/bin/ffx/file_properties.py index 21935e1..d75c69c 100644 --- a/bin/ffx/file_properties.py +++ b/bin/ffx/file_properties.py @@ -14,7 +14,8 @@ class FileProperties(): FILE_EXTENSIONS = ['mkv', 'mp4', 'avi', 'flv', 'webm'] - SEASON_EPISODE_INDICATOR_MATCH = '[sS]([0-9]+)[eE]([0-9]+)' + SE_INDICATOR_PATTERN = '([sS][0-9]+[eE][0-9]+)' + SEASON_EPISODE_INDICATOR_MATCH = '[sS]([0-9]+)[eE]([0-9]+)' EPISODE_INDICATOR_MATCH = '[eE]([0-9]+)' DEFAULT_INDEX_DIGITS = 3 @@ -48,14 +49,18 @@ class FileProperties(): # Checking if database contains matching pattern matchResult = self.__pc.matchFilename(self.__sourceFilename) - self.__logger.debug(f"FileProperties.__init__(): Match result {matchResult}") + self.__logger.debug(f"FileProperties.__init__(): Match result: {matchResult}") self.__pattern: Pattern = matchResult['pattern'] if matchResult else None if matchResult: databaseMatchedGroups = matchResult['match'].groups() - self.__season = databaseMatchedGroups[0] - self.__episode = databaseMatchedGroups[1] + self.__logger.debug(f"FileProperties.__init__(): Matched groups: {databaseMatchedGroups}") + + seIndicator = databaseMatchedGroups[0] + + se_match = re.search(FileProperties.SEASON_EPISODE_INDICATOR_MATCH, seIndicator) + e_match = re.search(FileProperties.EPISODE_INDICATOR_MATCH, seIndicator) else: self.__logger.debug(f"FileProperties.__init__(): Checking file name for indicator {self.__sourceFilename}") @@ -63,15 +68,15 @@ class FileProperties(): se_match = re.search(FileProperties.SEASON_EPISODE_INDICATOR_MATCH, self.__sourceFilename) e_match = re.search(FileProperties.EPISODE_INDICATOR_MATCH, self.__sourceFilename) - if se_match is not None: - self.__season = int(se_match.group(1)) - self.__episode = int(se_match.group(2)) - elif e_match is not None: - self.__season = -1 - self.__episode = int(e_match.group(1)) - else: - self.__season = -1 - self.__episode = -1 + if se_match is not None: + self.__season = int(se_match.group(1)) + self.__episode = int(se_match.group(2)) + elif e_match is not None: + self.__season = -1 + self.__episode = int(e_match.group(1)) + else: + self.__season = -1 + self.__episode = -1 def getFormatData(self): diff --git a/bin/ffx/media_details_screen.py b/bin/ffx/media_details_screen.py index fc27760..ae86978 100644 --- a/bin/ffx/media_details_screen.py +++ b/bin/ffx/media_details_screen.py @@ -419,14 +419,12 @@ class MediaDetailsScreen(Screen): if event.button.id == "pattern_button": - INDICATOR_PATTERN = '([sS][0-9]+[eE][0-9]+)' - pattern = self.query_one("#pattern_input", Input).value - patternMatch = re.search(INDICATOR_PATTERN, pattern) + patternMatch = re.search(FileProperties.SE_INDICATOR_PATTERN, pattern) if patternMatch: - self.query_one("#pattern_input", Input).value = pattern.replace(patternMatch.group(1), INDICATOR_PATTERN) + self.query_one("#pattern_input", Input).value = pattern.replace(patternMatch.group(1), FileProperties.SE_INDICATOR_PATTERN) if event.button.id == "select_default_button": diff --git a/bin/ffx/pattern_details_screen.py b/bin/ffx/pattern_details_screen.py index 01fa20c..38b1d9d 100644 --- a/bin/ffx/pattern_details_screen.py +++ b/bin/ffx/pattern_details_screen.py @@ -28,6 +28,8 @@ from ffx.track_descriptor import TrackDescriptor from textual.widgets._data_table import CellDoesNotExist +from ffx.file_properties import FileProperties + # Screen[dict[int, str, int]] class PatternDetailsScreen(Screen): @@ -387,15 +389,13 @@ class PatternDetailsScreen(Screen): if event.button.id == "pattern_button": - INDICATOR_PATTERN = '([sS][0-9]+[eE][0-9]+)' - pattern = self.query_one("#pattern_input", Input).value - patternMatch = re.search(INDICATOR_PATTERN, pattern) + patternMatch = re.search(FileProperties.SE_INDICATOR_PATTERN, pattern) if patternMatch: - self.query_one("#pattern_input", Input).value = pattern.replace(patternMatch.group(1), INDICATOR_PATTERN) - + self.query_one("#pattern_input", Input).value = pattern.replace(patternMatch.group(1), + FileProperties.SE_INDICATOR_PATTERN) def handle_add_track(self, trackDescriptor : TrackDescriptor): diff --git a/bin/ffx/test/scenario_1.py b/bin/ffx/test/scenario_1.py index a24f546..a430a8b 100644 --- a/bin/ffx/test/scenario_1.py +++ b/bin/ffx/test/scenario_1.py @@ -65,9 +65,12 @@ class Scenario1(Scenario): expectedFilename = f"{expectedBasename}.{Scenario1.EXPECTED_FILE_EXTENSION}" - if self._context['test_variant'] and variantIdentifier != self._context['test_variant']: + if self._context['test_variant'] and not variantIdentifier.startswith(self._context['test_variant']): return + if ((self._context['test_passed_counter'] + self._context['test_failed_counter']) + >= self._context['test_limit']): + return self._logger.debug(f"Running Job: {variantLabel}") @@ -93,9 +96,9 @@ class Scenario1(Scenario): commandSequence = [sys.executable, self._ffxExecutablePath] - # if self._context['verbosity']: - # commandSequence += ['--verbose', - # str(self._context['verbosity'])] + if self._context['verbosity']: + commandSequence += ['--verbose', + str(self._context['verbosity'])] commandSequence += ['convert', mediaFilePath, @@ -116,7 +119,7 @@ class Scenario1(Scenario): out, err, rc = executeProcess(commandSequence, directory = self._testDirectory) - if out: + if out and self._context['verbosity'] >= 9: self._logger.debug(f"{variantLabel}: Process output: {out}") if rc: self._logger.debug(f"{variantLabel}: Process returned ERROR {rc} ({err})") diff --git a/bin/ffx/test/scenario_2.py b/bin/ffx/test/scenario_2.py index f715f63..84d692e 100644 --- a/bin/ffx/test/scenario_2.py +++ b/bin/ffx/test/scenario_2.py @@ -64,10 +64,13 @@ class Scenario2(Scenario): jellyfinSelectorIndex = -1 - #if self._context['test_variant'] and variantIdentifier != self._context['test_variant']: if self._context['test_variant'] and not variantIdentifier.startswith(self._context['test_variant']): return + if ((self._context['test_passed_counter'] + self._context['test_failed_counter']) + >= self._context['test_limit']): + return + self._logger.debug(f"Running Job: {variantLabel}") @@ -83,8 +86,13 @@ class Scenario2(Scenario): # Phase 2: Run ffx commandSequence = [sys.executable, - self._ffxExecutablePath, - 'convert', + self._ffxExecutablePath] + + if self._context['verbosity']: + commandSequence += ['--verbose', + str(self._context['verbosity'])] + + commandSequence += ['convert', mediaFilePath, '--no-prompt'] @@ -96,7 +104,7 @@ class Scenario2(Scenario): out, err, rc = executeProcess(commandSequence, directory = self._testDirectory) - if out: + if out and self._context['verbosity'] >= 9: self._logger.debug(f"{variantLabel}: Process output: {out}") if rc: self._logger.debug(f"{variantLabel}: Process returned ERROR {rc} ({err})") diff --git a/bin/ffx/test/scenario_4.py b/bin/ffx/test/scenario_4.py index a516dfa..e10845f 100644 --- a/bin/ffx/test/scenario_4.py +++ b/bin/ffx/test/scenario_4.py @@ -33,7 +33,7 @@ class Scenario4(Scenario): TEST_FILE_LABEL = 'rotsh' TEST_FILE_EXTENSION = 'mkv' - TEST_PATTERN = f"{TEST_FILE_LABEL}_{FileProperties.SEASON_EPISODE_INDICATOR_MATCH}.{TEST_FILE_EXTENSION}" + TEST_PATTERN = f"{TEST_FILE_LABEL}_{FileProperties.SE_INDICATOR_PATTERN}.{TEST_FILE_EXTENSION}" EXPECTED_FILE_EXTENSION = 'webm' @@ -118,17 +118,22 @@ class Scenario4(Scenario): jellyfinSelectorIndex = -1 - if self._context['test_variant'] and variantIdentifier != self._context['test_variant']: + if self._context['test_variant'] and not variantIdentifier.startswith(self._context['test_variant']): return + if ((self._context['test_passed_counter'] + self._context['test_failed_counter']) + >= self._context['test_limit']): + return + + self._logger.debug(f"Running Job: {variantLabel}") + + for l in presetMediaDescriptor.getConfiguration(label = 'presetMediaDescriptor'): self._logger.debug(l) for l in sourceMediaDescriptor.getConfiguration(label = 'sourceMediaDescriptor'): self._logger.debug(l) - self._logger.debug(f"Running Job: {variantLabel}") - # Phase 1: Setup source files @@ -164,8 +169,13 @@ class Scenario4(Scenario): # Phase 3: Run ffx commandSequence = [sys.executable, - self._ffxExecutablePath, - '--database-file', + self._ffxExecutablePath] + + if self._context['verbosity']: + commandSequence += ['--verbose', + str(self._context['verbosity'])] + + commandSequence += ['--database-file', self._testDbFilePath, 'convert'] commandSequence += [tfo['filename'] for tfo in testFileList] @@ -179,8 +189,8 @@ class Scenario4(Scenario): out, err, rc = executeProcess(commandSequence, directory = self._testDirectory) - # if out: - # self._logger.debug(f"{variantLabel}: Process output: {out}") + if out and self._context['verbosity'] >= 9: + self._logger.debug(f"{variantLabel}: Process output: {out}") if rc: self._logger.debug(f"{variantLabel}: Process returned ERROR {rc} ({err})") @@ -258,14 +268,13 @@ class Scenario4(Scenario): self._context['test_passed_counter'] += 1 - self._reportLogger.info(f"{variantLabel}: Test passed") + self._reportLogger.info(f"\n{variantLabel}: Test passed\n") except AssertionError as ae: self._context['test_failed_counter'] += 1 - self._reportLogger.error(f"{variantLabel}: Test FAILED ({ae})") + self._reportLogger.error(f"\n{variantLabel}: Test FAILED ({ae})\n") - # exit() def run(self): diff --git a/bin/ffx_tests.py b/bin/ffx_tests.py index 6b3b542..9c4732f 100755 --- a/bin/ffx_tests.py +++ b/bin/ffx_tests.py @@ -75,8 +75,9 @@ def ffx(ctx, verbose, dry_run): @ffx.command() @click.pass_context @click.option('--scenario', type=str, default='', help='Only run tests from this scenario') -@click.option('--variant', type=str, default='', help='Only run this test variant') -def run(ctx, scenario, variant): +@click.option('--variant', type=str, default='', help='Only run variants beginning like this') +@click.option('--limit', type=int, default=0, help='Only run this number of tests') +def run(ctx, scenario, variant, limit): """Run ffx test sequences""" ctx.obj['logger'].info('Starting FFX test runs') @@ -84,6 +85,7 @@ def run(ctx, scenario, variant): ctx.obj['test_failed_counter'] = 0 ctx.obj['test_variant'] = variant + ctx.obj['test_limit'] = limit for si in Scenario.list():