Пример #1
0
    def test_03_duplicate_leading_double_asterisk_edge_case(self):
        """
		Regression test for duplicate leading **/ bug.
		"""
        regex, include = GitWildMatchPattern.pattern_to_regex('**')
        self.assertTrue(include)
        self.assertEqual(regex, '^.+$')

        equivalent_regex, include = GitWildMatchPattern.pattern_to_regex(
            '**/**')
        self.assertTrue(include)
        self.assertEqual(equivalent_regex, regex)

        equivalent_regex, include = GitWildMatchPattern.pattern_to_regex(
            '**/**/**')
        self.assertTrue(include)
        self.assertEqual(equivalent_regex, regex)

        regex, include = GitWildMatchPattern.pattern_to_regex('**/api')
        self.assertTrue(include)
        self.assertEqual(regex, '^(?:.+/)?api(?:/.*)?$')

        equivalent_regex, include = GitWildMatchPattern.pattern_to_regex(
            '**/**/api')
        self.assertTrue(include)
        self.assertEqual(equivalent_regex, regex)
Пример #2
0
	def test_03_double_asterisk_trailing_slash_edge_case(self):
		"""
		Tests the edge-case **/ pattern.

		This should match everything except individual files in the root directory.
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('**/')
		self.assertTrue(include)
		self.assertEqual(regex, '^.+/.*$')

		equivalent_regex, include = GitWildMatchPattern.pattern_to_regex('**/**/')
		self.assertTrue(include)
		self.assertEqual(equivalent_regex, regex)
Пример #3
0
	def test_01_absolute(self):
		"""
		Tests an absolute path pattern.

		This should match:

			an/absolute/file/path
			an/absolute/file/path/foo

		This should NOT match:

			foo/an/absolute/file/path
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('/an/absolute/file/path')
		self.assertTrue(include)
		self.assertEqual(regex, '^an/absolute/file/path(?:/.*)?$')

		pattern = GitWildMatchPattern(re.compile(regex), include)
		results = set(pattern.match([
			'an/absolute/file/path',
			'an/absolute/file/path/foo',
			'foo/an/absolute/file/path',
		]))
		self.assertEqual(results, set([
			'an/absolute/file/path',
			'an/absolute/file/path/foo',
		]))
Пример #4
0
	def test_04_prefix_wildcard(self):
		"""
		Tests a pattern with a prefix wildcard.

		This should match:

			bar.py
			bar.py/
			foo/bar.py
			foo/bar.py/baz
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('*.py')
		self.assertTrue(include)
		self.assertEqual(regex, '^(?:.+/)?[^/]*\\.py(?:/.*)?$')

		pattern = GitWildMatchPattern(re.compile(regex), include)
		results = set(pattern.match([
			'bar.py',
			'bar.py/',
			'foo/bar.py',
			'foo/bar.py/baz',
		]))
		self.assertEqual(results, set([
			'bar.py',
			'bar.py/',
			'foo/bar.py',
			'foo/bar.py/baz',
		]))
Пример #5
0
    def test_05_directory(self):
        """
		Tests a directory pattern.

		This should match:

			dir/
			foo/dir/
			foo/dir/bar

		This should **not** match:

			dir
		"""
        regex, include = GitWildMatchPattern.pattern_to_regex("dir/")
        self.assertTrue(include)
        self.assertEqual(regex, "^(?:.+/)?dir/.*$")

        pattern = GitWildMatchPattern(re.compile(regex), include)
        results = set(
            pattern.match([
                "dir/",
                "foo/dir/",
                "foo/dir/bar",
                "dir",
            ]))
        self.assertEqual(results, {
            "dir/",
            "foo/dir/",
            "foo/dir/bar",
        })
Пример #6
0
    def test_01_relative_nested(self):
        """
		Tests a relative nested path pattern.

		This should match:

			foo/spam
			foo/spam/bar

		This should **not** match (according to git check-ignore (v2.4.1)):

			bar/foo/spam
		"""
        regex, include = GitWildMatchPattern.pattern_to_regex("foo/spam")
        self.assertTrue(include)
        self.assertEqual(regex, "^foo/spam(?:/.*)?$")

        pattern = GitWildMatchPattern(re.compile(regex), include)
        results = set(
            pattern.match([
                "foo/spam",
                "foo/spam/bar",
                "bar/foo/spam",
            ]))
        self.assertEqual(results, {
            "foo/spam",
            "foo/spam/bar",
        })
	def test_04_infix_wildcard(self):
		"""
		Tests a pattern with an infix wildcard.

		This should match:

			foo--bar
			foo-hello-bar
			a/foo-hello-bar
			foo-hello-bar/b
			a/foo-hello-bar/b
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('foo-*-bar')
		self.assertTrue(include)
		self.assertEqual(regex, '^(?:.+/)?foo\\-[^/]*\\-bar(?:/.*)?$')

		pattern = GitWildMatchPattern(re.compile(regex), include)
		results = set(pattern.match([
			'foo--bar',
			'foo-hello-bar',
			'a/foo-hello-bar',
			'foo-hello-bar/b',
			'a/foo-hello-bar/b',
		]))
		self.assertEqual(results, {
			'foo--bar',
			'foo-hello-bar',
			'a/foo-hello-bar',
			'foo-hello-bar/b',
			'a/foo-hello-bar/b',
		})
