2009-04-05 18:44:08 -03:00
|
|
|
"""Tests for distutils.filelist."""
|
2009-08-18 05:16:33 -03:00
|
|
|
from os.path import join
|
2009-04-05 18:44:08 -03:00
|
|
|
import unittest
|
2009-08-18 05:16:33 -03:00
|
|
|
from distutils.filelist import glob_to_re, FileList
|
|
|
|
|
|
|
|
MANIFEST_IN = """\
|
|
|
|
include ok
|
|
|
|
include xo
|
|
|
|
exclude xo
|
|
|
|
include foo.tmp
|
|
|
|
global-include *.x
|
|
|
|
global-include *.txt
|
|
|
|
global-exclude *.tmp
|
|
|
|
recursive-include f *.oo
|
|
|
|
recursive-exclude global *.x
|
|
|
|
graft dir
|
|
|
|
prune dir3
|
|
|
|
"""
|
2009-04-05 18:44:08 -03:00
|
|
|
|
|
|
|
class FileListTestCase(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_glob_to_re(self):
|
|
|
|
# simple cases
|
2009-08-17 18:28:34 -03:00
|
|
|
self.assertEquals(glob_to_re('foo*'), 'foo[^/]*\\Z(?ms)')
|
|
|
|
self.assertEquals(glob_to_re('foo?'), 'foo[^/]\\Z(?ms)')
|
|
|
|
self.assertEquals(glob_to_re('foo??'), 'foo[^/][^/]\\Z(?ms)')
|
2009-04-05 18:44:08 -03:00
|
|
|
|
|
|
|
# special cases
|
2009-08-17 18:28:34 -03:00
|
|
|
self.assertEquals(glob_to_re(r'foo\\*'), r'foo\\\\[^/]*\Z(?ms)')
|
|
|
|
self.assertEquals(glob_to_re(r'foo\\\*'), r'foo\\\\\\[^/]*\Z(?ms)')
|
|
|
|
self.assertEquals(glob_to_re('foo????'), r'foo[^/][^/][^/][^/]\Z(?ms)')
|
|
|
|
self.assertEquals(glob_to_re(r'foo\\??'), r'foo\\\\[^/][^/]\Z(?ms)')
|
2009-04-05 18:44:08 -03:00
|
|
|
|
2009-08-18 05:16:33 -03:00
|
|
|
def test_process_template_line(self):
|
|
|
|
# testing all MANIFEST.in template patterns
|
|
|
|
file_list = FileList()
|
|
|
|
|
|
|
|
# simulated file list
|
2009-08-18 05:21:49 -03:00
|
|
|
file_list.allfiles = ['foo.tmp', 'ok', 'xo', 'four.txt',
|
2009-08-18 05:16:33 -03:00
|
|
|
join('global', 'one.txt'),
|
|
|
|
join('global', 'two.txt'),
|
|
|
|
join('global', 'files.x'),
|
|
|
|
join('global', 'here.tmp'),
|
|
|
|
join('f', 'o', 'f.oo'),
|
|
|
|
join('dir', 'graft-one'),
|
|
|
|
join('dir', 'dir2', 'graft2'),
|
|
|
|
join('dir3', 'ok'),
|
|
|
|
join('dir3', 'sub', 'ok.txt')
|
|
|
|
]
|
|
|
|
|
|
|
|
for line in MANIFEST_IN.split('\n'):
|
|
|
|
if line.strip() == '':
|
|
|
|
continue
|
|
|
|
file_list.process_template_line(line)
|
|
|
|
|
2009-08-18 05:21:49 -03:00
|
|
|
wanted = ['ok', 'four.txt', join('global', 'one.txt'),
|
|
|
|
join('global', 'two.txt'), join('f', 'o', 'f.oo'),
|
|
|
|
join('dir', 'graft-one'), join('dir', 'dir2', 'graft2')]
|
2009-08-18 05:16:33 -03:00
|
|
|
|
|
|
|
self.assertEquals(file_list.files, wanted)
|
|
|
|
|
2009-04-05 18:44:08 -03:00
|
|
|
def test_suite():
|
|
|
|
return unittest.makeSuite(FileListTestCase)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main(defaultTest="test_suite")
|