def test_untag_interactive(self): user_choice = ["foo", "bar"] present_tags = ["foo", "bar", "bas"] class FrontendAnon(FrontendAdapter): def __init__(self): super().__init__() self.provided_options = [] def get_tags(self, available_tags: List[str], allow_custom_tags) -> List[str]: self.provided_options = available_tags return user_choice class TieCoreTestInteractiveUntag(TieCoreAdapter): def __init__(self): self.untagged_file = "" self.removed_tags = "" def list(self, files: List[str]) -> List[str]: return present_tags def untag(self, file: str, tags: List[str]): self.untagged_file = file self.removed_tags = tags frontend = FrontendAnon() core = TieCoreTestInteractiveUntag() tie_main.run(core, RunOptions(["untag", "-f", "testfile1"]), frontend) self.assertEqual(sorted(present_tags), frontend.provided_options, "wrong options were provided") self.assertEqual(user_choice, core.removed_tags, "wrong tags were removed")
def test_index(self): core = TieCoreTestImpl(Action.index, [], ["testfile1", "testfile2"]) tie_main.run(core, RunOptions(["index", "-f", "testfile1", "testfile2"]), self.frontend) self.assertTrue(core.was_called_correctly(), "core was called incorrectly")
def _setup_tag_invalid_meta_data_file(confirm_nuke): exif = ExifEditor(Configuration()) index = Index(TEST_INDEX_LOCATION, exif) core = TieCoreImpl(exif, index) cli.run_cmd(["cp", READ_FILE, WRITE_FILE]) frontend = FrontendTest(confirm_nuke, []) tie_main.run(core, RunOptions(["tag", "foo", WRITE_FILE]), frontend)
def test_untag_frontend_cli_files_long(self): opts = RunOptions(["untag", "tag 1", "tag 2", "--files", "foo", "bar"]) self.assertEqual(Action.untag, opts.action) self.assertEqual(["tag 1", "tag 2"], opts.tags) self.assertEqual(False, opts.needs_tags(), "needs tags") self.assertEqual(["foo", "bar"], opts.files, "needs files") self.assertEqual(FrontendType.cli, opts.frontend)
def test_query(self): opts = RunOptions(["query", "tag 1", "tag 2"]) self.assertEqual(Action.query, opts.action) self.assertEqual(["tag 1", "tag 2"], opts.tags) self.assertEqual(False, opts.needs_tags(), "needs tags") self.assertEqual(FrontendType.cli, opts.frontend) self.assertEqual(MatchType.all, opts.match_type)
def test_tag_white_space(self): # Duplicates in constructor calls account for repeated calls to method core = TieCoreTestImpl(Action.tag, ["foo"], [WHITE_SPACE_FILE_MD, WHITE_SPACE_FILE_MD]) tie_main.run(core, RunOptions(["tag", "foo", "-f", WHITE_SPACE_FILE_MD]), self.frontend) self.assertTrue(core.was_called_correctly(), "core was called incorrectly")
def test_untag(self): # Duplicates in constructor calls account for repeated calls to method core = TieCoreTestImpl( Action.untag, ["foo", "bar", "foo", "bar"], ["testfile1", "testfile1", "testfile2", "testfile2"]) tie_main.run( core, RunOptions(["untag", "foo", "bar", "-f", "testfile1", "testfile2"]), self.frontend) self.assertTrue(core.was_called_correctly(), "core was called incorrectly")
def test_untag_interactive_multiple_files(self): user_choice = ["foo", "bas"] file_1 = "file1" file_2 = "file2" class FrontendAnon(FrontendAdapter): def __init__(self): super().__init__() self.provided_options = [] def get_tags(self, available_tags: List[str], allow_custom_tags) -> List[str]: self.provided_options = available_tags return user_choice class TieCoreTestInteractiveUntag(TieCoreAdapter): def __init__(self): super().__init__() self.untagged_files = list() self.removed_tags = list() def list(self, files: List[str]) -> List[str]: return ["foo", "bar", "bas", "bam"] def untag(self, file: str, tags: List[str]): self.untagged_files.append(file) for t in tags: self.removed_tags.append(t) frontend = FrontendAnon() core = TieCoreTestInteractiveUntag() tie_main.run(core, RunOptions(["untag", "-f", file_1, file_2]), frontend) self.assertEqual(sorted(["foo", "bar", "bas", "bam"]), frontend.provided_options, "wrong options were provided") self.assertEqual([file_1, file_2], core.untagged_files, "wrong files untagged") self.assertEqual(["foo", "bas", "foo", "bas"], core.removed_tags, "wrong tags were removed")
def main(*args): try: setup_sys_path() configuration = config.load_user_config() run_options = RunOptions(list(args[1:])) frontend_type = run_options.frontend front_end = ff.from_type(frontend_type) index_root_dir = configuration.index_path exif = ExifEditor(configuration) index = Index(index_root_dir, exif) core = TieCoreImpl(exif, index) if run_options.action == Action.help: print_usage() else: tie_main.run(core, run_options, front_end) except ParseError as parse_error: printerr("Error: " + parse_error.msg) sys.exit(EXIT_CODE_PARSE_ERROR) except InvalidMetaDataError as meta_data_error: printerr("Error: " + meta_data_error.msg) sys.exit(EXIT_CODE_INVALID_META_DATA) except KeyboardInterrupt: printerr("Application aborted by user") sys.exit(EXIT_CODE_INVALID_META_DATA) except FileNotFoundError: # No need to print it. this is already done by subprocess sys.exit(EXIT_CODE_FILE_NOT_FOUND) except CalledProcessError: # No need to print it. this is already done by subprocess sys.exit(EXIT_CODE_UNKNOWN_SUBPROCESS_ERROR)
def test_index_short_no_files_option(self): opts = RunOptions(["i", "foo"]) self.assertEqual(Action.index, opts.action) self.assertEqual(["foo"], opts.files)
def test_query_no_tags_frontend_batch(self): opts = RunOptions(["query", "-F", "batch"]) self.assertEqual(FrontendType.batch, opts.frontend) self.assertEqual(MatchType.all, opts.match_type)
def test_query_no_tags(self): opts = RunOptions(["query"]) self.assertEqual(Action.query, opts.action) self.assertEqual(True, opts.needs_tags(), "needs tags") self.assertEqual(FrontendType.cli, opts.frontend) self.assertEqual(MatchType.all, opts.match_type)
def test_list_no_files_option(self): opts = RunOptions(["l", "foo"]) self.assertEqual(Action.list, opts.action) self.assertEqual(["foo"], opts.files)
def test_list_files_two_args(self): opts = RunOptions(["list", "foo", "bar"]) self.assertEqual(Action.list, opts.action) self.assertEqual(False, opts.needs_tags(), "needs tags") self.assertEqual(["foo", "bar"], opts.files, "needs files") self.assertEqual(FrontendType.cli, opts.frontend)
def test_list_no_files(self): self.assertRaises(ParseError, lambda: RunOptions(["list"]))
def test_query_match_type_arg_missing(self): self.assertRaises( ParseError, lambda: RunOptions(["query", "tag 1", "tag 2", "--match-type"]))
def test_query_with_files_arg(self): self.assertRaises( ParseError, lambda: RunOptions([ "query", "tag 1", "tag 2", "-m", "any", "--files", "foo.jpg" ]))
def test_index(self): opts = RunOptions(["index", "--files", "foo", "bar"]) self.assertEqual(Action.index, opts.action) self.assertEqual(False, opts.needs_tags(), "needs tags") self.assertEqual(["foo", "bar"], opts.files, "needs files") self.assertEqual(FrontendType.cli, opts.frontend)
def test_query_match_any_long(self): opts = RunOptions(["query", "tag 1", "tag 2", "--match-type", "any"]) self.assertEqual(MatchType.any, opts.match_type)
def test_index_no_files(self): self.assertRaises(ParseError, lambda: RunOptions(["index"]))
def test_query_frontend_arg_missing(self): self.assertRaises( ParseError, lambda: RunOptions(["query", "tag 1", "tag 2", "--frontend"]))
def test_invalid_action(self): self.assertRaises(ParseError, lambda: RunOptions(["blubb"]))
def test_list_files_arg_missing(self): self.assertRaises(ParseError, lambda: RunOptions(["list", "--files"]))
def test_invalid_action_more_args(self): self.assertRaises(ParseError, lambda: RunOptions(["blubb", "bbla"]))
def test_list_frontend_gtk_files_long(self): opts = RunOptions(["list", "--frontend", "gtk", "--files", "foo"]) self.assertEqual(Action.list, opts.action) self.assertEqual(False, opts.needs_tags(), "needs tags") self.assertEqual(["foo"], opts.files, "needs files") self.assertEqual(FrontendType.gtk, opts.frontend)
def test_invalid_option(self): self.assertRaises(ParseError, lambda: RunOptions(["index", "--brr", "bar"]))
def test_list_short(self): opts = RunOptions(["l", "--files", "foo"]) self.assertEqual(Action.list, opts.action) self.assertEqual(["foo"], opts.files)
def test_invalid_frontend(self): self.assertRaises( ParseError, lambda: RunOptions(["tag", "foo", "-F", "gt", "bar"]))
def test_list_frontend_gtk_files_short(self): opts = RunOptions(["list", "-F", "gtk", "-f", "bar"]) self.assertEqual(Action.list, opts.action) self.assertEqual(False, opts.needs_tags(), "needs tags") self.assertEqual(["bar"], opts.files, "needs files") self.assertEqual(FrontendType.gtk, opts.frontend)
def test_no_action(self): self.assertRaises(ParseError, lambda: RunOptions(["--files", "foo"]))