Пример #8
0
    def test_03_only_double_asterisk(self):
        """
		Tests a double-asterisk pattern which matches everything.
		"""
        regex, include = GitWildMatchPattern.pattern_to_regex('**')
        self.assertTrue(include)
        self.assertEqual(regex, '^.+$')
Пример #9
0
    def test_03_inner_double_asterisk(self):
        """
		Tests a path with an inner double-asterisk directory.

		This should match:

			left/bar/right
			left/foo/bar/right
			left/bar/right/foo

		This should **not** match (according to git check-ignore (v2.4.1)):

			foo/left/bar/right
		"""
        regex, include = GitWildMatchPattern.pattern_to_regex("left/**/right")
        self.assertTrue(include)
        self.assertEqual(regex, "^left(?:/.+)?/right(?:/.*)?$")

        pattern = GitWildMatchPattern(re.compile(regex), include)
        results = set(
            pattern.match([
                "left/bar/right",
                "left/foo/bar/right",
                "left/bar/right/foo",
                "foo/left/bar/right",
            ]))
        self.assertEqual(results, {
            "left/bar/right",
            "left/foo/bar/right",
            "left/bar/right/foo",
        })
	def test_02_comment(self):
		"""
		Tests a comment pattern.
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('# Cork soakers.')
		self.assertIsNone(include)
		self.assertIsNone(regex)
Пример #11
0
    def test_00_empty(self):
        """
		Tests an empty pattern.
		"""
        regex, include = GitWildMatchPattern.pattern_to_regex('')
        self.assertIsNone(include)
        self.assertIsNone(regex)
	def test_03_only_double_asterisk(self):
		"""
		Tests a double-asterisk pattern which matches everything.
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('**')
		self.assertTrue(include)
		self.assertEqual(regex, '^.+$')
Пример #13
0
    def test_01_relative(self):
        """
		Tests a relative path pattern.

		This should match:

			spam
			spam/
			foo/spam
			spam/foo
			foo/spam/bar
		"""
        regex, include = GitWildMatchPattern.pattern_to_regex("spam")
        self.assertTrue(include)
        self.assertEqual(regex, "^(?:.+/)?spam(?:/.*)?$")

        pattern = GitWildMatchPattern(re.compile(regex), include)
        results = set(
            pattern.match([
                "spam",
                "spam/",
                "foo/spam",
                "spam/foo",
                "foo/spam/bar",
            ]))
        self.assertEqual(results, {
            "spam",
            "spam/",
            "foo/spam",
            "spam/foo",
            "foo/spam/bar",
        })
Пример #14
0
    def test_04_prefix_wildcard(self):
        """
		Tests a pattern with a prefix wildcard.

		This should match:

			bar.py
			bar.py/
			foo/bar.py
			foo/bar.py/baz
		"""
        regex, include = GitWildMatchPattern.pattern_to_regex("*.py")
        self.assertTrue(include)
        self.assertEqual(regex, "^(?:.+/)?[^/]*\\.py(?:/.*)?$")

        pattern = GitWildMatchPattern(re.compile(regex), include)
        results = set(
            pattern.match([
                "bar.py",
                "bar.py/",
                "foo/bar.py",
                "foo/bar.py/baz",
            ]))
        self.assertEqual(results, {
            "bar.py",
            "bar.py/",
            "foo/bar.py",
            "foo/bar.py/baz",
        })
