当前位置: 首页>>代码示例>>Python>>正文


Python gitwildmatch.GitWildMatchPattern类代码示例

本文整理汇总了Python中pathspec.patterns.gitwildmatch.GitWildMatchPattern的典型用法代码示例。如果您正苦于以下问题:Python GitWildMatchPattern类的具体用法?Python GitWildMatchPattern怎么用?Python GitWildMatchPattern使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了GitWildMatchPattern类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_04_postfix_wildcard

	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',
		})
开发者ID:cpburnz,项目名称:python-path-specification,代码行数:31,代码来源:test_gitwildmatch.py

示例2: test_01_relative

	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',
		})
开发者ID:cpburnz,项目名称:python-path-specification,代码行数:31,代码来源:test_gitwildmatch.py

示例3: test_05_directory

	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',
		})
开发者ID:cpburnz,项目名称:python-path-specification,代码行数:30,代码来源:test_gitwildmatch.py

示例4: test_04_infix_wildcard

	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',
		})
开发者ID:cpburnz,项目名称:python-path-specification,代码行数:31,代码来源:test_gitwildmatch.py

示例5: test_01_absolute

	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',
		})
开发者ID:cpburnz,项目名称:python-path-specification,代码行数:27,代码来源:test_gitwildmatch.py

示例6: test_03_inner_double_asterisk

	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',
		})
开发者ID:cpburnz,项目名称:python-path-specification,代码行数:30,代码来源:test_gitwildmatch.py

示例7: test_04_prefix_wildcard

	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',
		})
开发者ID:cpburnz,项目名称:python-path-specification,代码行数:28,代码来源:test_gitwildmatch.py

示例8: test_07_match_bytes_and_unicode

	def test_07_match_bytes_and_unicode(self):
		"""
		Test byte string patterns matching byte string paths.
		"""
		pattern = GitWildMatchPattern(b'*.py')
		results = set(pattern.match(['a.py']))
		self.assertEqual(results, {'a.py'})
开发者ID:cpburnz,项目名称:python-path-specification,代码行数:7,代码来源:test_gitwildmatch.py

示例9: test_01_relative_nested

	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',
		})
开发者ID:cpburnz,项目名称:python-path-specification,代码行数:27,代码来源:test_gitwildmatch.py

示例10: test_07_match_unicode_and_unicode

	def test_07_match_unicode_and_unicode(self):
		"""
		Test unicode patterns with unicode paths.
		"""
		pattern = GitWildMatchPattern('*.py')
		results = set(pattern.match(['a.py']))
		self.assertEqual(results, {'a.py'})
开发者ID:cpburnz,项目名称:python-path-specification,代码行数:7,代码来源:test_gitwildmatch.py

示例11: test_07_match_bytes_and_unicode_fail

	def test_07_match_bytes_and_unicode_fail(self):
		"""
		Test byte string patterns matching byte string paths.
		"""
		pattern = GitWildMatchPattern(b'*.py')
		with self.assertRaises(TypeError):
			for _ in pattern.match(['a.py']):
				pass
开发者ID:cpburnz,项目名称:python-path-specification,代码行数:8,代码来源:test_gitwildmatch.py

示例12: test_07_match_unicode_and_bytes_fail

	def test_07_match_unicode_and_bytes_fail(self):
		"""
		Test unicode patterns with byte paths.
		"""
		pattern = GitWildMatchPattern('*.py')
		with self.assertRaises(TypeError):
			for _ in pattern.match([b'a.py']):
				pass
开发者ID:cpburnz,项目名称:python-path-specification,代码行数:8,代码来源:test_gitwildmatch.py

示例13: test_07_match_bytes_and_bytes_complete

	def test_07_match_bytes_and_bytes_complete(self):
		"""
		Test byte string patterns matching byte string paths.
		"""
		encoded = bytes(bytearray(range(0,256)))
		escaped = b"".join(b"\\" + encoded[i:i+1] for i in range(len(encoded)))
		pattern = GitWildMatchPattern(escaped)
		results = set(pattern.match([encoded]))
		self.assertEqual(results, {encoded})
开发者ID:cpburnz,项目名称:python-path-specification,代码行数:9,代码来源:test_gitwildmatch.py

示例14: test_02_comment

	def test_02_comment(self):
		"""
		Tests a comment pattern.
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('# Cork soakers.')
		self.assertIsNone(include)
		self.assertIsNone(regex)
开发者ID:cpburnz,项目名称:python-path-specification,代码行数:7,代码来源:test_gitwildmatch.py

示例15: test_00_empty

	def test_00_empty(self):
		"""
		Tests an empty pattern.
		"""
		regex, include = GitWildMatchPattern.pattern_to_regex('')
		self.assertIsNone(include)
		self.assertIsNone(regex)
开发者ID:cpburnz,项目名称:python-path-specification,代码行数:7,代码来源:test_gitwildmatch.py


注:本文中的pathspec.patterns.gitwildmatch.GitWildMatchPattern类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。