codekingpro/portable-devtools
114k
1import platform2import sysconfig3import textwrap4 5import pytest6 7from .. import base8 9pytestmark = pytest.mark.usefixtures('suppress_path_mangle')10 11 12@pytest.fixture13def c_file(tmp_path):14 c_file = tmp_path / 'foo.c'15 gen_headers = ('Python.h',)16 is_windows = platform.system() == "Windows"17 plat_headers = ('windows.h',) * is_windows18 all_headers = gen_headers + plat_headers19 headers = '\n'.join(f'#include <{header}>\n' for header in all_headers)20 payload = (21 textwrap.dedent(22 """23 #headers24 void PyInit_foo(void) {}25 """26 )27 .lstrip()28 .replace('#headers', headers)29 )30 c_file.write_text(payload, encoding='utf-8')31 return c_file32 33 34def test_set_include_dirs(c_file):35 """36 Extensions should build even if set_include_dirs is invoked.37 In particular, compiler-specific paths should not be overridden.38 """39 compiler = base.new_compiler()40 python = sysconfig.get_paths()['include']41 compiler.set_include_dirs([python])42 compiler.compile([c_file])43 44 # do it again, setting include dirs after any initialization45 compiler.set_include_dirs([python])46 compiler.compile([c_file])47 48 49def test_has_function_prototype():50 # Issue https://github.com/pypa/setuptools/issues/364851 # Test prototype-generating behavior.52 53 compiler = base.new_compiler()54 55 # Every C implementation should have these.56 assert compiler.has_function('abort')57 assert compiler.has_function('exit')58 with pytest.deprecated_call(match='includes is deprecated'):59 # abort() is a valid expression with the <stdlib.h> prototype.60 assert compiler.has_function('abort', includes=['stdlib.h'])61 with pytest.deprecated_call(match='includes is deprecated'):62 # But exit() is not valid with the actual prototype in scope.63 assert not compiler.has_function('exit', includes=['stdlib.h'])64 # And setuptools_does_not_exist is not declared or defined at all.65 assert not compiler.has_function('setuptools_does_not_exist')66 with pytest.deprecated_call(match='includes is deprecated'):67 assert not compiler.has_function(68 'setuptools_does_not_exist', includes=['stdio.h']69 )70 71 72def test_include_dirs_after_multiple_compile_calls(c_file):73 """74 Calling compile multiple times should not change the include dirs75 (regression test for setuptools issue #3591).76 """77 compiler = base.new_compiler()78 python = sysconfig.get_paths()['include']79 compiler.set_include_dirs([python])80 compiler.compile([c_file])81 assert compiler.include_dirs == [python]82 compiler.compile([c_file])83 assert compiler.include_dirs == [python]84 