Пример #15
0
    def test_03_double_asterisk_trailing_slash_edge_case(self):
        """
		Tests the edge-case **/ pattern.

		This should match everything except individual files in the root directory.
		"""
        regex, include = GitWildMatchPattern.pattern_to_regex('**/')
        self.assertTrue(include)
        # FIXME: currently failing
        # REVIEW: I believe this is the correct regex for this case
        # self.assertEqual(regex, '^(?:.+/).*$')

        equivalent_regex, include = GitWildMatchPattern.pattern_to_regex(
            '**/**/')
        self.assertTrue(include)
        self.assertEqual(equivalent_regex, regex)
Пример #16
0
    def test_04_postfix_wildcard(self):
        """
		Tests a pattern with a postfix wildcard.

		This should match:

			~temp-
			~temp-foo
			~temp-foo/bar
			foo/~temp-bar
			foo/~temp-bar/baz
		"""
        regex, include = GitWildMatchPattern.pattern_to_regex("~temp-*")
        self.assertTrue(include)
        self.assertEqual(regex, "^(?:.+/)?\\~temp\\-[^/]*(?:/.*)?$")

        pattern = GitWildMatchPattern(re.compile(regex), include)
        results = set(
            pattern.match([
                "~temp-",
                "~temp-foo",
                "~temp-foo/bar",
                "foo/~temp-bar",
                "foo/~temp-bar/baz",
            ]))
        self.assertEqual(
            results,
            {
                "~temp-",
                "~temp-foo",
                "~temp-foo/bar",
                "foo/~temp-bar",
                "foo/~temp-bar/baz",
            },
        )
Пример #17
0
    def test_01_absolute(self):
        """
		Tests an absolute path pattern.

		This should match:

			an/absolute/file/path
			an/absolute/file/path/foo

		This should NOT match:

			foo/an/absolute/file/path
		"""
        regex, include = GitWildMatchPattern.pattern_to_regex(
            "/an/absolute/file/path")
        self.assertTrue(include)
        self.assertEqual(regex, "^an/absolute/file/path(?:/.*)?$")

        pattern = GitWildMatchPattern(re.compile(regex), include)
        results = set(
            pattern.match([
                "an/absolute/file/path",
                "an/absolute/file/path/foo",
                "foo/an/absolute/file/path",
            ]))
        self.assertEqual(results, {
            "an/absolute/file/path",
            "an/absolute/file/path/foo",
        })
	def test_03_inner_double_asterisk(self):
		"""
		Tests a path with an inner double-asterisk directory.

		This should match:

			left/bar/right
			left/foo/bar/right
			left/bar/right/foo

		This should **not** match (according to git check-ignore (v2.4.1)):

			foo/left/bar/right
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('left/**/right')
		self.assertTrue(include)
		self.assertEqual(regex, '^left(?:/.+)?/right(?:/.*)?$')

		pattern = GitWildMatchPattern(re.compile(regex), include)
		results = set(pattern.match([
			'left/bar/right',
			'left/foo/bar/right',
			'left/bar/right/foo',
			'foo/left/bar/right',
		]))
		self.assertEqual(results, {
			'left/bar/right',
			'left/foo/bar/right',
			'left/bar/right/foo',
		})
	def test_00_empty(self):
		"""
		Tests an empty pattern.
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('')
		self.assertIsNone(include)
		self.assertIsNone(regex)
