1import sys 2import distutils.command.build_ext as orig 3from distutils.sysconfig import get_config_var 4 5from setuptools.extern import six 6 7from setuptools.command.build_ext import build_ext, get_abi3_suffix 8from setuptools.dist import Distribution 9from setuptools.extension import Extension 10 11 12class TestBuildExt: 13 def test_get_ext_filename(self): 14 """ 15 Setuptools needs to give back the same 16 result as distutils, even if the fullname 17 is not in ext_map. 18 """ 19 dist = Distribution() 20 cmd = build_ext(dist) 21 cmd.ext_map['foo/bar'] = '' 22 res = cmd.get_ext_filename('foo') 23 wanted = orig.build_ext.get_ext_filename(cmd, 'foo') 24 assert res == wanted 25 26 def test_abi3_filename(self): 27 """ 28 Filename needs to be loadable by several versions 29 of Python 3 if 'is_abi3' is truthy on Extension() 30 """ 31 print(get_abi3_suffix()) 32 33 extension = Extension('spam.eggs', ['eggs.c'], py_limited_api=True) 34 dist = Distribution(dict(ext_modules=[extension])) 35 cmd = build_ext(dist) 36 cmd.finalize_options() 37 assert 'spam.eggs' in cmd.ext_map 38 res = cmd.get_ext_filename('spam.eggs') 39 40 if six.PY2 or not get_abi3_suffix(): 41 assert res.endswith(get_config_var('SO')) 42 elif sys.platform == 'win32': 43 assert res.endswith('eggs.pyd') 44 else: 45 assert 'abi3' in res 46