Uname:Linux mail.sarafai.ru 6.1.0-43-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.162-1 (2026-02-08) x86_64

403WebShell
403Webshell
Server IP : 82.148.16.210  /  Your IP : 216.73.216.19
Web Server : nginx/1.29.5
System : Linux mail.sarafai.ru 6.1.0-43-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.162-1 (2026-02-08) x86_64
User : root ( 0)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /proc/thread-self/root/lib/cloudinit/tests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /proc/thread-self/root/lib/cloudinit/tests/test_conftest.py
import pytest

from cloudinit import subp
from cloudinit.tests.helpers import CiTestCase


class TestDisableSubpUsage:
    """Test that the disable_subp_usage fixture behaves as expected."""

    def test_using_subp_raises_assertion_error(self):
        with pytest.raises(AssertionError):
            subp.subp(["some", "args"])

    def test_typeerrors_on_incorrect_usage(self):
        with pytest.raises(TypeError):
            # We are intentionally passing no value for a parameter, so:
            #  pylint: disable=no-value-for-parameter
            subp.subp()

    @pytest.mark.allow_all_subp
    def test_subp_usage_can_be_reenabled(self):
        subp.subp(['whoami'])

    @pytest.mark.allow_subp_for("whoami")
    def test_subp_usage_can_be_conditionally_reenabled(self):
        # The two parameters test each potential invocation with a single
        # argument
        with pytest.raises(AssertionError) as excinfo:
            subp.subp(["some", "args"])
        assert "allowed: whoami" in str(excinfo.value)
        subp.subp(['whoami'])

    @pytest.mark.allow_subp_for("whoami", "bash")
    def test_subp_usage_can_be_conditionally_reenabled_for_multiple_cmds(self):
        with pytest.raises(AssertionError) as excinfo:
            subp.subp(["some", "args"])
        assert "allowed: whoami,bash" in str(excinfo.value)
        subp.subp(['bash', '-c', 'true'])
        subp.subp(['whoami'])

    @pytest.mark.allow_all_subp
    @pytest.mark.allow_subp_for("bash")
    def test_both_marks_raise_an_error(self):
        with pytest.raises(AssertionError, match="marked both"):
            subp.subp(["bash"])


class TestDisableSubpUsageInTestSubclass(CiTestCase):
    """Test that disable_subp_usage doesn't impact CiTestCase's subp logic."""

    def test_using_subp_raises_exception(self):
        with pytest.raises(Exception):
            subp.subp(["some", "args"])

    def test_typeerrors_on_incorrect_usage(self):
        with pytest.raises(TypeError):
            subp.subp()

    def test_subp_usage_can_be_reenabled(self):
        _old_allowed_subp = self.allow_subp
        self.allowed_subp = True
        try:
            subp.subp(['bash', '-c', 'true'])
        finally:
            self.allowed_subp = _old_allowed_subp

Youez - 2016 - github.com/yon3zu
LinuXploit