Tarek Ziadé | 889b0aa | 2009-04-05 21:49:36 +0000 | [diff] [blame] | 1 | """Tests for distutils.filelist.""" |
| 2 | import unittest |
Tarek Ziadé | 03d5d08 | 2009-09-21 13:01:54 +0000 | [diff] [blame] | 3 | |
Tarek Ziadé | 6173285 | 2009-08-18 08:23:10 +0000 | [diff] [blame] | 4 | from distutils.filelist import glob_to_re, FileList |
Éric Araujo | 70ec44a | 2010-11-06 02:44:43 +0000 | [diff] [blame] | 5 | from test.support import captured_stdout, run_unittest |
Tarek Ziadé | 03d5d08 | 2009-09-21 13:01:54 +0000 | [diff] [blame] | 6 | from distutils import debug |
Tarek Ziadé | 6173285 | 2009-08-18 08:23:10 +0000 | [diff] [blame] | 7 | |
Tarek Ziadé | 889b0aa | 2009-04-05 21:49:36 +0000 | [diff] [blame] | 8 | class FileListTestCase(unittest.TestCase): |
| 9 | |
| 10 | def test_glob_to_re(self): |
| 11 | # simple cases |
Tarek Ziadé | 74c23ac | 2009-08-17 21:35:46 +0000 | [diff] [blame] | 12 | self.assertEquals(glob_to_re('foo*'), 'foo[^/]*\\Z(?ms)') |
| 13 | self.assertEquals(glob_to_re('foo?'), 'foo[^/]\\Z(?ms)') |
| 14 | self.assertEquals(glob_to_re('foo??'), 'foo[^/][^/]\\Z(?ms)') |
Tarek Ziadé | 889b0aa | 2009-04-05 21:49:36 +0000 | [diff] [blame] | 15 | |
| 16 | # special cases |
Tarek Ziadé | 74c23ac | 2009-08-17 21:35:46 +0000 | [diff] [blame] | 17 | self.assertEquals(glob_to_re(r'foo\\*'), r'foo\\\\[^/]*\Z(?ms)') |
| 18 | self.assertEquals(glob_to_re(r'foo\\\*'), r'foo\\\\\\[^/]*\Z(?ms)') |
| 19 | self.assertEquals(glob_to_re('foo????'), r'foo[^/][^/][^/][^/]\Z(?ms)') |
| 20 | self.assertEquals(glob_to_re(r'foo\\??'), r'foo\\\\[^/][^/]\Z(?ms)') |
Tarek Ziadé | 889b0aa | 2009-04-05 21:49:36 +0000 | [diff] [blame] | 21 | |
Tarek Ziadé | 03d5d08 | 2009-09-21 13:01:54 +0000 | [diff] [blame] | 22 | def test_debug_print(self): |
| 23 | file_list = FileList() |
| 24 | with captured_stdout() as stdout: |
| 25 | file_list.debug_print('xxx') |
| 26 | stdout.seek(0) |
| 27 | self.assertEquals(stdout.read(), '') |
| 28 | |
| 29 | debug.DEBUG = True |
| 30 | try: |
| 31 | with captured_stdout() as stdout: |
| 32 | file_list.debug_print('xxx') |
| 33 | stdout.seek(0) |
| 34 | self.assertEquals(stdout.read(), 'xxx\n') |
| 35 | finally: |
| 36 | debug.DEBUG = False |
| 37 | |
Tarek Ziadé | 889b0aa | 2009-04-05 21:49:36 +0000 | [diff] [blame] | 38 | def test_suite(): |
| 39 | return unittest.makeSuite(FileListTestCase) |
| 40 | |
| 41 | if __name__ == "__main__": |
Éric Araujo | 70ec44a | 2010-11-06 02:44:43 +0000 | [diff] [blame] | 42 | run_unittest(test_suite()) |