HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/twisted/application/twist/test/__pycache__/test_options.cpython-38.pyc
U


W[�*�@s�dZddlmZmZddlmZddlmZddlm	Z	ddl
mZmZm
Z
ddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlZGdd�dejjj�Z dS)z2
Tests for L{twisted.application.twist._options}.
�)�stdout�stderr)�reactor)�version)�
UsageError)�LogLevel�textFileLogObserver�jsonFileLogObserver)�
MemoryReactor�)�
NoSuchReactor)�ServiceMaker)�
ExitStatus)�	DummyExit)�_options�)�TwistOptionsNc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:S);�OptionsTestsz$
    Tests for L{TwistOptions}.
    cCst�|_|�td|j�dS)zX
        Patch L{_twist.exit} so we can capture usage and prevent actual exits.
        �exitN)rr�patchr��self�r�M/usr/lib/python3/dist-packages/twisted/application/twist/test/test_options.py�	patchExitszOptionsTests.patchExitcs&g�_d�fdd�	}��td|�dS)zZ
        Patch L{_options.open} so we can capture usage and prevent actual opens.
        Ncs(|dkrtdd|���j�||f�tS)N�	nocanopen)�IOError�opened�append�NotImplemented)�name�moderrr�fakeOpen-sz(OptionsTests.patchOpen.<locals>.fakeOpenZopenFile)N)rrr)rr"rrr�	patchOpen'szOptionsTests.patchOpencs$i�_�fdd�}��td|�dS)zo
        Patch C{_options.installReactor} so we can capture usage and prevent
        actual installs.
        cs"|dkrt��t�}|�j|<|S)N�fusion)rr
�installedReactors)r rrrr�installReactor>s

z8OptionsTests.patchInstallReactor.<locals>.installReactorr&N)r%rr)rr&rrr�patchInstallReactor7sz OptionsTests.patchInstallReactorcCst�}|�|���d��dS)z@
        L{TwistOptions.getSynopsis} appends arguments.
        z plugin [plugin_options]N)r�
assertTrueZgetSynopsis�endswith�r�optionsrrr�
test_synopsisIs�zOptionsTests.test_synopsiscCs<|��t�}|��|�|jjtj�|�|jjt	�dS)zl
        L{TwistOptions.opt_version} exits with L{ExitStatus.EX_OK} and prints
        the version.
        N)
rrZopt_version�assertEqualsr�statusr�EX_OK�messagerr*rrr�test_versionTs
zOptionsTests.test_versioncCsD|��t�}|�d�|�t|j�tdg��|�|dd�dS)zo
        L{TwistOptions.installReactor} installs the chosen reactor and sets
        the reactor name.
        r$ZreactorNameN)r'r�opt_reactor�assertEqual�setr%r-r*rrr�test_reactorbs

zOptionsTests.test_reactorcCs<|��t�}d|_|�dg�|�t|j�tdg��dS)z�
        L{TwistOptions.installReactor} installs the chosen reactor after the
        command line options have been parsed.
        ztest-subcommandz--reactor=fusionr$N)r'rZ
subCommandZparseOptionsr3r4r%r*rrr�test_installCorrectReactorps
z'OptionsTests.test_installCorrectReactorcCs"|��t�}|�t|jd�dS)zn
        L{TwistOptions.installReactor} raises UsageError if an unknown reactor
        is specified.
        ZcoalN)r'r�assertRaisesrr2r*rrr�test_installReactorBogus~sz%OptionsTests.test_installReactorBoguscCst�}|�t|�d��dS)z�
        L{TwistOptions.installReactor} returns the currently installed reactor
        when the default reactor name is specified.
        �defaultN)r�assertIdenticalrr&r*rrr�test_installReactorDefault�sz'OptionsTests.test_installReactorDefaultcCs&t�}|�d�|�|dtj�dS)zQ
        L{TwistOptions.opt_log_level} sets the corresponding log level.
        �warnZlogLevelN)r�
opt_log_levelr:rr<r*rrr�test_logLevelValid�s
zOptionsTests.test_logLevelValidcCst�}|�t|jd�dS)zi
        L{TwistOptions.opt_log_level} with an invalid log level name raises
        UsageError.
        ZcheeseN)rr7rr=r*rrr�test_logLevelInvalid�sz!OptionsTests.test_logLevelInvalidcCs$t�}|�|�|�|d|�dS)z�
        Set log file name and check the selected output stream.

        @param name: The name of the file.
        @param expectedStream: The expected stream.
        ZlogFileN)r�opt_log_filer:)rr ZexpectedStreamr+rrr�_testLogFile�s
zOptionsTests._testLogFilecCs|�dt�dS)zW
        L{TwistOptions.opt_log_file} given C{"-"} as a file name uses stdout.
        �-N)rArrrrr�test_logFileStdout�szOptionsTests.test_logFileStdoutcCs|�dt�dS)zW
        L{TwistOptions.opt_log_file} given C{"+"} as a file name uses stderr.
        �+N)rArrrrr�test_logFileStderr�szOptionsTests.test_logFileStderrcCs,|��t�}|�d�|�dg|j�dS)zX
        L{TwistOptions.opt_log_file} opens the given file name in append mode.
        �mylog)rF�aN)r#rr@r3rr*rrr�test_logFileNamed�s