Пример #20
0
	def test_01_relative(self):
		"""
		Tests a relative path pattern.

		This should match:

			spam
			spam/
			foo/spam
			spam/foo
			foo/spam/bar
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('spam')
		self.assertTrue(include)
		self.assertEqual(regex, '^(?:.+/)?spam(?:/.*)?$')

		pattern = GitWildMatchPattern(re.compile(regex), include)
		results = set(pattern.match([
			'spam',
			'spam/',
			'foo/spam',
			'spam/foo',
			'foo/spam/bar',
		]))
		self.assertEqual(results, {
			'spam',
			'spam/',
			'foo/spam',
			'spam/foo',
			'foo/spam/bar',
		})
	def test_04_postfix_wildcard(self):
		"""
		Tests a pattern with a postfix wildcard.

		This should match:

			~temp-
			~temp-foo
			~temp-foo/bar
			foo/~temp-bar
			foo/~temp-bar/baz
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('~temp-*')
		self.assertTrue(include)
		self.assertEqual(regex, '^(?:.+/)?\\~temp\\-[^/]*(?:/.*)?$')

		pattern = GitWildMatchPattern(re.compile(regex), include)
		results = set(pattern.match([
			'~temp-',
			'~temp-foo',
			'~temp-foo/bar',
			'foo/~temp-bar',
			'foo/~temp-bar/baz',
		]))
		self.assertEqual(results, {
			'~temp-',
			'~temp-foo',
			'~temp-foo/bar',
			'foo/~temp-bar',
			'foo/~temp-bar/baz',
		})
Пример #22
0
	def test_04_postfix_wildcard(self):
		"""
		Tests a pattern with a postfix wildcard.

		This should match:

			~temp-
			~temp-foo
			~temp-foo/bar
			foo/~temp-bar
			foo/~temp-bar/baz
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('~temp-*')
		self.assertTrue(include)
		self.assertEqual(regex, '^(?:.+/)?\\~temp\\-[^/]*(?:/.*)?$')

		pattern = GitWildMatchPattern(re.compile(regex), include)
		results = set(pattern.match([
			'~temp-',
			'~temp-foo',
			'~temp-foo/bar',
			'foo/~temp-bar',
			'foo/~temp-bar/baz',
		]))
		self.assertEqual(results, {
			'~temp-',
			'~temp-foo',
			'~temp-foo/bar',
			'foo/~temp-bar',
			'foo/~temp-bar/baz',
		})
Пример #23
0
	def test_05_directory(self):
		"""
		Tests a directory pattern.

		This should match:

			dir/
			foo/dir/
			foo/dir/bar

		This should **not** match:

			dir
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('dir/')
		self.assertTrue(include)
		self.assertEqual(regex, '^(?:.+/)?dir/.*$')

		pattern = GitWildMatchPattern(re.compile(regex), include)
		results = set(pattern.match([
			'dir/',
			'foo/dir/',
			'foo/dir/bar',
			'dir',
		]))
		self.assertEqual(results, {
			'dir/',
			'foo/dir/',
			'foo/dir/bar',
		})
	def test_05_directory(self):
		"""
		Tests a directory pattern.

		This should match:

			dir/
			foo/dir/
			foo/dir/bar

		This should **not** match:

			dir
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('dir/')
		self.assertTrue(include)
		self.assertEqual(regex, '^(?:.+/)?dir/.*$')

		pattern = GitWildMatchPattern(re.compile(regex), include)
		results = set(pattern.match([
			'dir/',
			'foo/dir/',
			'foo/dir/bar',
			'dir',
		]))
		self.assertEqual(results, {
			'dir/',
			'foo/dir/',
			'foo/dir/bar',
		})
Пример #25
0
	def test_03_parent_double_asterisk(self):
		"""
		Tests a file name with a double-asterisk parent directory.

		This should match:

			spam
			foo/spam
			foo/spam/bar
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('**/spam')
		self.assertTrue(include)
		self.assertEqual(regex, '^(?:.+/)?spam(?:/.*)?$')

		pattern = GitWildMatchPattern(re.compile(regex), include)
		results = set(pattern.match([
			'spam',
			'foo/spam',
			'foo/spam/bar',
		]))
		self.assertEqual(results, {
			'spam',
			'foo/spam',
			'foo/spam/bar',
		})
