From 14fc3d258881e3c34e3c83dc90cbfe35cfb229d5 Mon Sep 17 00:00:00 2001 From: cpburnz <2126043+cpburnz@users.noreply.github.com> Date: Sat, 30 Sep 2023 11:49:48 -0400 Subject: [PATCH] Testing for issue 81 --- DEV.md | 4 +++ tests/test_02_gitwildmatch.py | 55 +++++++++++++++++++++++------------ tests/test_04_gitignore.py | 54 ++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 19 deletions(-) diff --git a/DEV.md b/DEV.md index fb646b4..ee4d876 100644 --- a/DEV.md +++ b/DEV.md @@ -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/) diff --git a/tests/test_02_gitwildmatch.py b/tests/test_02_gitwildmatch.py index da176bd..b933082 100644 --- a/tests/test_02_gitwildmatch.py +++ b/tests/test_02_gitwildmatch.py @@ -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', @@ -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', @@ -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', @@ -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, [ @@ -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, [ @@ -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) diff --git a/tests/test_04_gitignore.py b/tests/test_04_gitignore.py index abb5b6a..9478800 100644 --- a/tests/test_04_gitignore.py +++ b/tests/test_04_gitignore.py @@ -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())