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

Side by Side Diff: Lib/packaging/tests/test_command_build_ext.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 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
« no previous file with comments | « Lib/packaging/tests/support.py ('k') | Lib/packaging/tests/test_command_register.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import os 1 import os
2 import sys 2 import sys
3 import site 3 import site
4 import shutil 4 import shutil
5 import sysconfig 5 import sysconfig
6 import textwrap
7 from io import StringIO 6 from io import StringIO
8 from packaging.dist import Distribution 7 from packaging.dist import Distribution
9 from packaging.errors import (UnknownFileError, CompileError, 8 from packaging.errors import UnknownFileError, CompileError
10 PackagingPlatformError)
11 from packaging.command.build_ext import build_ext 9 from packaging.command.build_ext import build_ext
12 from packaging.compiler.extension import Extension 10 from packaging.compiler.extension import Extension
13 from test.script_helper import assert_python_ok 11 from test.script_helper import assert_python_ok
14 12
15 from packaging.tests import support, unittest, verbose, unload 13 from packaging.tests import support, unittest, verbose, unload
16 14
17 15
18 def _get_source_filename(): 16 def _get_source_filename():
19 # use installed copy if available
20 tests_f = os.path.join(os.path.dirname(__file__), 'xxmodule.c')
21 if os.path.exists(tests_f):
22 return tests_f
23 # otherwise try using copy from build directory
24 srcdir = sysconfig.get_config_var('srcdir') 17 srcdir = sysconfig.get_config_var('srcdir')
25 return os.path.join(srcdir, 'Modules', 'xxmodule.c') 18 return os.path.join(srcdir, 'Modules', 'xxmodule.c')
26 19
27 20
28 class BuildExtTestCase(support.TempdirManager, 21 class BuildExtTestCase(support.TempdirManager,
29 support.LoggingCatcher, 22 support.LoggingCatcher,
30 unittest.TestCase): 23 unittest.TestCase):
31 def setUp(self): 24 def setUp(self):
32 # Create a simple test environment 25 # Create a simple test environment
33 # Note that we're making changes to sys.path 26 # Note that we're making changes to sys.path
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 path = cmd.get_ext_fullpath('twisted.runner.portmap') 349 path = cmd.get_ext_fullpath('twisted.runner.portmap')
357 wanted = os.path.join(curdir, 'tmpdir', 'twisted', 'runner', 350 wanted = os.path.join(curdir, 'tmpdir', 'twisted', 'runner',
358 'portmap' + ext) 351 'portmap' + ext)
359 self.assertEqual(wanted, path) 352 self.assertEqual(wanted, path)
360 353
361 # building twisted.runner.portmap inplace 354 # building twisted.runner.portmap inplace
362 cmd.inplace = True 355 cmd.inplace = True
363 path = cmd.get_ext_fullpath('twisted.runner.portmap') 356 path = cmd.get_ext_fullpath('twisted.runner.portmap')
364 wanted = os.path.join(curdir, 'twisted', 'runner', 'portmap' + ext) 357 wanted = os.path.join(curdir, 'twisted', 'runner', 'portmap' + ext)
365 self.assertEqual(wanted, path) 358 self.assertEqual(wanted, path)
366
367 @unittest.skipUnless(sys.platform == 'darwin',
368 'test only relevant for Mac OS X')
369 def test_deployment_target_default(self):
370 # Issue 9516: Test that, in the absence of the environment variable,
371 # an extension module is compiled with the same deployment target as
372 # the interpreter.
373 self._try_compile_deployment_target('==', None)
374
375 @unittest.skipUnless(sys.platform == 'darwin',
376 'test only relevant for Mac OS X')
377 def test_deployment_target_too_low(self):
378 # Issue 9516: Test that an extension module is not allowed to be
379 # compiled with a deployment target less than that of the interpreter.
380 self.assertRaises(PackagingPlatformError,
381 self._try_compile_deployment_target, '>', '10.1')
382
383 @unittest.skipUnless(sys.platform == 'darwin',
384 'test only relevant for Mac OS X')
385 def test_deployment_target_higher_ok(self):
386 # Issue 9516: Test that an extension module can be compiled with a
387 # deployment target higher than that of the interpreter: the ext
388 # module may depend on some newer OS feature.
389 deptarget = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
390 if deptarget:
391 # increment the minor version number (i.e. 10.6 -> 10.7)
392 deptarget = [int(x) for x in deptarget.split('.')]
393 deptarget[-1] += 1
394 deptarget = '.'.join(str(i) for i in deptarget)
395 self._try_compile_deployment_target('<', deptarget)
396
397 def _try_compile_deployment_target(self, operator, target):
398 orig_environ = os.environ
399 os.environ = orig_environ.copy()
400 self.addCleanup(setattr, os, 'environ', orig_environ)
401
402 if target is None:
403 if os.environ.get('MACOSX_DEPLOYMENT_TARGET'):
404 del os.environ['MACOSX_DEPLOYMENT_TARGET']
405 else:
406 os.environ['MACOSX_DEPLOYMENT_TARGET'] = target
407
408 deptarget_c = os.path.join(self.tmp_dir, 'deptargetmodule.c')
409
410 with open(deptarget_c, 'w') as fp:
411 fp.write(textwrap.dedent('''\
412 #include <AvailabilityMacros.h>
413
414 int dummy;
415
416 #if TARGET %s MAC_OS_X_VERSION_MIN_REQUIRED
417 #else
418 #error "Unexpected target"
419 #endif
420
421 ''' % operator))
422
423 # get the deployment target that the interpreter was built with
424 target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
425 target = tuple(map(int, target.split('.')))
426 target = '%02d%01d0' % target
427
428 deptarget_ext = Extension(
429 'deptarget',
430 [deptarget_c],
431 extra_compile_args=['-DTARGET=%s' % (target,)],
432 )
433 dist = Distribution({
434 'name': 'deptarget',
435 'ext_modules': [deptarget_ext],
436 })
437 dist.package_dir = self.tmp_dir
438 cmd = build_ext(dist)
439 cmd.build_lib = self.tmp_dir
440 cmd.build_temp = self.tmp_dir
441
442 try:
443 old_stdout = sys.stdout
444 if not verbose:
445 # silence compiler output
446 sys.stdout = StringIO()
447 try:
448 cmd.ensure_finalized()
449 cmd.run()
450 finally:
451 sys.stdout = old_stdout
452
453 except CompileError:
454 self.fail("Wrong deployment target during compilation")
455 359
456 360
457 def test_suite(): 361 def test_suite():
458 src = _get_source_filename() 362 src = _get_source_filename()
459 if not os.path.exists(src): 363 if not os.path.exists(src):
460 if verbose: 364 if verbose:
461 print('test_command_build_ext: Cannot find source code (test' 365 print('test_command_build_ext: Cannot find source code (test'
462 ' must run in python build dir)') 366 ' must run in python build dir)')
463 return unittest.TestSuite() 367 return unittest.TestSuite()
464 else: 368 else:
465 return unittest.makeSuite(BuildExtTestCase) 369 return unittest.makeSuite(BuildExtTestCase)
466 370
467 if __name__ == '__main__': 371 if __name__ == '__main__':
468 unittest.main(defaultTest='test_suite') 372 unittest.main(defaultTest='test_suite')
OLDNEW
« no previous file with comments | « Lib/packaging/tests/support.py ('k') | Lib/packaging/tests/test_command_register.py » ('j') | no next file with comments »

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