diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2021-11-10 12:12:49 -0500 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2021-11-10 12:13:40 -0500 |
| commit | 958ce2304e153b274e2ff7b40b1e7d5ddd214904 (patch) | |
| tree | bb1b77cfc08c31fb69eebdb0c66f5c0dde3f5223 /setuptools/tests/test_build_clib.py | |
| parent | 23f63dd44c5d9f75de195833d25a5f2872220c2b (diff) | |
| parent | 8af23a41194ae747faf3e60f9cc19141b5e7ad24 (diff) | |
| download | python-setuptools-git-958ce2304e153b274e2ff7b40b1e7d5ddd214904.tar.gz | |
Merge pull request #2866 into main.
Diffstat (limited to 'setuptools/tests/test_build_clib.py')
| -rw-r--r-- | setuptools/tests/test_build_clib.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/setuptools/tests/test_build_clib.py b/setuptools/tests/test_build_clib.py new file mode 100644 index 00000000..48bea2b4 --- /dev/null +++ b/setuptools/tests/test_build_clib.py @@ -0,0 +1,57 @@ +import pytest + +import mock +from distutils.errors import DistutilsSetupError +from setuptools.command.build_clib import build_clib +from setuptools.dist import Distribution + + +class TestBuildCLib: + @mock.patch( + 'setuptools.command.build_clib.newer_pairwise_group') + def test_build_libraries(self, mock_newer): + dist = Distribution() + cmd = build_clib(dist) + + # this will be a long section, just making sure all + # exceptions are properly raised + libs = [('example', {'sources': 'broken.c'})] + with pytest.raises(DistutilsSetupError): + cmd.build_libraries(libs) + + obj_deps = 'some_string' + libs = [('example', {'sources': ['source.c'], 'obj_deps': obj_deps})] + with pytest.raises(DistutilsSetupError): + cmd.build_libraries(libs) + + obj_deps = {'': ''} + libs = [('example', {'sources': ['source.c'], 'obj_deps': obj_deps})] + with pytest.raises(DistutilsSetupError): + cmd.build_libraries(libs) + + obj_deps = {'source.c': ''} + libs = [('example', {'sources': ['source.c'], 'obj_deps': obj_deps})] + with pytest.raises(DistutilsSetupError): + cmd.build_libraries(libs) + + # with that out of the way, let's see if the crude dependency + # system works + cmd.compiler = mock.MagicMock(spec=cmd.compiler) + mock_newer.return_value = ([], []) + + obj_deps = {'': ('global.h',), 'example.c': ('example.h',)} + libs = [('example', {'sources': ['example.c'], 'obj_deps': obj_deps})] + + cmd.build_libraries(libs) + assert [['example.c', 'global.h', 'example.h']] in \ + mock_newer.call_args[0] + assert not cmd.compiler.compile.called + assert cmd.compiler.create_static_lib.call_count == 1 + + # reset the call numbers so we can test again + cmd.compiler.reset_mock() + + mock_newer.return_value = '' # anything as long as it's not ([],[]) + cmd.build_libraries(libs) + assert cmd.compiler.compile.call_count == 1 + assert cmd.compiler.create_static_lib.call_count == 1 |