Пример #26
0
	def test_02_comment(self):
		"""
		Tests a comment pattern.
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('# Cork soakers.')
		self.assertIsNone(include)
		self.assertIsNone(regex)
	def test_01_relative_nested(self):
		"""
		Tests a relative nested path pattern.

		This should match:

			foo/spam
			foo/spam/bar

		This should **not** match (according to git check-ignore (v2.4.1)):

			bar/foo/spam
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('foo/spam')
		self.assertTrue(include)
		self.assertEqual(regex, '^foo/spam(?:/.*)?$')

		pattern = GitWildMatchPattern(re.compile(regex), include)
		results = set(pattern.match([
			'foo/spam',
			'foo/spam/bar',
			'bar/foo/spam',
		]))
		self.assertEqual(results, {
			'foo/spam',
			'foo/spam/bar',
		})
	def test_04_prefix_wildcard(self):
		"""
		Tests a pattern with a prefix wildcard.

		This should match:

			bar.py
			bar.py/
			foo/bar.py
			foo/bar.py/baz
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('*.py')
		self.assertTrue(include)
		self.assertEqual(regex, '^(?:.+/)?[^/]*\\.py(?:/.*)?$')

		pattern = GitWildMatchPattern(re.compile(regex), include)
		results = set(pattern.match([
			'bar.py',
			'bar.py/',
			'foo/bar.py',
			'foo/bar.py/baz',
		]))
		self.assertEqual(results, {
			'bar.py',
			'bar.py/',
			'foo/bar.py',
			'foo/bar.py/baz',
		})
	def test_01_absolute(self):
		"""
		Tests an absolute path pattern.

		This should match:

			an/absolute/file/path
			an/absolute/file/path/foo

		This should NOT match:

			foo/an/absolute/file/path
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('/an/absolute/file/path')
		self.assertTrue(include)
		self.assertEqual(regex, '^an/absolute/file/path(?:/.*)?$')

		pattern = GitWildMatchPattern(re.compile(regex), include)
		results = set(pattern.match([
			'an/absolute/file/path',
			'an/absolute/file/path/foo',
			'foo/an/absolute/file/path',
		]))
		self.assertEqual(results, {
			'an/absolute/file/path',
			'an/absolute/file/path/foo',
		})
	def test_01_relative(self):
		"""
		Tests a relative path pattern.

		This should match:

			spam
			spam/
			foo/spam
			spam/foo
			foo/spam/bar
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('spam')
		self.assertTrue(include)
		self.assertEqual(regex, '^(?:.+/)?spam(?:/.*)?$')

		pattern = GitWildMatchPattern(re.compile(regex), include)
		results = set(pattern.match([
			'spam',
			'spam/',
			'foo/spam',
			'spam/foo',
			'foo/spam/bar',
		]))
		self.assertEqual(results, {
			'spam',
			'spam/',
			'foo/spam',
			'spam/foo',
			'foo/spam/bar',
		})
Пример #31
0
    def test_04_infix_wildcard(self):
        """
		Tests a pattern with an infix wildcard.

		This should match:

			foo--bar
			foo-hello-bar
			a/foo-hello-bar
			foo-hello-bar/b
			a/foo-hello-bar/b
		"""
        regex, include = GitWildMatchPattern.pattern_to_regex("foo-*-bar")
        self.assertTrue(include)
        self.assertEqual(regex, "^(?:.+/)?foo\\-[^/]*\\-bar(?:/.*)?$")

        pattern = GitWildMatchPattern(re.compile(regex), include)
        results = set(
            pattern.match([
                "foo--bar",
                "foo-hello-bar",
                "a/foo-hello-bar",
                "foo-hello-bar/b",
                "a/foo-hello-bar/b",
            ]))
        self.assertEqual(
            results,
            {
                "foo--bar",
                "foo-hello-bar",
                "a/foo-hello-bar",
                "foo-hello-bar/b",
                "a/foo-hello-bar/b",
            },
        )
	def test_01_absolute_root(self):
		"""
		Tests a single root absolute path pattern.

		This should NOT match any file (according to git check-ignore
		(v2.4.1)).
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('/')
		self.assertIsNone(include)
		self.assertIsNone(regex)
Пример #33
0
    def test_01_absolute_root(self):
        """
		Tests a single root absolute path pattern.

		This should NOT match any file (according to git check-ignore
		(v2.4.1)).
		"""
        regex, include = GitWildMatchPattern.pattern_to_regex('/')
        self.assertIsNone(include)
        self.assertIsNone(regex)
