當前位置: 首頁>>代碼示例>>Python>>正文


Python GitWildMatchPattern.pattern_to_regex方法代碼示例

本文整理匯總了Python中pathspec.patterns.gitwildmatch.GitWildMatchPattern.pattern_to_regex方法的典型用法代碼示例。如果您正苦於以下問題:Python GitWildMatchPattern.pattern_to_regex方法的具體用法?Python GitWildMatchPattern.pattern_to_regex怎麽用?Python GitWildMatchPattern.pattern_to_regex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pathspec.patterns.gitwildmatch.GitWildMatchPattern的用法示例。


在下文中一共展示了GitWildMatchPattern.pattern_to_regex方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_02_comment

# 需要導入模塊: from pathspec.patterns.gitwildmatch import GitWildMatchPattern [as 別名]
# 或者: from pathspec.patterns.gitwildmatch.GitWildMatchPattern import pattern_to_regex [as 別名]
	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,代碼行數:9,代碼來源:test_gitwildmatch.py

示例2: test_01_relative

# 需要導入模塊: from pathspec.patterns.gitwildmatch import GitWildMatchPattern [as 別名]
# 或者: from pathspec.patterns.gitwildmatch.GitWildMatchPattern import pattern_to_regex [as 別名]
	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,代碼行數:33,代碼來源:test_gitwildmatch.py

示例3: test_00_empty

# 需要導入模塊: from pathspec.patterns.gitwildmatch import GitWildMatchPattern [as 別名]
# 或者: from pathspec.patterns.gitwildmatch.GitWildMatchPattern import pattern_to_regex [as 別名]
	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,代碼行數:9,代碼來源:test_gitwildmatch.py

示例4: test_04_infix_wildcard

# 需要導入模塊: from pathspec.patterns.gitwildmatch import GitWildMatchPattern [as 別名]
# 或者: from pathspec.patterns.gitwildmatch.GitWildMatchPattern import pattern_to_regex [as 別名]
	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,代碼行數:33,代碼來源:test_gitwildmatch.py

示例5: test_03_only_double_asterisk

# 需要導入模塊: from pathspec.patterns.gitwildmatch import GitWildMatchPattern [as 別名]
# 或者: from pathspec.patterns.gitwildmatch.GitWildMatchPattern import pattern_to_regex [as 別名]
	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, '^.+$')
開發者ID:cpburnz,項目名稱:python-path-specification,代碼行數:9,代碼來源:test_gitwildmatch.py

示例6: test_04_prefix_wildcard

# 需要導入模塊: from pathspec.patterns.gitwildmatch import GitWildMatchPattern [as 別名]
# 或者: from pathspec.patterns.gitwildmatch.GitWildMatchPattern import pattern_to_regex [as 別名]
	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,代碼行數:30,代碼來源:test_gitwildmatch.py

示例7: test_05_directory

# 需要導入模塊: from pathspec.patterns.gitwildmatch import GitWildMatchPattern [as 別名]
# 或者: from pathspec.patterns.gitwildmatch.GitWildMatchPattern import pattern_to_regex [as 別名]
	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,代碼行數:32,代碼來源:test_gitwildmatch.py

示例8: test_01_relative_nested

# 需要導入模塊: from pathspec.patterns.gitwildmatch import GitWildMatchPattern [as 別名]
# 或者: from pathspec.patterns.gitwildmatch.GitWildMatchPattern import pattern_to_regex [as 別名]
	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,代碼行數:29,代碼來源:test_gitwildmatch.py

示例9: test_01_absolute

# 需要導入模塊: from pathspec.patterns.gitwildmatch import GitWildMatchPattern [as 別名]
# 或者: from pathspec.patterns.gitwildmatch.GitWildMatchPattern import pattern_to_regex [as 別名]
	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,代碼行數:29,代碼來源:test_gitwildmatch.py

示例10: test_04_postfix_wildcard

# 需要導入模塊: from pathspec.patterns.gitwildmatch import GitWildMatchPattern [as 別名]
# 或者: from pathspec.patterns.gitwildmatch.GitWildMatchPattern import pattern_to_regex [as 別名]
	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,代碼行數:33,代碼來源:test_gitwildmatch.py

示例11: test_03_inner_double_asterisk

# 需要導入模塊: from pathspec.patterns.gitwildmatch import GitWildMatchPattern [as 別名]
# 或者: from pathspec.patterns.gitwildmatch.GitWildMatchPattern import pattern_to_regex [as 別名]
	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,代碼行數:32,代碼來源:test_gitwildmatch.py

示例12: test_01_absolute_root

# 需要導入模塊: from pathspec.patterns.gitwildmatch import GitWildMatchPattern [as 別名]
# 或者: from pathspec.patterns.gitwildmatch.GitWildMatchPattern import pattern_to_regex [as 別名]
	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)
開發者ID:cpburnz,項目名稱:python-path-specification,代碼行數:12,代碼來源:test_gitwildmatch.py

示例13: test_03_parent_double_asterisk

# 需要導入模塊: from pathspec.patterns.gitwildmatch import GitWildMatchPattern [as 別名]
# 或者: from pathspec.patterns.gitwildmatch.GitWildMatchPattern import pattern_to_regex [as 別名]
	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(?:/.*)?$')
開發者ID:cyj0912,項目名稱:DependencyMan,代碼行數:14,代碼來源:test_gitwildmatch.py

示例14: test_02_ignore

# 需要導入模塊: from pathspec.patterns.gitwildmatch import GitWildMatchPattern [as 別名]
# 或者: from pathspec.patterns.gitwildmatch.GitWildMatchPattern import pattern_to_regex [as 別名]
	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$')
開發者ID:cyj0912,項目名稱:DependencyMan,代碼行數:14,代碼來源:test_gitwildmatch.py

示例15: test_04_prefix_wildcard

# 需要導入模塊: from pathspec.patterns.gitwildmatch import GitWildMatchPattern [as 別名]
# 或者: from pathspec.patterns.gitwildmatch.GitWildMatchPattern import pattern_to_regex [as 別名]
	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(?:/.*)?$')
開發者ID:cyj0912,項目名稱:DependencyMan,代碼行數:16,代碼來源:test_gitwildmatch.py


注:本文中的pathspec.patterns.gitwildmatch.GitWildMatchPattern.pattern_to_regex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。