Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6840721

Browse files
author
Tarek Ziadé
committed
Merged revisions 73170 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r73170 | tarek.ziade | 2009-06-03 13:12:08 +0200 (Wed, 03 Jun 2009) | 1 line more cleanup and test coverage for distutils.extension ........
1 parent e6ed2f9 commit 6840721

2 files changed

Lines changed: 42 additions & 15 deletions

File tree

Lib/distutils/extension.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55

66
__revision__ = "$Id$"
77

8-
import os, sys
9-
10-
try:
11-
import warnings
12-
except ImportError:
13-
warnings = None
8+
import os
9+
import sys
10+
import warnings
1411

1512
# This class is really only used by the "build_ext" command, so it might
1613
# make sense to put it in distutils.command.build_ext. However, that
@@ -129,14 +126,11 @@ def __init__(self, name, sources,
129126
self.optional = optional
130127

131128
# If there are unknown keyword options, warn about them
132-
if len(kw):
133-
L = map(repr, sorted(kw))
134-
msg = "Unknown Extension options: " + ', '.join(L)
135-
if warnings is not None:
136-
warnings.warn(msg)
137-
else:
138-
sys.stderr.write(msg + '\n')
139-
129+
if len(kw) > 0:
130+
options = [repr(option) for option in kw]
131+
options = ', '.join(sorted(options))
132+
msg = "Unknown Extension options: %s" % options
133+
warnings.warn(msg)
140134

141135
def read_setup_file(filename):
142136
"""Reads a Setup file and returns Extension instances."""

Lib/distutils/tests/test_extension.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
"""Tests for distutils.extension."""
22
import unittest
33
import os
4+
import warnings
45

5-
from distutils.extension import read_setup_file
6+
from test.support import check_warnings
7+
from distutils.extension import read_setup_file, Extension
68

79
class ExtensionTestCase(unittest.TestCase):
810

@@ -28,6 +30,37 @@ def test_read_setup_file(self):
2830

2931
self.assertEquals(names, wanted)
3032

33+
def test_extension_init(self):
34+
# the first argument, which is the name, must be a string
35+
self.assertRaises(AssertionError, Extension, 1, [])
36+
ext = Extension('name', [])
37+
self.assertEquals(ext.name, 'name')
38+
39+
# the second argument, which is the list of files, must
40+
# be a list of strings
41+
self.assertRaises(AssertionError, Extension, 'name', 'file')
42+
self.assertRaises(AssertionError, Extension, 'name', ['file', 1])
43+
ext = Extension('name', ['file1', 'file2'])
44+
self.assertEquals(ext.sources, ['file1', 'file2'])
45+
46+
# others arguments have defaults
47+
for attr in ('include_dirs', 'define_macros', 'undef_macros',
48+
'library_dirs', 'libraries', 'runtime_library_dirs',
49+
'extra_objects', 'extra_compile_args', 'extra_link_args',
50+
'export_symbols', 'swig_opts', 'depends'):
51+
self.assertEquals(getattr(ext, attr), [])
52+
53+
self.assertEquals(ext.language, None)
54+
self.assertEquals(ext.optional, None)
55+
56+
# if there are unknown keyword options, warn about them
57+
with check_warnings() as w:
58+
warnings.simplefilter('always')
59+
ext = Extension('name', ['file1', 'file2'], chic=True)
60+
61+
self.assertEquals(len(w.warnings), 1)
62+
self.assertEquals(str(w.warnings[0].message),
63+
"Unknown Extension options: 'chic'")
3164

3265
def test_suite():
3366
return unittest.makeSuite(ExtensionTestCase)

0 commit comments

Comments
 (0)