6 git_ftp
= __import__('git-ftp', globals(), locals(), ['parse_ftpignore', 'is_ignored', 'split_pattern'], 0)
7 parse_ftpignore
= git_ftp
.parse_ftpignore
8 is_ignored
= git_ftp
.is_ignored
9 split_pattern
= git_ftp
.split_pattern
12 class TestGitFtp(unittest
.TestCase
):
14 def test_parse_ftpignore(self
):
16 # comment and blank line
18 # negate patterns behaviour (not supported)
22 # shell glob (without /)
30 self
.assertEqual(parse_ftpignore(patterns
.split("\n")),
31 ['!fileX.txt', 'config/', '*swp', 'BasePresenter.php', 'css/*less', '/.htaccess']
35 def test_split_pattern(self
):
36 self
.assertEqual(split_pattern('/foo/rand[/]om/dir/'), ['', 'foo\\Z(?ms)', 'rand[/]om\\Z(?ms)', 'dir\\Z(?ms)', '\\Z(?ms)'])
37 self
.assertEqual(split_pattern('/ano[/]her/bar/file[.-0]txt'), ['', 'ano[/]her\\Z(?ms)', 'bar\\Z(?ms)', 'file[.-0]txt\\Z(?ms)'])
38 self
.assertEqual(split_pattern('left[/right'), ['left\\[\\Z(?ms)', 'right\\Z(?ms)'])
39 self
.assertEqual(split_pattern('left[/notright]'), ['left[/notright]\\Z(?ms)'])
42 def test_is_ignored(self
):
43 self
.assertTrue(is_ignored('/foo/bar/', 'bar/'), 'Ending slash matches only dir.')
44 self
.assertFalse(is_ignored('/foo/bar', 'bar/'), 'Ending slash matches only dir.')
45 self
.assertTrue(is_ignored('/foo/bar/baz', 'bar/'), 'Ending slash matches only dir and path underneath it.')
47 self
.assertFalse(is_ignored('foo/bar', 'foo?*bar'), 'Slash must be matched explicitly.')
49 self
.assertTrue(is_ignored('/foo/bar/', 'bar'))
50 self
.assertTrue(is_ignored('/foo/bar', 'bar'))
51 self
.assertTrue(is_ignored('/foo/bar/baz', 'bar'))
53 self
.assertTrue(is_ignored('/foo/bar/file.txt', 'bar/*.txt'))
54 self
.assertFalse(is_ignored('/foo/bar/file.txt', '/*.txt'), 'Leading slash matches against root dir.')
55 self
.assertTrue(is_ignored('/file.txt', '/*.txt'), 'Leading slash matches against root dir.')
57 self
.assertTrue(is_ignored('/foo/bar/output.o', 'bar/*.[oa]'), 'Character group.')
58 self
.assertFalse(is_ignored('/aaa/bbb/ccc', 'aaa/[!b]*'), 'Character ignore.')
59 self
.assertTrue(is_ignored('/aaa/bbb/ccc', '[a-z][a-c][!b-d]'), 'Character range.')
63 if __name__
== '__main__':