예제 #1
0
    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")
예제 #2
0
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)
예제 #3
0
 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")
예제 #4
0
 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")
예제 #5
0
 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")
예제 #6
0
    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")
예제 #7
0
파일: tie.py 프로젝트: enguerrand/tie
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)
예제 #8
0
 def test_untag_file_without_tags(self):
     core = TieCoreAdapter()
     self.assertRaises(
         ParseError, lambda: tie_main.run(
             core, RunOptions(["untag", "-f", READ_FILE_MD_NO_TAGS]), self.
             frontend))
예제 #9
0
 def test_list(self):
     core = TieCoreTestImpl(Action.list, [], ["testfile"])
     tie_main.run(core, RunOptions(["list", "-f", "testfile"]),
                  self.frontend)
     self.assertTrue(core.was_called_correctly(),
                     "core was called incorrectly")
예제 #10
0
 def test_query_no_tags(self):
     core = TieCoreTestImpl(Action.query, [], [])
     self.assertRaises(
         ParseError, lambda: tie_main.run(core, RunOptions(["query"]),
                                          FrontendTest(UserReply.yes, [])))
예제 #11
0
 def test_query_interactive_tags(self):
     core = TieCoreTestImpl(Action.query, ["foo", "bar"], [])
     tie_main.run(core, RunOptions(["query"]), self.frontend)
     self.assertTrue(core.was_called_correctly(),
                     "core was called incorrectly")