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

Side by Side Diff: Lib/distutils/tests/test_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/distutils/sysconfig.py ('k') | Lib/distutils/tests/test_build_py.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 sys 1 import sys
2 import os 2 import os
3 import shutil 3 import shutil
4 from io import StringIO 4 from io import StringIO
5 import textwrap 5 import textwrap
6 6
7 from distutils.core import Distribution 7 from distutils.core import Distribution
8 from distutils.command.build_ext import build_ext 8 from distutils.command.build_ext import build_ext
9 from distutils import sysconfig 9 from distutils import sysconfig
10 from distutils.tests.support import TempdirManager 10 from distutils.tests.support import TempdirManager
11 from distutils.tests.support import LoggingSilencer 11 from distutils.tests.support import LoggingSilencer
12 from distutils.extension import Extension 12 from distutils.extension import Extension
13 from distutils.errors import ( 13 from distutils.errors import (
14 CompileError, DistutilsPlatformError, DistutilsSetupError, 14 CompileError, DistutilsSetupError, UnknownFileError)
15 UnknownFileError)
16 15
17 import unittest 16 import unittest
18 from test import support 17 from test import support
19 from test.support import run_unittest 18 from test.support import run_unittest
20 19
21 # http://bugs.python.org/issue4373 20 # http://bugs.python.org/issue4373
22 # Don't load the xx module more than once. 21 # Don't load the xx module more than once.
23 ALREADY_TESTED = False 22 ALREADY_TESTED = False
24 23
25 def _get_source_filename(): 24 def _get_source_filename():
26 # use installed copy if available
27 tests_f = os.path.join(os.path.dirname(__file__), 'xxmodule.c')
28 if os.path.exists(tests_f):
29 return tests_f
30 # otherwise try using copy from build directory
31 srcdir = sysconfig.get_config_var('srcdir') 25 srcdir = sysconfig.get_config_var('srcdir')
32 return os.path.join(srcdir, 'Modules', 'xxmodule.c') 26 return os.path.join(srcdir, 'Modules', 'xxmodule.c')
33 27
34 class BuildExtTestCase(TempdirManager, 28 class BuildExtTestCase(TempdirManager,
35 LoggingSilencer, 29 LoggingSilencer,
36 unittest.TestCase): 30 unittest.TestCase):
37 def setUp(self): 31 def setUp(self):
38 # Create a simple test environment 32 # Create a simple test environment
39 # Note that we're making changes to sys.path 33 # Note that we're making changes to sys.path
40 super(BuildExtTestCase, self).setUp() 34 super(BuildExtTestCase, self).setUp()
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 self.assertEqual(wanted, path) 419 self.assertEqual(wanted, path)
426 420
427 # building twisted.runner.portmap inplace 421 # building twisted.runner.portmap inplace
428 cmd.inplace = 1 422 cmd.inplace = 1
429 path = cmd.get_ext_fullpath('twisted.runner.portmap') 423 path = cmd.get_ext_fullpath('twisted.runner.portmap')
430 wanted = os.path.join(curdir, 'twisted', 'runner', 'portmap' + ext) 424 wanted = os.path.join(curdir, 'twisted', 'runner', 'portmap' + ext)
431 self.assertEqual(wanted, path) 425 self.assertEqual(wanted, path)
432 426
433 427
434 @unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for MacOS X') 428 @unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for MacOS X')
435 def test_deployment_target_default(self): 429 def test_deployment_target(self):
436 # Issue 9516: Test that, in the absence of the environment variable, 430 self._try_compile_deployment_target()
437 # an extension module is compiled with the same deployment target as
438 # the interpreter.
439 self._try_compile_deployment_target('==', None)
440 431
441 @unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for MacOS X')
442 def test_deployment_target_too_low(self):
443 # Issue 9516: Test that an extension module is not allowed to be
444 # compiled with a deployment target less than that of the interpreter.
445 self.assertRaises(DistutilsPlatformError,
446 self._try_compile_deployment_target, '>', '10.1')
447
448 @unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for MacOS X')
449 def test_deployment_target_higher_ok(self):
450 # Issue 9516: Test that an extension module can be compiled with a
451 # deployment target higher than that of the interpreter: the ext
452 # module may depend on some newer OS feature.
453 deptarget = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
454 if deptarget:
455 # increment the minor version number (i.e. 10.6 -> 10.7)
456 deptarget = [int(x) for x in deptarget.split('.')]
457 deptarget[-1] += 1
458 deptarget = '.'.join(str(i) for i in deptarget)
459 self._try_compile_deployment_target('<', deptarget)
460
461 def _try_compile_deployment_target(self, operator, target):
462 orig_environ = os.environ 432 orig_environ = os.environ
463 os.environ = orig_environ.copy() 433 os.environ = orig_environ.copy()
464 self.addCleanup(setattr, os, 'environ', orig_environ) 434 self.addCleanup(setattr, os, 'environ', orig_environ)
465 435
466 if target is None: 436 os.environ['MACOSX_DEPLOYMENT_TARGET']='10.1'
467 if os.environ.get('MACOSX_DEPLOYMENT_TARGET'): 437 self._try_compile_deployment_target()
468 del os.environ['MACOSX_DEPLOYMENT_TARGET']
469 else:
470 os.environ['MACOSX_DEPLOYMENT_TARGET'] = target
471 438
439
440 def _try_compile_deployment_target(self):
472 deptarget_c = os.path.join(self.tmp_dir, 'deptargetmodule.c') 441 deptarget_c = os.path.join(self.tmp_dir, 'deptargetmodule.c')
473 442
474 with open(deptarget_c, 'w') as fp: 443 with open(deptarget_c, 'w') as fp:
475 fp.write(textwrap.dedent('''\ 444 fp.write(textwrap.dedent('''\
476 #include <AvailabilityMacros.h> 445 #include <AvailabilityMacros.h>
477 446
478 int dummy; 447 int dummy;
479 448
480 #if TARGET %s MAC_OS_X_VERSION_MIN_REQUIRED 449 #if TARGET != MAC_OS_X_VERSION_MIN_REQUIRED
481 #else
482 #error "Unexpected target" 450 #error "Unexpected target"
483 #endif 451 #endif
484 452
485 ''' % operator)) 453 '''))
486 454
487 # get the deployment target that the interpreter was built with
488 target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') 455 target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
489 target = tuple(map(int, target.split('.'))) 456 target = tuple(map(int, target.split('.')))
490 target = '%02d%01d0' % target 457 target = '%02d%01d0' % target
458
491 deptarget_ext = Extension( 459 deptarget_ext = Extension(
492 'deptarget', 460 'deptarget',
493 [deptarget_c], 461 [deptarget_c],
494 extra_compile_args=['-DTARGET=%s'%(target,)], 462 extra_compile_args=['-DTARGET=%s'%(target,)],
495 ) 463 )
496 dist = Distribution({ 464 dist = Distribution({
497 'name': 'deptarget', 465 'name': 'deptarget',
498 'ext_modules': [deptarget_ext] 466 'ext_modules': [deptarget_ext]
499 }) 467 })
500 dist.package_dir = self.tmp_dir 468 dist.package_dir = self.tmp_dir
(...skipping 20 matching lines...) Expand all
521 src = _get_source_filename() 489 src = _get_source_filename()
522 if not os.path.exists(src): 490 if not os.path.exists(src):
523 if support.verbose: 491 if support.verbose:
524 print('test_build_ext: Cannot find source code (test' 492 print('test_build_ext: Cannot find source code (test'
525 ' must run in python build dir)') 493 ' must run in python build dir)')
526 return unittest.TestSuite() 494 return unittest.TestSuite()
527 else: return unittest.makeSuite(BuildExtTestCase) 495 else: return unittest.makeSuite(BuildExtTestCase)
528 496
529 if __name__ == '__main__': 497 if __name__ == '__main__':
530 support.run_unittest(test_suite()) 498 support.run_unittest(test_suite())
OLDNEW
« no previous file with comments | « Lib/distutils/sysconfig.py ('k') | Lib/distutils/tests/test_build_py.py » ('j') | no next file with comments »

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