Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(30553)

Side by Side Diff: Lib/distutils/tests/test_build_ext.py

Issue 19600: Use specific asserts in distutils tests
Patch Set: Created 5 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 import sys 1 import sys
2 import os 2 import os
3 from io import StringIO 3 from io import StringIO
4 import textwrap 4 import textwrap
5 5
6 from distutils.core import Distribution 6 from distutils.core import Distribution
7 from distutils.command.build_ext import build_ext 7 from distutils.command.build_ext import build_ext
8 from distutils import sysconfig 8 from distutils import sysconfig
9 from distutils.tests.support import (TempdirManager, LoggingSilencer, 9 from distutils.tests.support import (TempdirManager, LoggingSilencer,
10 copy_xxmodule_c, fixup_build_ext) 10 copy_xxmodule_c, fixup_build_ext)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 for attr in ('error', 'foo', 'new', 'roj'): 70 for attr in ('error', 'foo', 'new', 'roj'):
71 self.assertTrue(hasattr(xx, attr)) 71 self.assertTrue(hasattr(xx, attr))
72 72
73 self.assertEqual(xx.foo(2, 5), 7) 73 self.assertEqual(xx.foo(2, 5), 7)
74 self.assertEqual(xx.foo(13,15), 28) 74 self.assertEqual(xx.foo(13,15), 28)
75 self.assertEqual(xx.new().demo(), None) 75 self.assertEqual(xx.new().demo(), None)
76 if support.HAVE_DOCSTRINGS: 76 if support.HAVE_DOCSTRINGS:
77 doc = 'This is a template module just for instruction.' 77 doc = 'This is a template module just for instruction.'
78 self.assertEqual(xx.__doc__, doc) 78 self.assertEqual(xx.__doc__, doc)
79 self.assertTrue(isinstance(xx.Null(), xx.Null)) 79 self.assertIsInstance(xx.Null(), xx.Null)
80 self.assertTrue(isinstance(xx.Str(), xx.Str)) 80 self.assertIsInstance(xx.Str(), xx.Str)
81 81
82 def tearDown(self): 82 def tearDown(self):
83 # Get everything back to normal 83 # Get everything back to normal
84 support.unload('xx') 84 support.unload('xx')
85 sys.path = self.sys_path[0] 85 sys.path = self.sys_path[0]
86 sys.path[:] = self.sys_path[1] 86 sys.path[:] = self.sys_path[1]
87 if sys.version > "2.6": 87 if sys.version > "2.6":
88 import site 88 import site
89 site.USER_BASE = self.old_user_base 89 site.USER_BASE = self.old_user_base
90 from distutils.command import build_ext 90 from distutils.command import build_ext
(...skipping 12 matching lines...) Expand all
103 try: 103 try:
104 cmd.ensure_finalized() 104 cmd.ensure_finalized()
105 finally: 105 finally:
106 sys.platform = old 106 sys.platform = old
107 if old_var is None: 107 if old_var is None:
108 del _config_vars['Py_ENABLE_SHARED'] 108 del _config_vars['Py_ENABLE_SHARED']
109 else: 109 else:
110 _config_vars['Py_ENABLE_SHARED'] = old_var 110 _config_vars['Py_ENABLE_SHARED'] = old_var
111 111
112 # make sure we get some library dirs under solaris 112 # make sure we get some library dirs under solaris
113 self.assertTrue(len(cmd.library_dirs) > 0) 113 self.assertGreater(len(cmd.library_dirs), 0)
114 114
115 def test_user_site(self): 115 def test_user_site(self):
116 # site.USER_SITE was introduced in 2.6 116 # site.USER_SITE was introduced in 2.6
117 if sys.version < '2.6': 117 if sys.version < '2.6':
118 return 118 return
119 119
120 import site 120 import site
121 dist = Distribution({'name': 'xx'}) 121 dist = Distribution({'name': 'xx'})
122 cmd = build_ext(dist) 122 cmd = build_ext(dist)
123 123
124 # making sure the user option is there 124 # making sure the user option is there
125 options = [name for name, short, lable in 125 options = [name for name, short, lable in
126 cmd.user_options] 126 cmd.user_options]
127 self.assertTrue('user' in options) 127 self.assertIn('user', options)
128 128
129 # setting a value 129 # setting a value
130 cmd.user = 1 130 cmd.user = 1
131 131
132 # setting user based lib and include 132 # setting user based lib and include
133 lib = os.path.join(site.USER_BASE, 'lib') 133 lib = os.path.join(site.USER_BASE, 'lib')
134 incl = os.path.join(site.USER_BASE, 'include') 134 incl = os.path.join(site.USER_BASE, 'include')
135 os.mkdir(lib) 135 os.mkdir(lib)
136 os.mkdir(incl) 136 os.mkdir(incl)
137 137
(...skipping 26 matching lines...) Expand all
164 def test_finalize_options(self): 164 def test_finalize_options(self):
165 # Make sure Python's include directories (for Python.h, pyconfig.h, 165 # Make sure Python's include directories (for Python.h, pyconfig.h,
166 # etc.) are in the include search path. 166 # etc.) are in the include search path.
167 modules = [Extension('foo', ['xxx'], optional=False)] 167 modules = [Extension('foo', ['xxx'], optional=False)]
168 dist = Distribution({'name': 'xx', 'ext_modules': modules}) 168 dist = Distribution({'name': 'xx', 'ext_modules': modules})
169 cmd = build_ext(dist) 169 cmd = build_ext(dist)
170 cmd.finalize_options() 170 cmd.finalize_options()
171 171
172 from distutils import sysconfig 172 from distutils import sysconfig
173 py_include = sysconfig.get_python_inc() 173 py_include = sysconfig.get_python_inc()
174 self.assertTrue(py_include in cmd.include_dirs) 174 self.assertIn(py_include, cmd.include_dirs)
175 175
176 plat_py_include = sysconfig.get_python_inc(plat_specific=1) 176 plat_py_include = sysconfig.get_python_inc(plat_specific=1)
177 self.assertTrue(plat_py_include in cmd.include_dirs) 177 self.assertIn(plat_py_include, cmd.include_dirs)
178 178
179 # make sure cmd.libraries is turned into a list 179 # make sure cmd.libraries is turned into a list
180 # if it's a string 180 # if it's a string
181 cmd = build_ext(dist) 181 cmd = build_ext(dist)
182 cmd.libraries = 'my_lib, other_lib lastlib' 182 cmd.libraries = 'my_lib, other_lib lastlib'
183 cmd.finalize_options() 183 cmd.finalize_options()
184 self.assertEqual(cmd.libraries, ['my_lib', 'other_lib', 'lastlib']) 184 self.assertEqual(cmd.libraries, ['my_lib', 'other_lib', 'lastlib'])
185 185
186 # make sure cmd.library_dirs is turned into a list 186 # make sure cmd.library_dirs is turned into a list
187 # if it's a string 187 # if it's a string
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 # second element of each tuple in 'ext_modules' 248 # second element of each tuple in 'ext_modules'
249 # must be a ary (build info) 249 # must be a ary (build info)
250 exts = [('foo.bar', '')] 250 exts = [('foo.bar', '')]
251 self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, exts) 251 self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, exts)
252 252
253 # ok this one should pass 253 # ok this one should pass
254 exts = [('foo.bar', {'sources': [''], 'libraries': 'foo', 254 exts = [('foo.bar', {'sources': [''], 'libraries': 'foo',
255 'some': 'bar'})] 255 'some': 'bar'})]
256 cmd.check_extensions_list(exts) 256 cmd.check_extensions_list(exts)
257 ext = exts[0] 257 ext = exts[0]
258 self.assertTrue(isinstance(ext, Extension)) 258 self.assertIsInstance(ext, Extension)
259 259
260 # check_extensions_list adds in ext the values passed 260 # check_extensions_list adds in ext the values passed
261 # when they are in ('include_dirs', 'library_dirs', 'libraries' 261 # when they are in ('include_dirs', 'library_dirs', 'libraries'
262 # 'extra_objects', 'extra_compile_args', 'extra_link_args') 262 # 'extra_objects', 'extra_compile_args', 'extra_link_args')
263 self.assertEqual(ext.libraries, 'foo') 263 self.assertEqual(ext.libraries, 'foo')
264 self.assertTrue(not hasattr(ext, 'some')) 264 self.assertFalse(hasattr(ext, 'some'))
265 265
266 # 'macros' element of build info dict must be 1- or 2-tuple 266 # 'macros' element of build info dict must be 1- or 2-tuple
267 exts = [('foo.bar', {'sources': [''], 'libraries': 'foo', 267 exts = [('foo.bar', {'sources': [''], 'libraries': 'foo',
268 'some': 'bar', 'macros': [('1', '2', '3'), 'foo']})] 268 'some': 'bar', 'macros': [('1', '2', '3'), 'foo']})]
269 self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, exts) 269 self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, exts)
270 270
271 exts[0][1]['macros'] = [('1', '2'), ('3',)] 271 exts[0][1]['macros'] = [('1', '2'), ('3',)]
272 cmd.check_extensions_list(exts) 272 cmd.check_extensions_list(exts)
273 self.assertEqual(exts[0].undef_macros, ['3']) 273 self.assertEqual(exts[0].undef_macros, ['3'])
274 self.assertEqual(exts[0].define_macros, [('1', '2')]) 274 self.assertEqual(exts[0].define_macros, [('1', '2')])
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 477
478 except CompileError: 478 except CompileError:
479 self.fail("Wrong deployment target during compilation") 479 self.fail("Wrong deployment target during compilation")
480 480
481 481
482 def test_suite(): 482 def test_suite():
483 return unittest.makeSuite(BuildExtTestCase) 483 return unittest.makeSuite(BuildExtTestCase)
484 484
485 if __name__ == '__main__': 485 if __name__ == '__main__':
486 support.run_unittest(test_suite()) 486 support.run_unittest(test_suite())
OLDNEW

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+