Пример #34
0
def get_exclude_list_from_gitignore() -> List[str]:
    """Converts .gitignore patterns to regex and return this exclude regex
    list."""
    path = Path(".gitignore")
    gitignore_regex: List[str] = []
    if path.is_file():
        for line in tokenize.open(path).readlines():
            regex = GitWildMatchPattern.pattern_to_regex(line)[0]
            if regex:
                gitignore_regex.append(regex)
    return gitignore_regex
Пример #35
0
	def test_02_ignore(self):
		"""
		Tests an exclude pattern.

		This should NOT match (according to git check-ignore (v2.4.1)):

			temp/foo
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('!temp')
		self.assertIsNotNone(include)
		self.assertFalse(include)
		self.assertEqual(regex, '^(?:.+/)?temp$')
Пример #36
0
    def test_02_ignore(self):
        """
		Tests an exclude pattern.

		This should NOT match (according to git check-ignore (v2.4.1)):

			temp/foo
		"""
        regex, include = GitWildMatchPattern.pattern_to_regex('!temp')
        self.assertIsNotNone(include)
        self.assertFalse(include)
        self.assertEqual(regex, '^(?:.+/)?temp$')
Пример #37
0
    def test_03_parent_double_asterisk(self):
        """
		Tests a file name with a double-asterisk parent directory.

		This should match:

			foo/spam
			foo/spam/bar
		"""
        regex, include = GitWildMatchPattern.pattern_to_regex('**/spam')
        self.assertTrue(include)
        self.assertEqual(regex, '^(?:.+/)?spam(?:/.*)?$')
Пример #38
0
	def test_03_parent_double_asterisk(self):
		"""
		Tests a file name with a double-asterisk parent directory.

		This should match:

			foo/spam
			foo/spam/bar
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('**/spam')
		self.assertTrue(include)
		self.assertEqual(regex, '^(?:.+/)?spam(?:/.*)?$')
Пример #39
0
	def test_04_prefix_wildcard(self):
		"""
		Tests a pattern with a prefix wildcard.

		This should match:

			bar.py
			bar.py/
			foo/bar.py
			foo/bar.py/baz
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('*.py')
		self.assertTrue(include)
		self.assertEqual(regex, '^(?:.+/)?[^/]*\\.py(?:/.*)?$')
Пример #40
0
    def test_04_prefix_wildcard(self):
        """
		Tests a pattern with a prefix wildcard.

		This should match:

			bar.py
			bar.py/
			foo/bar.py
			foo/bar.py/baz
		"""
        regex, include = GitWildMatchPattern.pattern_to_regex('*.py')
        self.assertTrue(include)
        self.assertEqual(regex, '^(?:.+/)?[^/]*\\.py(?:/.*)?$')
Пример #41
0
    def test_01_relative(self):
        """
		Tests a relative path pattern.

		This should match:

			spam
			spam/
			foo/spam
			spam/foo
			foo/spam/bar
		"""
        regex, include = GitWildMatchPattern.pattern_to_regex('spam')
        self.assertTrue(include)
        self.assertEqual(regex, '^(?:.+/)?spam(?:/.*)?$')
Пример #42
0
	def test_04_postfix_wildcard(self):
		"""
		Tests a pattern with a postfix wildcard.

		This should match:

			~temp-
			~temp-foo
			~temp-foo/bar
			foo/~temp-bar
			foo/~temp-bar/baz
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('~temp-*')
		self.assertTrue(include)
		self.assertEqual(regex, '^(?:.+/)?\\~temp\\-[^/]*(?:/.*)?$')
Пример #43
0
    def test_04_postfix_wildcard(self):
        """
		Tests a pattern with a postfix wildcard.

		This should match:

			~temp-
			~temp-foo
			~temp-foo/bar
			foo/~temp-bar
			foo/~temp-bar/baz
		"""
        regex, include = GitWildMatchPattern.pattern_to_regex('~temp-*')
        self.assertTrue(include)
        self.assertEqual(regex, '^(?:.+/)?\\~temp\\-[^/]*(?:/.*)?$')
