Esempio n. 1
0
    def test_Windows_piority_of_cv_files_as_files_and_lnk_files(self):

        if platform.system() != 'Windows':
            # This test only makes sense on Windows where .filetags can exist in same dir as .filetags.lnk
            return

        # Note: cwd = subdir3
        # Let's create all missing files in all dirs:
        filetags.create_link(self.subdir2_file, self.subdir1_file)  # create link
        filetags.create_link(self.subdir2b_file, self.tempdir_file)  # create link

        # prio 1 = .filetag file in startfile directory
        self.assertEqual(filetags.locate_and_parse_controlled_vocabulary(self.subdir1_test_file),
                         [self.subdir1_cv])

        # prio 2 = .filetag.lnk file in startfile directory
        os.remove(self.subdir1_file)  # removing the .filetags from the subdir1
        self.assertEqual(filetags.locate_and_parse_controlled_vocabulary(self.subdir1_test_file),
                         [self.subdir2_cv])

        # prio 3 = .filetag file in tempdir
        os.remove(self.subdir1_file + '.lnk')  # removing the .filetags link file from the subdir1
        self.assertEqual(filetags.locate_and_parse_controlled_vocabulary(self.subdir1_test_file),
                         [self.tempdir_cv])

        # prio 4 = .filetag.lnk file in tempdir
        os.remove(self.tempdir_file)  # removing the .filetags link file from the subdir1
        self.assertEqual(filetags.locate_and_parse_controlled_vocabulary(self.subdir1_test_file),
                         [self.subdir2b_cv])
Esempio n. 2
0
    def test_Windows_piority_of_cv_files_as_files_and_lnk_files(self):

        if platform.system() != 'Windows':
            # This test only makes sense on Windows where .filetags can exist in same dir as .filetags.lnk
            return

        # Note: cwd = subdir3
        # Let's create all missing files in all dirs:
        filetags.create_link(self.subdir2_file, self.subdir1_file)  # create link
        filetags.create_link(self.subdir2b_file, self.tempdir_file)  # create link

        # prio 1 = .filetag file in startfile directory
        self.assertEqual(filetags.locate_and_parse_controlled_vocabulary(self.subdir1_test_file),
                         [self.subdir1_cv])

        # prio 2 = .filetag.lnk file in startfile directory
        os.remove(self.subdir1_file)  # removing the .filetags from the subdir1
        self.assertEqual(filetags.locate_and_parse_controlled_vocabulary(self.subdir1_test_file),
                         [self.subdir2_cv])

        # prio 3 = .filetag file in tempdir
        os.remove(self.subdir1_file + '.lnk')  # removing the .filetags link file from the subdir1
        self.assertEqual(filetags.locate_and_parse_controlled_vocabulary(self.subdir1_test_file),
                         [self.tempdir_cv])

        # prio 4 = .filetag.lnk file in tempdir
        os.remove(self.tempdir_file)  # removing the .filetags link file from the subdir1
        self.assertEqual(filetags.locate_and_parse_controlled_vocabulary(self.subdir1_test_file),
                         [self.subdir2b_cv])
Esempio n. 3
0
    def test_comment_line_in_cv(self):
        """
        This tests does not use the setup from the test class. However, it does use several
        other util functions defined in this class. Therefore, I set up a different test
        case here and re-use the util functions.

        Test CV file looks like:

        foo
        # comment
        bar
        ## another comment
        baz
        #
        tag #inline-comment

        This should result in following CV: ["foo", "bar", "baz", "tag"] and not more.

        """

        tempdir = tempfile.mkdtemp(prefix='TestControlledVocabulary_Comments_line_')
        print("\ntempdir: " + tempdir + '  <<<' + '#' * 10)
        assert(os.path.isdir(tempdir))

        # create Controlled vocabulary files:
        cv_file = os.path.join(tempdir, '.filetags')
        self.create_file(cv_file, "foo\n# comment\nbar\n## another comment\nbaz\n#\ntag #inline-comment\n\n")
        assert(os.path.isfile(cv_file))

        # setup complete

        cv = filetags.locate_and_parse_controlled_vocabulary(cv_file)
        self.assertEqual(set(cv), set(["foo", "bar", "baz", "tag"]))
