HEX
Server: LiteSpeed
System: Linux atali.colombiahosting.com.co 5.14.0-570.12.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Tue May 13 06:11:55 EDT 2025 x86_64
User: coopserp (1713)
PHP: 8.2.29
Disabled: dl,exec,passthru,proc_open,proc_close,shell_exec,memory_limit,system,popen,curl_multi_exec,show_source,symlink,link,leak,listen,diskfreespace,tmpfile,ignore_user_abord,highlight_file,source,show_source,fpaththru,virtual,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setid,posix_times,posix_ttyname,posix_uname,proc_get_status,proc_nice,proc_terminate
Upload Files
File: //opt/cloudlinux/venv/lib/python3.11/site-packages/setuptools/tests/test_build_clib.py
import random
from unittest import mock

import pytest

from setuptools.command.build_clib import build_clib
from setuptools.dist import Distribution

from distutils.errors import DistutilsSetupError


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

    @mock.patch('setuptools.command.build_clib.newer_pairwise_group')
    def test_build_libraries_reproducible(self, mock_newer):
        dist = Distribution()
        cmd = build_clib(dist)

        # 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 = ([], [])

        original_sources = ['a-example.c', 'example.c']
        sources = original_sources

        obj_deps = {'': ('global.h',), 'example.c': ('example.h',)}
        libs = [('example', {'sources': sources, 'obj_deps': obj_deps})]

        cmd.build_libraries(libs)
        computed_call_args = mock_newer.call_args[0]

        while sources == original_sources:
            sources = random.sample(original_sources, len(original_sources))
        libs = [('example', {'sources': sources, 'obj_deps': obj_deps})]

        cmd.build_libraries(libs)
        assert computed_call_args == mock_newer.call_args[0]