]> git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Python/Python-2.7.2/Lib/distutils/tests/test_filelist.py
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Lib / distutils / tests / test_filelist.py
1 """Tests for distutils.filelist."""
2 from os.path import join
3 import unittest
4 from test.test_support import captured_stdout, run_unittest
5
6 from distutils.filelist import glob_to_re, FileList
7 from distutils import debug
8
9 MANIFEST_IN = """\
10 include ok
11 include xo
12 exclude xo
13 include foo.tmp
14 global-include *.x
15 global-include *.txt
16 global-exclude *.tmp
17 recursive-include f *.oo
18 recursive-exclude global *.x
19 graft dir
20 prune dir3
21 """
22
23 class FileListTestCase(unittest.TestCase):
24
25 def test_glob_to_re(self):
26 # simple cases
27 self.assertEqual(glob_to_re('foo*'), 'foo[^/]*\\Z(?ms)')
28 self.assertEqual(glob_to_re('foo?'), 'foo[^/]\\Z(?ms)')
29 self.assertEqual(glob_to_re('foo??'), 'foo[^/][^/]\\Z(?ms)')
30
31 # special cases
32 self.assertEqual(glob_to_re(r'foo\\*'), r'foo\\\\[^/]*\Z(?ms)')
33 self.assertEqual(glob_to_re(r'foo\\\*'), r'foo\\\\\\[^/]*\Z(?ms)')
34 self.assertEqual(glob_to_re('foo????'), r'foo[^/][^/][^/][^/]\Z(?ms)')
35 self.assertEqual(glob_to_re(r'foo\\??'), r'foo\\\\[^/][^/]\Z(?ms)')
36
37 def test_process_template_line(self):
38 # testing all MANIFEST.in template patterns
39 file_list = FileList()
40
41 # simulated file list
42 file_list.allfiles = ['foo.tmp', 'ok', 'xo', 'four.txt',
43 join('global', 'one.txt'),
44 join('global', 'two.txt'),
45 join('global', 'files.x'),
46 join('global', 'here.tmp'),
47 join('f', 'o', 'f.oo'),
48 join('dir', 'graft-one'),
49 join('dir', 'dir2', 'graft2'),
50 join('dir3', 'ok'),
51 join('dir3', 'sub', 'ok.txt')
52 ]
53
54 for line in MANIFEST_IN.split('\n'):
55 if line.strip() == '':
56 continue
57 file_list.process_template_line(line)
58
59 wanted = ['ok', 'four.txt', join('global', 'one.txt'),
60 join('global', 'two.txt'), join('f', 'o', 'f.oo'),
61 join('dir', 'graft-one'), join('dir', 'dir2', 'graft2')]
62
63 self.assertEqual(file_list.files, wanted)
64
65 def test_debug_print(self):
66 file_list = FileList()
67 with captured_stdout() as stdout:
68 file_list.debug_print('xxx')
69 stdout.seek(0)
70 self.assertEqual(stdout.read(), '')
71
72 debug.DEBUG = True
73 try:
74 with captured_stdout() as stdout:
75 file_list.debug_print('xxx')
76 stdout.seek(0)
77 self.assertEqual(stdout.read(), 'xxx\n')
78 finally:
79 debug.DEBUG = False
80
81 def test_suite():
82 return unittest.makeSuite(FileListTestCase)
83
84 if __name__ == "__main__":
85 run_unittest(test_suite())