new API
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 2s
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 2s
This commit is contained in:
@@ -9,25 +9,20 @@ from kpmatch import PatternParsingError
|
||||
|
||||
class ParseTests(TestCase):
|
||||
def test_compile(self):
|
||||
pattern = kpmatch.compile("*.txt")
|
||||
(pattern,) = kpmatch.compile("*.txt")
|
||||
self.assertIsInstance(pattern, kpmatch.Pattern)
|
||||
self.assertTrue(pattern.match("file.txt"))
|
||||
self.assertEqual(pattern.specificity, 12)
|
||||
|
||||
patterns = kpmatch.compile("*.{png,jpg,jpeg,webp}")
|
||||
self.assertEqual(4, len(patterns))
|
||||
self.assertTrue(any([pattern.match("file.jpeg") for pattern in patterns]))
|
||||
self.assertTrue(any([pattern.match("file.png") for pattern in patterns]))
|
||||
self.assertFalse(any([pattern.match("file.txt") for pattern in patterns]))
|
||||
|
||||
def test_kpmatch(self):
|
||||
self.assertTrue(kpmatch.kpmatch("file.txt", "*.txt"))
|
||||
self.assertFalse(kpmatch.kpmatch("file.jpg", "*.txt"))
|
||||
|
||||
def test_is_valid_pattern(self):
|
||||
self.assertTrue(kpmatch.is_valid_pattern("*.txt"))
|
||||
self.assertFalse(kpmatch.is_valid_pattern("[.txt"))
|
||||
|
||||
def test_specificity(self):
|
||||
self.assertEqual(kpmatch.specificity(""), 0)
|
||||
self.assertEqual(kpmatch.specificity("**"), 1)
|
||||
self.assertEqual(kpmatch.specificity("*.txt"), 12)
|
||||
self.assertEqual(kpmatch.specificity("file.txt"), 15)
|
||||
|
||||
def assertRaisesPPE(self, error_message: str, position: int, pattern: str):
|
||||
with self.assertRaises(PatternParsingError) as cm:
|
||||
kpmatch.compile(pattern)
|
||||
@@ -49,12 +44,5 @@ class ParseTests(TestCase):
|
||||
|
||||
self.assertRaisesPPE('Missing closing bracket "}" to match "{"', 3, "abc{def")
|
||||
self.assertRaisesPPE(
|
||||
'Character "{" is not allowed inside a one-of pattern', 6, "abc{de{f}"
|
||||
'Character "{" is not allowed inside a braced section', 6, "abc{de{f}"
|
||||
)
|
||||
self.assertRaisesPPE(
|
||||
'A star "*" wildcard is not allowed inside a one-of pattern',
|
||||
8,
|
||||
"abc{def,*}",
|
||||
)
|
||||
self.assertRaisesPPE("Empty choice in a one-of pattern", 8, "abc{def,}")
|
||||
self.assertRaisesPPE("Empty choice in a one-of pattern", 4, "abc{,def}")
|
||||
|
||||
Reference in New Issue
Block a user