def test_read_manifest(self): import check_manifest from check_manifest import _glob_to_regexp as g2r with open('MANIFEST.in', 'w') as f: f.write('exclude *.gif\n') f.write('global-exclude *.png\n') check_manifest.read_manifest() self.assertEqual(check_manifest.IGNORE, ['default-ignore-rules', '*.png']) self.assertEqual(check_manifest.IGNORE_REGEXPS, ['default-ignore-regexps', g2r('*.gif')])
def test_glob_to_regexp(self): from check_manifest import _glob_to_regexp as g2r sep = r'\\' if os.path.sep == '\\' else os.path.sep self.assertEqual(g2r('foo.py'), r'foo\.py\Z(?ms)') self.assertEqual(g2r('foo/bar.py'), r'foo\/bar\.py\Z(?ms)') self.assertEqual(g2r('foo*.py'), r'foo[^%s]*\.py\Z(?ms)' % sep) self.assertEqual(g2r('foo?.py'), r'foo[^%s]\.py\Z(?ms)' % sep) self.assertEqual(g2r('foo[123].py'), r'foo[123]\.py\Z(?ms)') self.assertEqual(g2r('foo[!123].py'), r'foo[^123]\.py\Z(?ms)') self.assertEqual(g2r('foo/*.py'), r'foo\/[^%s]*\.py\Z(?ms)' % sep)
def test_get_ignore_from_manifest(self): from check_manifest import _get_ignore_from_manifest as parse from check_manifest import _glob_to_regexp as g2r j = os.path.join # The return value is a tuple with two lists: # ([<list of filename ignores>], [<list of regular expressions>]) self.assertEqual(parse(''), ([], [])) self.assertEqual(parse(' \n '), ([], [])) self.assertEqual(parse('exclude *.cfg'), ([], [g2r('*.cfg')])) self.assertEqual(parse('#exclude *.cfg'), ([], [])) self.assertEqual(parse('exclude *.cfg'), ([], [g2r('*.cfg')])) self.assertEqual(parse('\texclude\t*.cfg foo.* bar.txt'), (['bar.txt'], [g2r('*.cfg'), g2r('foo.*')])) self.assertEqual(parse('exclude some/directory/*.cfg'), ([], [g2r('some/directory/*.cfg')])) self.assertEqual(parse('include *.cfg'), ([], [])) self.assertEqual(parse('global-exclude *.pyc'), (['*.pyc'], [])) self.assertEqual(parse('global-exclude *.pyc *.sh'), (['*.pyc', '*.sh'], [])) self.assertEqual(parse('recursive-exclude dir *.pyc'), ([j('dir', '*.pyc')], [])) self.assertEqual(parse('recursive-exclude dir *.pyc foo*.sh'), ([j('dir', '*.pyc'), j('dir', 'foo*.sh'), j('dir', '*', 'foo*.sh')], [])) self.assertEqual(parse('recursive-exclude dir nopattern.xml'), ([j('dir', 'nopattern.xml'), j('dir', '*', 'nopattern.xml')], [])) # We should not fail when a recursive-exclude line is wrong: self.assertEqual(parse('recursive-exclude dirwithoutpattern'), ([], [])) self.assertEqual(parse('prune dir'), (['dir', j('dir', '*')], [])) # You should not add a slash at the end of a prune, but let's # not fail over it or end up with double slashes. self.assertEqual(parse('prune dir/'), (['dir', j('dir', '*')], [])) # You should also not have a leading slash self.assertEqual(parse('prune /dir'), (['/dir', j('/dir', '*')], [])) # And a mongo test case of everything at the end text = textwrap.dedent(""" #exclude *.01 exclude *.02 exclude *.03 04.* bar.txt exclude *.05 exclude some/directory/*.cfg global-exclude *.10 *.11 global-exclude *.12 include *.20 prune 30 recursive-exclude 40 *.41 recursive-exclude 42 *.43 44.* """) self.assertEqual( parse(text), ([ 'bar.txt', '*.10', '*.11', '*.12', '30', j('30', '*'), j('40', '*.41'), j('42', '*.43'), j('42', '44.*'), j('42', '*', '44.*'), ], [ g2r('*.02'), g2r('*.03'), g2r('04.*'), g2r('*.05'), g2r('some/directory/*.cfg'), ]))
def test_get_ignore_from_manifest(self): from check_manifest import _get_ignore_from_manifest as parse from check_manifest import _glob_to_regexp as g2r j = os.path.join # The return value is a tuple with two lists: # ([<list of filename ignores>], [<list of regular expressions>]) self.assertEqual(parse(''), ([], [])) self.assertEqual(parse(' \n '), ([], [])) self.assertEqual(parse('exclude *.cfg'), ([], [g2r('*.cfg')])) self.assertEqual(parse('#exclude *.cfg'), ([], [])) self.assertEqual(parse('exclude *.cfg'), ([], [g2r('*.cfg')])) self.assertEqual( parse('\texclude\t*.cfg foo.* bar.txt'), (['bar.txt'], [g2r('*.cfg'), g2r('foo.*')])) self.assertEqual(parse('exclude some/directory/*.cfg'), ([], [g2r('some/directory/*.cfg')])) self.assertEqual(parse('include *.cfg'), ([], [])) self.assertEqual(parse('global-exclude *.pyc'), (['*.pyc'], [])) self.assertEqual(parse('global-exclude *.pyc *.sh'), (['*.pyc', '*.sh'], [])) self.assertEqual(parse('recursive-exclude dir *.pyc'), ([j('dir', '*.pyc')], [])) self.assertEqual(parse('recursive-exclude dir *.pyc foo*.sh'), ([ j('dir', '*.pyc'), j('dir', 'foo*.sh'), j('dir', '*', 'foo*.sh') ], [])) self.assertEqual( parse('recursive-exclude dir nopattern.xml'), ([j('dir', 'nopattern.xml'), j('dir', '*', 'nopattern.xml')], [])) # We should not fail when a recursive-exclude line is wrong: self.assertEqual(parse('recursive-exclude dirwithoutpattern'), ([], [])) self.assertEqual(parse('prune dir'), (['dir', j('dir', '*')], [])) # You should not add a slash at the end of a prune, but let's # not fail over it or end up with double slashes. self.assertEqual(parse('prune dir/'), (['dir', j('dir', '*')], [])) # You should also not have a leading slash self.assertEqual(parse('prune /dir'), (['/dir', j('/dir', '*')], [])) # And a mongo test case of everything at the end text = textwrap.dedent(""" #exclude *.01 exclude *.02 exclude *.03 04.* bar.txt exclude *.05 exclude some/directory/*.cfg global-exclude *.10 *.11 global-exclude *.12 include *.20 prune 30 recursive-exclude 40 *.41 recursive-exclude 42 *.43 44.* """) self.assertEqual(parse(text), ([ 'bar.txt', '*.10', '*.11', '*.12', '30', j('30', '*'), j('40', '*.41'), j('42', '*.43'), j('42', '44.*'), j('42', '*', '44.*'), ], [ g2r('*.02'), g2r('*.03'), g2r('04.*'), g2r('*.05'), g2r('some/directory/*.cfg'), ]))