forked from mherrmann/gitignore_parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
21 lines (19 loc) · 660 Bytes
/
tests.py
File metadata and controls
21 lines (19 loc) · 660 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from gitignore_parser import parse_gitignore
from tempfile import NamedTemporaryFile
from unittest import TestCase
class Test(TestCase):
def test_simple(self):
matches = _parse_gitignore_string(
'__pycache__/\n'
'*.py[cod]',
fake_base_dir='/home/michael'
)
self.assertFalse(matches('/home/michael/main.py'))
self.assertTrue(matches('/home/michael/main.pyc'))
self.assertTrue(matches('/home/michael/dir/main.pyc'))
self.assertTrue(matches('/home/michael/__pycache__'))
def _parse_gitignore_string(s, fake_base_dir=None):
with NamedTemporaryFile('w') as tmp:
tmp.write(s)
tmp.seek(0)
return parse_gitignore(tmp.name, fake_base_dir)