forked from alexdredmon/arcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for removal of .gitignore on running tests
- Loading branch information
1 parent
e5e964b
commit 7bbf159
Showing
1 changed file
with
23 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,34 @@ | ||
import unittest | ||
from lib.gitignore_parser import parse_gitignore, is_ignored | ||
import os | ||
import tempfile | ||
|
||
class TestGitignoreParser(unittest.TestCase): | ||
|
||
class TestGitignoreParser(unittest.TestCase): | ||
def test_parse_gitignore(self): | ||
with open(".gitignore", "w") as f: | ||
f.write("__pycache__\nvenv") | ||
ignore_patterns = parse_gitignore(".gitignore", ["additional_pattern"]) | ||
self.assertIn("__pycache__", ignore_patterns) | ||
self.assertIn("venv", ignore_patterns) | ||
self.assertIn("additional_pattern", ignore_patterns) | ||
os.remove(".gitignore") | ||
with tempfile.NamedTemporaryFile( | ||
mode="w+", delete=False | ||
) as temp_gitignore: | ||
temp_gitignore.write("__pycache__\nvenv") | ||
temp_gitignore_path = temp_gitignore.name | ||
|
||
try: | ||
ignore_patterns = parse_gitignore( | ||
temp_gitignore_path, ["additional_pattern"] | ||
) | ||
self.assertIn("__pycache__", ignore_patterns) | ||
self.assertIn("venv", ignore_patterns) | ||
self.assertIn("additional_pattern", ignore_patterns) | ||
finally: | ||
os.unlink(temp_gitignore_path) | ||
|
||
def test_is_ignored(self): | ||
ignore_patterns = {"__pycache__", "venv"} | ||
self.assertTrue(is_ignored("test/__pycache__/file.py", ignore_patterns)) | ||
self.assertTrue( | ||
is_ignored("test/__pycache__/file.py", ignore_patterns) | ||
) | ||
self.assertFalse(is_ignored("test/file.py", ignore_patterns)) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |