From e42f59046bc0966a830fe6d38caf5b627ca291b1 Mon Sep 17 00:00:00 2001 From: Vladimir Chebotarev Date: Sun, 28 Aug 2022 09:11:41 +0300 Subject: [PATCH] Added test for excluding from subdirectories. cpburnz/python-path-specification#39 --- tests/test_match.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_match.py b/tests/test_match.py index d8555e1..78e8769 100644 --- a/tests/test_match.py +++ b/tests/test_match.py @@ -215,6 +215,17 @@ def test_exclude_directories(self): self.assertFalse(matches("/home/michael/file.yaml", is_dir=True)) self.assertFalse(matches("/home/michael/dir.yaml/file.sql", is_dir=False)) + def test_exclude_from_subdirectory(self): + matches = self.__parse_gitignore_string(["*.log", "!important/*.log", "trace.*"], fake_base_dir="/home/michael") + for is_dir in (False, True): + with self.subTest(i=is_dir): + self.assertTrue(matches("/home/michael/a.log", is_dir=is_dir)) + self.assertFalse(matches("/home/michael/b.txt", is_dir=is_dir)) + self.assertFalse(matches("/home/michael/important", is_dir=is_dir)) + self.assertFalse(matches("/home/michael/important/d.log", is_dir=is_dir)) + self.assertFalse(matches("/home/michael/important/e.txt", is_dir=is_dir)) + self.assertTrue(matches("/home/michael/trace.c", is_dir=is_dir)) + def test_ignore_all_subdirectories(self): matches = self.__parse_gitignore_string(["**/"], fake_base_dir="/home/michael") for is_dir in (False, True):