| 
									
										
										
										
											2009-06-03 10:31:15 +00:00
										 |  |  | """Tests for distutils.extension.""" | 
					
						
							| 
									
										
										
										
											2010-02-24 01:46:21 +00:00
										 |  |  | import unittest | 
					
						
							| 
									
										
										
										
											2010-07-22 12:50:05 +00:00
										 |  |  | import os | 
					
						
							| 
									
										
										
										
											2009-06-03 11:17:15 +00:00
										 |  |  | import warnings | 
					
						
							| 
									
										
										
										
											2009-06-03 10:31:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-06 02:44:43 +00:00
										 |  |  | from test.support import check_warnings, run_unittest | 
					
						
							| 
									
										
										
										
											2009-06-03 11:17:15 +00:00
										 |  |  | from distutils.extension import read_setup_file, Extension | 
					
						
							| 
									
										
										
										
											2009-06-03 10:31:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | class ExtensionTestCase(unittest.TestCase): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_read_setup_file(self): | 
					
						
							|  |  |  |         # trying to read a Setup file | 
					
						
							|  |  |  |         # (sample extracted from the PyGame project) | 
					
						
							|  |  |  |         setup = os.path.join(os.path.dirname(__file__), 'Setup.sample') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         exts = read_setup_file(setup) | 
					
						
							|  |  |  |         names = [ext.name for ext in exts] | 
					
						
							|  |  |  |         names.sort() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # here are the extensions read_setup_file should have created | 
					
						
							|  |  |  |         # out of the file | 
					
						
							|  |  |  |         wanted = ['_arraysurfarray', '_camera', '_numericsndarray', | 
					
						
							|  |  |  |                   '_numericsurfarray', 'base', 'bufferproxy', 'cdrom', | 
					
						
							|  |  |  |                   'color', 'constants', 'display', 'draw', 'event', | 
					
						
							|  |  |  |                   'fastevent', 'font', 'gfxdraw', 'image', 'imageext', | 
					
						
							|  |  |  |                   'joystick', 'key', 'mask', 'mixer', 'mixer_music', | 
					
						
							|  |  |  |                   'mouse', 'movie', 'overlay', 'pixelarray', 'pypm', | 
					
						
							|  |  |  |                   'rect', 'rwobject', 'scrap', 'surface', 'surflock', | 
					
						
							|  |  |  |                   'time', 'transform'] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-20 19:04:17 +00:00
										 |  |  |         self.assertEqual(names, wanted) | 
					
						
							| 
									
										
										
										
											2009-06-03 10:31:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-22 12:50:05 +00:00
										 |  |  |     def test_extension_init(self): | 
					
						
							|  |  |  |         # the first argument, which is the name, must be a string | 
					
						
							| 
									
										
										
										
											2009-06-03 11:17:15 +00:00
										 |  |  |         self.assertRaises(AssertionError, Extension, 1, []) | 
					
						
							| 
									
										
										
										
											2010-07-22 12:50:05 +00:00
										 |  |  |         ext = Extension('name', []) | 
					
						
							| 
									
										
										
										
											2010-11-20 19:04:17 +00:00
										 |  |  |         self.assertEqual(ext.name, 'name') | 
					
						
							| 
									
										
										
										
											2009-06-03 11:17:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # the second argument, which is the list of files, must | 
					
						
							|  |  |  |         # be a list of strings | 
					
						
							|  |  |  |         self.assertRaises(AssertionError, Extension, 'name', 'file') | 
					
						
							|  |  |  |         self.assertRaises(AssertionError, Extension, 'name', ['file', 1]) | 
					
						
							|  |  |  |         ext = Extension('name', ['file1', 'file2']) | 
					
						
							| 
									
										
										
										
											2010-11-20 19:04:17 +00:00
										 |  |  |         self.assertEqual(ext.sources, ['file1', 'file2']) | 
					
						
							| 
									
										
										
										
											2009-06-03 11:17:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # others arguments have defaults | 
					
						
							|  |  |  |         for attr in ('include_dirs', 'define_macros', 'undef_macros', | 
					
						
							|  |  |  |                      'library_dirs', 'libraries', 'runtime_library_dirs', | 
					
						
							|  |  |  |                      'extra_objects', 'extra_compile_args', 'extra_link_args', | 
					
						
							|  |  |  |                      'export_symbols', 'swig_opts', 'depends'): | 
					
						
							| 
									
										
										
										
											2010-11-20 19:04:17 +00:00
										 |  |  |             self.assertEqual(getattr(ext, attr), []) | 
					
						
							| 
									
										
										
										
											2009-06-03 11:17:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-20 19:04:17 +00:00
										 |  |  |         self.assertEqual(ext.language, None) | 
					
						
							|  |  |  |         self.assertEqual(ext.optional, None) | 
					
						
							| 
									
										
										
										
											2009-06-03 11:17:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # if there are unknown keyword options, warn about them | 
					
						
							|  |  |  |         with check_warnings() as w: | 
					
						
							|  |  |  |             warnings.simplefilter('always') | 
					
						
							|  |  |  |             ext = Extension('name', ['file1', 'file2'], chic=True) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-20 19:04:17 +00:00
										 |  |  |         self.assertEqual(len(w.warnings), 1) | 
					
						
							|  |  |  |         self.assertEqual(str(w.warnings[0].message), | 
					
						
							| 
									
										
										
										
											2009-06-03 11:17:15 +00:00
										 |  |  |                           "Unknown Extension options: 'chic'") | 
					
						
							| 
									
										
										
										
											2009-06-03 10:31:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | def test_suite(): | 
					
						
							|  |  |  |     return unittest.makeSuite(ExtensionTestCase) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if __name__ == "__main__": | 
					
						
							| 
									
										
										
										
											2010-11-06 02:44:43 +00:00
										 |  |  |     run_unittest(test_suite()) |