zOptionsTests.test_logFileNamedcCsJ|��|��t�}|�d�|�|jjtj�|�	|jj
�d��dS)z�
        L{TwistOptions.opt_log_file} exits with L{ExitStatus.EX_IOERR} if
        unable to open the log file due to an L{EnvironmentError}.
        rz%Unable to open log file 'nocanopen': N)rr#rr@r-rr.r�EX_IOERRr(r0�
startswithr*rrr�test_logFileCantOpen�s
��z!OptionsTests.test_logFileCantOpencCs4t�}|�|�|�|d|�|�|d|�dS)z�
        Set log file format and check the selected observer.

        @param format: The format of the file.
        @param expectedObserver: The expected observer.
        �fileLogObserverFactory�	logFormatN)r�opt_log_formatr:r3)r�formatZexpectedObserverr+rrr�_testLogFormat�s
�zOptionsTests._testLogFormatcCs|�dt�dS)�g
        L{TwistOptions.opt_log_format} given C{"text"} uses a
        L{textFileLogObserver}.
        �textN)rPrrrrr�test_logFormatText�szOptionsTests.test_logFormatTextcCs|�dt�dS)rQ�jsonN)rPr	rrrr�test_logFormatJSON�szOptionsTests.test_logFormatJSONcCst�}|�t|jd�dS)zk
        L{TwistOptions.opt_log_format} given an invalid format name raises
        L{UsageError}.
        ZfrommageN)rr7rrNr*rrr�test_logFormatInvalidsz"OptionsTests.test_logFormatInvalidcCsN|��t�}|�d�|�d�|��|�|dt�|�|dd�dS)�r
        L{TwistOptions.selectDefaultLogObserver} will not override an already
        selected observer.
        rR�quesorLrMN)r#rrNr@�selectDefaultLogObserverr:rr3r*rrr�'test_selectDefaultLogObserverNoOverride
s

�z4OptionsTests.test_selectDefaultLogObserverNoOverridecCs\Gdd�dt�}|�td|��t�}|�d�|��|�|dt�|�|dd�dS)	rWc@seZdZdd�ZdS)zIOptionsTests.test_selectDefaultLogObserverDefaultWithTTY.<locals>.TTYFilecSsdS)NTrrrrr�isatty$szPOptionsTests.test_selectDefaultLogObserverDefaultWithTTY.<locals>.TTYFile.isattyN)�__name__�
__module__�__qualname__r[rrrr�TTYFile#sr_rrBrLrMrRN)	�objectrrrr@rYr:rr3)rr_r+rrr�+test_selectDefaultLogObserverDefaultWithTTYs
�z8OptionsTests.test_selectDefaultLogObserverDefaultWithTTYcCsD|��t�}|�d�|��|�|dt�|�|dd�dS)rWrXrLrMrTN)r#rr@rYr:r	r3r*rrr�.test_selectDefaultLogObserverDefaultWithoutTTY4s
�z;OptionsTests.test_selectDefaultLogObserverDefaultWithoutTTYcCs6t�}|j}|D] }|�|t�|�||t�qdS)zM
        L{TwistOptions.plugins} is a mapping of available plug-ins.
        N)r�plugins�assertIsInstance�strr
)rr+rcr rrr�test_pluginsTypeEs
zOptionsTests.test_pluginsTypecCst�}|�d|j�dS)z�
        L{TwistOptions.plugins} includes a C{"web"} plug-in.
        This is an attempt to verify that something we expect to be in the list
        is in there without enumerating all of the built-in plug-ins.
        ZwebN)rZassertInrcr*rrr�test_pluginsIncludeWebQsz#OptionsTests.test_pluginsIncludeWebcCsPt�}|jD]>\}}}}|�|t�|�|d�|�t|��|�|t�qdS)z~
        L{TwistOptions.subCommands} is an iterable of tuples as expected by
        L{twisted.python.usage.Options}.
        N)r�subCommandsrdrer:r(�callable)rr+r �shortcut�parser�docrrr�test_subCommandsType\sz!OptionsTests.test_subCommandsTypecCs4t�}t|j�}tdd�|jD��}|�||�dS)zW
        L{TwistOptions.subCommands} includes a sub-command for every plug-in.
        css|]\}}}}|VqdS)Nr)�.0r rjrkrlrrr�	<genexpr>qs
z:OptionsTests.test_subCommandsIncludeWeb.<locals>.<genexpr>N)rr4rcrhr3)rr+rcrhrrr�test_subCommandsIncludeWebjs
�z'OptionsTests.test_subCommandsIncludeWebcCs |��t�}|�t|j�dS)zd
        L{TwistOptions.postOptions} raises L{UsageError} is it has no
        sub-command.
        N)r'rr7rZpostOptionsr*rrr�test_postOptionsNoSubCommandxsz)OptionsTests.test_postOptionsNoSubCommandN) r\r]r^�__doc__rr#r'r,r1r5r6r8r;r>r?rArCrErHrKrPrSrUrVrZrarbrfrgrmrprqrrrrrs:	



r)!rr�sysrrZtwisted.internetrZtwisted.copyrightrZtwisted.python.usagerZtwisted.loggerrrr	Ztwisted.test.proto_helpersr
Zreactorsr�servicer
Zrunner._exitrZrunner.test.test_runnerrZtwistrrZtwisted.trial.unittestZtwistedZtrialZunittestZTestCaserrrrr�<module>s