Esempio n. 4
0
    def test_find_cv_as_file_in_tempdir_when_startfile_dir_has_nothing(self):

        # Note: cwd = subdir3

        os.remove(self.subdir1_file)  # removing the .filetags from the subdir1
        self.assertEqual(filetags.locate_and_parse_controlled_vocabulary(self.subdir1_test_file),
                         [self.tempdir_cv])
Esempio n. 5
0
    def test_find_cv_in_startfile_dir_instead_of_cwd(self):

        # Note: cwd = subdir3

        self.assertEqual(
            filetags.locate_and_parse_controlled_vocabulary(
                self.subdir1_test_file), [self.subdir1_cv])
Esempio n. 6
0
    def test_comment_line_in_cv(self):
        """
        This tests does not use the setup from the test class. However, it does use several
        other util functions defined in this class. Therefore, I set up a different test
        case here and re-use the util functions.

        Test CV file looks like:

        foo
        # comment
        bar
        ## another comment
        baz
        #
        tag #inline-comment

        This should result in following CV: ["foo", "bar", "baz", "tag"] and not more.

        """

        tempdir = tempfile.mkdtemp(prefix='TestControlledVocabulary_Comments_line_')
        print("\ntempdir: " + tempdir + '  <<<' + '#' * 10)
        assert(os.path.isdir(tempdir))

        # create Controlled vocabulary files:
        cv_file = os.path.join(tempdir, '.filetags')
        self.create_file(cv_file, "foo\n# comment\nbar\n## another comment\nbaz\n#\ntag #inline-comment\n\n")
        assert(os.path.isfile(cv_file))

        # setup complete

        cv = filetags.locate_and_parse_controlled_vocabulary(cv_file)
        self.assertEqual(set(cv), set(["foo", "bar", "baz", "tag"]))
Esempio n. 7
0
    def test_find_cv_as_file_in_tempdir_when_startfile_dir_has_nothing(self):

        # Note: cwd = subdir3

        os.remove(self.subdir1_file)  # removing the .filetags from the subdir1
        self.assertEqual(filetags.locate_and_parse_controlled_vocabulary(self.subdir1_test_file),
                         [self.tempdir_cv])
Esempio n. 8
0
    def test_find_cv_as_link_in_startfile_dir_when_there_is_no_cv_as_file(self):

        # Note: cwd = subdir3

        os.remove(self.subdir1_file)  # removing the .filetags from the subdir1
        filetags.create_link(self.subdir2_file, self.subdir1_file)  # create link

        self.assertEqual(filetags.locate_and_parse_controlled_vocabulary(self.subdir1_test_file),
                         [self.subdir2_cv])
Esempio n. 9
0
    def test_find_cv_as_link_in_startfile_dir_when_there_is_no_cv_as_file(self):

        # Note: cwd = subdir3

        os.remove(self.subdir1_file)  # removing the .filetags from the subdir1
        filetags.create_link(self.subdir2_file, self.subdir1_file)  # create link

        self.assertEqual(filetags.locate_and_parse_controlled_vocabulary(self.subdir1_test_file),
                         [self.subdir2_cv])
Esempio n. 10
0
    def test_find_cv_in_cwd_as_first_fallback_when_no_startfile_is_given(self):

        # Note: cwd = subdir3

        os.remove(self.subdir1_file)  # removing the .filetags from the subdir1
        os.remove(self.tempdir_file)  # removing the .filetags from the tempdir
        filetags.create_link(self.subdir2_file, os.path.join(self.subdir3, '.filetags'))  # create link

        self.assertEqual(filetags.locate_and_parse_controlled_vocabulary(False),
                         [self.subdir2_cv])
Esempio n. 11
0
    def test_find_cv_in_cwd_as_first_fallback_when_no_startfile_is_given(self):

        # Note: cwd = subdir3

        os.remove(self.subdir1_file)  # removing the .filetags from the subdir1
        os.remove(self.tempdir_file)  # removing the .filetags from the tempdir
        filetags.create_link(self.subdir2_file, os.path.join(self.subdir3, '.filetags'))  # create link

        self.assertEqual(filetags.locate_and_parse_controlled_vocabulary(False),
                         [self.subdir2_cv])
Esempio n. 12
0
    def test_find_cv_in_startfile_dir_instead_of_cwd(self):

        # Note: cwd = subdir3

        self.assertEqual(filetags.locate_and_parse_controlled_vocabulary(self.subdir1_test_file),
                         [self.subdir1_cv])