Пример #44
0
    def test_04_infix_wildcard(self):
        """
		Tests a pattern with an infix wildcard.

		This should match:

			foo--bar
			foo-hello-bar
			a/foo-hello-bar
			foo-hello-bar/b
			a/foo-hello-bar/b
		"""
        regex, include = GitWildMatchPattern.pattern_to_regex('foo-*-bar')
        self.assertTrue(include)
        self.assertEqual(regex, '^(?:.+/)?foo\\-[^/]*\\-bar(?:/.*)?$')
Пример #45
0
	def test_01_relative(self):
		"""
		Tests a relative path pattern.

		This should match:

			spam
			spam/
			foo/spam
			spam/foo
			foo/spam/bar
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('spam')
		self.assertTrue(include)
		self.assertEqual(regex, '^(?:.+/)?spam(?:/.*)?$')
Пример #46
0
	def test_04_infix_wildcard(self):
		"""
		Tests a pattern with an infix wildcard.

		This should match:

			foo--bar
			foo-hello-bar
			a/foo-hello-bar
			foo-hello-bar/b
			a/foo-hello-bar/b
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('foo-*-bar')
		self.assertTrue(include)
		self.assertEqual(regex, '^(?:.+/)?foo\\-[^/]*\\-bar(?:/.*)?$')
Пример #47
0
    def test_01_relative_nested(self):
        """
		Tests a relative nested path pattern.

		This should match:

			foo/spam
			foo/spam/bar

		This should **not** match (according to git check-ignore (v2.4.1)):

			bar/foo/spam
		"""
        regex, include = GitWildMatchPattern.pattern_to_regex('foo/spam')
        self.assertTrue(include)
        self.assertEqual(regex, '^foo/spam(?:/.*)?$')
Пример #48
0
    def test_03_child_double_asterisk(self):
        """
		Tests a directory name with a double-asterisk child
		directory.

		This should match:

			spam/bar

		This should **not** match (according to git check-ignore (v2.4.1)):

			foo/spam/bar
		"""
        regex, include = GitWildMatchPattern.pattern_to_regex('spam/**')
        self.assertTrue(include)
        self.assertEqual(regex, '^spam/.*$')
Пример #49
0
	def test_01_absolute(self):
		"""
		Tests an absolute path pattern.

		This should match:

			an/absolute/file/path
			an/absolute/file/path/foo

		This should NOT match:

			foo/an/absolute/file/path
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('/an/absolute/file/path')
		self.assertTrue(include)
		self.assertEqual(regex, '^an/absolute/file/path(?:/.*)?$')
Пример #50
0
	def test_01_relative_nested(self):
		"""
		Tests a relative nested path pattern.

		This should match:

			foo/spam
			foo/spam/bar

		This should **not** match (according to git check-ignore (v2.4.1)):

			bar/foo/spam
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('foo/spam')
		self.assertTrue(include)
		self.assertEqual(regex, '^foo/spam(?:/.*)?$')
Пример #51
0
	def test_03_child_double_asterisk(self):
		"""
		Tests a directory name with a double-asterisk child
		directory.

		This should match:

			spam/bar

		This should **not** match (according to git check-ignore (v2.4.1)):

			foo/spam/bar
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('spam/**')
		self.assertTrue(include)
		self.assertEqual(regex, '^spam/.*$')
Пример #52
0
	def test_05_directory(self):
		"""
		Tests a directory pattern.

		This should match:

			dir/
			foo/dir/
			foo/dir/bar

		This should **not** match:

			dir
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('dir/')
		self.assertTrue(include)
		self.assertEqual(regex, '^(?:.+/)?dir/.*$')
	def test_03_parent_double_asterisk(self):
		"""
		Tests a file name with a double-asterisk parent directory.

		This should match:

			foo/spam
			foo/spam/bar
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('**/spam')
		self.assertTrue(include)
		self.assertEqual(regex, '^(?:.+/)?spam(?:/.*)?$')

		pattern = GitWildMatchPattern(re.compile(regex), include)
		results = set(pattern.match([
			'foo/spam',
			'foo/spam/bar',
		]))
		self.assertEqual(results, {
			'foo/spam',
			'foo/spam/bar',
		})