Skip to content

Commit

Permalink
Testing for issue 81
Browse files Browse the repository at this point in the history
  • Loading branch information
cpburnz committed Sep 30, 2023
1 parent 64ea07e commit 14fc3d2
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 19 deletions.
4 changes: 4 additions & 0 deletions DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ Review the following PyPI packages.
- v23.7.0 (latest as of 2023-09-06) requires Python 3.8+.
- [black on Wheelodex](https://www.wheelodex.org/projects/black/).

[dvc](https://github.com/iterative/dvc)

- v3.23.0 (latest as of 2023-09-30) requires Python 3.8+.
- [dvc on Wheelodex](https://www.wheelodex.org/projects/dvc/).

[hatchling](https://pypi.org/project/hatchling/)

Expand Down
55 changes: 36 additions & 19 deletions tests/test_02_gitwildmatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,10 +669,11 @@ def test_10_escape_pound_start(self):
]))
self.assertEqual(results, {"#sign"})

def test_11_match_directory_1(self):
def test_11_issue_19_directory_a(self):
"""
Test matching a directory.
Test a directory discrepancy, scenario A.
"""
# NOTE: The result from GitWildMatchPattern will differ from GitIgnoreSpec.
pattern = GitWildMatchPattern("dirG/")
results = set(filter(pattern.match_file, [
'fileA',
Expand All @@ -689,10 +690,11 @@ def test_11_match_directory_1(self):
'dirG/fileO',
})

def test_11_match_directory_2(self):
def test_11_issue_19_directory_b(self):
"""
Test matching a directory.
Test a directory discrepancy, scenario B.
"""
# NOTE: The result from GitWildMatchPattern will differ from GitIgnoreSpec.
pattern = GitWildMatchPattern("dirG/*")
results = set(filter(pattern.match_file, [
'fileA',
Expand All @@ -709,10 +711,11 @@ def test_11_match_directory_2(self):
'dirG/fileO',
})

def test_11_match_sub_directory_3(self):
def test_11_issue_19_directory_c(self):
"""
Test matching a directory.
Test a directory discrepancy, scenario C.
"""
# NOTE: The result from GitWildMatchPattern will differ from GitIgnoreSpec.
pattern = GitWildMatchPattern("dirG/**")
results = set(filter(pattern.match_file, [
'fileA',
Expand Down Expand Up @@ -774,21 +777,23 @@ def test_12_asterisk_4_descendant(self):
'anydir/file.txt',
})

def test_13_issue_77_regex(self):
def test_12_issue_62(self):
"""
Test the resulting regex for regex bracket expression negation.
Test including all files, scenario A.
"""
regex, include = GitWildMatchPattern.pattern_to_regex('a[^b]c')
self.assertTrue(include)

equiv_regex, include = GitWildMatchPattern.pattern_to_regex('a[!b]c')
self.assertTrue(include)

self.assertEqual(regex, equiv_regex)
pattern = GitWildMatchPattern('*')
results = set(filter(pattern.match_file, [
'file.txt',
'anydir/file.txt',
]))
self.assertEqual(results, {
'file.txt',
'anydir/file.txt',
})

def test_13_negate_with_caret(self):
def test_13_issue_77_1_negate_with_caret(self):
"""
Test negation using the caret symbol (^)
Test negation using the caret symbol ("^").
"""
pattern = GitWildMatchPattern("a[^gy]c")
results = set(filter(pattern.match_file, [
Expand All @@ -799,9 +804,9 @@ def test_13_negate_with_caret(self):
]))
self.assertEqual(results, {"abc", "adc"})

def test_13_negate_with_exclamation_mark(self):
def test_13_issue_77_1_negate_with_exclamation_mark(self):
"""
Test negation using the exclamation mark (!)
Test negation using the exclamation mark ("!").
"""
pattern = GitWildMatchPattern("a[!gy]c")
results = set(filter(pattern.match_file, [
Expand All @@ -811,3 +816,15 @@ def test_13_negate_with_exclamation_mark(self):
"adc",
]))
self.assertEqual(results, {"abc", "adc"})

def test_13_issue_77_2_regex(self):
"""
Test the resulting regex for regex bracket expression negation.
"""
regex, include = GitWildMatchPattern.pattern_to_regex('a[^b]c')
self.assertTrue(include)

equiv_regex, include = GitWildMatchPattern.pattern_to_regex('a[!b]c')
self.assertTrue(include)

self.assertEqual(regex, equiv_regex)
54 changes: 54 additions & 0 deletions tests/test_04_gitignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,57 @@ def test_07_issue_74(self):
'test2/a.txt',
'test2/c/c.txt',
})

def test_08_issue_81_a(self):
"""
Test issue 81.
"""
spec = GitIgnoreSpec.from_lines([
"*",
"!libfoo",
"!libfoo/**",
])
files = {
"./libfoo/__init__.py",
}
ignores = set(spec.match_files(files))
self.assertEqual(ignores, set())
self.assertEqual(files - ignores, {
"./libfoo/__init__.py",
})

def test_08_issue_81_b(self):
"""
Test issue 81.
"""
spec = GitIgnoreSpec.from_lines([
"*",
"!libfoo",
"!libfoo/*",
])
files = {
"./libfoo/__init__.py",
}
ignores = set(spec.match_files(files))
self.assertEqual(ignores, set())
self.assertEqual(files - ignores, {
"./libfoo/__init__.py",
})

def test_08_issue_81_c(self):
"""
Test issue 81.
"""
spec = GitIgnoreSpec.from_lines([
"*",
"!libfoo",
"!libfoo/",
])
files = {
"./libfoo/__init__.py",
}
ignores = set(spec.match_files(files))
self.assertEqual(ignores, {
"./libfoo/__init__.py",
})
self.assertEqual(files - ignores, set())

0 comments on commit 14fc3d2

Please sign in to comment.