%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/application/twist/test/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/application/twist/test/__pycache__/test_options.cpython-312.pyc

�

Ϫ�f�,��.�dZddlmZmZddlmZmZmZmZm	Z	m
Z
ddlZddl
mZddlmZddlmZddlmZdd	lmZmZmZmZdd
lmZddlmZdd
lmZddl m!Z!ddl"m#Z#ddl$m%Z%ddl%m&Z&Gd�dejNjPjR�Z*y)z2
Tests for L{twisted.application.twist._options}.
�)�stderr�stdout)�Callable�Dict�List�Optional�TextIO�TupleN)�version)�reactor)�IReactorCore)�
MemoryReactor)�FileLogObserver�LogLevel�jsonFileLogObserver�textFileLogObserver)�
UsageError�)�
NoSuchReactor)�
ExitStatus)�	DummyExit)�ServiceMaker)�_options�)�TwistOptionsc��eZdZdZd$d�Zd$d�Zd$d�Zd$d�Zd$d�Zd$d	�Z	d$d
�Z
d$d�Zd$d�Zd$d
�Z
d$d�Zdededdfd�Zd$d�Zd$d�Zd$d�Zd$d�Zdedeegefddfd�Zd$d�Zd$d�Zd$d�Zd$d�Zd$d�Zd$d�Zd$d�Zd$d �Z d$d!�Z!d$d"�Z"d$d#�Z#y)%�OptionsTestsz$
    Tests for L{TwistOptions}.
    �returnNc�d�t�|_|jtd|j�y)zX
        Patch L{_twist.exit} so we can capture usage and prevent actual exits.
        �exitN)rr �patchr��selfs �M/usr/lib/python3/dist-packages/twisted/application/twist/test/test_options.py�	patchExitzOptionsTests.patchExit$s!���K��	��
�
�8�V�T�Y�Y�/�c���g�_ddtdttdtf�fd�
}�j	t
d|�y)zZ
        Patch L{_options.open} so we can capture usage and prevent actual opens.
        N�name�moderc�n��|dk(r
tdd|���jj||f�tS)N�	nocanopen)�OSError�opened�append�NotImplemented)r(r)r#s  �r$�fakeOpenz(OptionsTests.patchOpen.<locals>.fakeOpen1s6����{�"��d�D�$�/�/��K�K����d�|�,�!�!r&�openFile)N)r-�strrr	r!r)r#r0s` r$�	patchOpenzOptionsTests.patchOpen+s<���8:���	"�3�	"�h�s�m�	"�v�	"�	
�
�
�8�Z��2r&c�f��i�_dtdtf�fd�}�jtd|�y)zo
        Patch C{_options.installReactor} so we can capture usage and prevent
        actual installs.
        r(rc�X��|dk7r
t��t�}|�j|<|S)N�fusion)rr�installedReactors)r(rr#s  �r$�installReactorz8OptionsTests.patchInstallReactor.<locals>.installReactorAs/����x��#�o�%�#�o�G�+2�D�"�"�4�(��Nr&r8N)r7r2r
r!r)r#r8s` r$�patchInstallReactorz OptionsTests.patchInstallReactor:s3���
;=���	��	��	�	
�
�
�8�-�~�>r&c�t�t�}|j|j�jd��y)z@
        L{TwistOptions.getSynopsis} appends arguments.
        z plugin [plugin_options]N)r�
assertTrue�getSynopsis�endswith�r#�optionss  r$�
test_synopsiszOptionsTests.test_synopsisKs,���.������+�+�-�6�6�7Q�R�Sr&c��|j�t�}|j�|j|jj
tj�|j|jjt�y)zl
        L{TwistOptions.opt_version} exits with L{ExitStatus.EX_OK} and prints
        the version.
        N)
r%r�opt_version�assertEqualsr �statusr�EX_OK�messagerr>s  r$�test_versionzOptionsTests.test_versionSs[��
	
�����.���������$�)�)�*�*�J�,<�,<�=����$�)�)�+�+�W�5r&c���|j�t�}|jd�|jt	|j
�dh�|j
|dd�y)zo
        L{TwistOptions.installReactor} installs the chosen reactor and sets
        the reactor name.
        r6�reactorNameN)r9r�opt_reactor�assertEqual�setr7rCr>s  r$�test_reactorzOptionsTests.test_reactor`sW��
	
� � �"��.�����H�%�����T�3�3�4�x�j�A����'�-�0�(�;r&c��|j�t�}d|_|jdg�|j	t|j�dh�y)z�
        L{TwistOptions.installReactor} installs the chosen reactor after the
        command line options have been parsed.
        ztest-subcommandz--reactor=fusionr6N)r9r�
subCommand�parseOptionsrKrLr7r>s  r$�test_installCorrectReactorz'OptionsTests.test_installCorrectReactormsN��
	
� � �"��.��.������0�1�2�����T�3�3�4�x�j�Ar&c�z�|j�t�}|jt|jd�y)zn
        L{TwistOptions.installReactor} raises UsageError if an unknown reactor
        is specified.
        �coalN)r9r�assertRaisesrrJr>s  r$�test_installReactorBogusz%OptionsTests.test_installReactorBoguszs/��
	
� � �"��.�����*�g�&9�&9�6�Br&c�b�t�}|jt|jd��y)z�
        L{TwistOptions.installReactor} returns the currently installed reactor
        when the default reactor name is specified.
        �defaultN)r�assertIdenticalrr8r>s  r$�test_installReactorDefaultz'OptionsTests.test_installReactorDefault�s&��
�.�����W�g�&<�&<�Y�&G�Hr&c��t�}|jd�|j|dtj�y)zQ
        L{TwistOptions.opt_log_level} sets the corresponding log level.
        �warn�logLevelN)r�
opt_log_levelrXrr[r>s  r$�test_logLevelValidzOptionsTests.test_logLevelValid�s2���.�����f�%����W�Z�0�(�-�-�@r&c�Z�t�}|jt|jd�y)zi
        L{TwistOptions.opt_log_level} with an invalid log level name raises
        UsageError.
        �cheeseN)rrTrr]r>s  r$�test_logLevelInvalidz!OptionsTests.test_logLevelInvalid�s#��
�.�����*�g�&;�&;�X�Fr&r(�expectedStreamc�d�t�}|j|�|j|d|�y)z�
        Set log file name and check the selected output stream.

        @param name: The name of the file.
        @param expectedStream: The expected stream.
        �logFileN)r�opt_log_filerX)r#r(rbr?s    r$�_testLogFilezOptionsTests._testLogFile�s.���.�����T�"����W�Y�/��@r&c�0�|jdt�y)zW
        L{TwistOptions.opt_log_file} given C{"-"} as a file name uses stdout.
        �-N)rfrr"s r$�test_logFileStdoutzOptionsTests.test_logFileStdout����	
���#�v�&r&c�0�|jdt�y)zW
        L{TwistOptions.opt_log_file} given C{"+"} as a file name uses stderr.
        �+N)rfrr"s r$�test_logFileStderrzOptionsTests.test_logFileStderr�rjr&c��|j�t�}|jd�|jdg|j�y)zX
        L{TwistOptions.opt_log_file} opens the given file name in append mode.
        �mylog)ro�aN)r3rrerKr-r>s  r$�test_logFileNamedzOptionsTests.test_logFileNamed�s:��	
�����.�����W�%����.�)�4�;�;�7r&c��|j�|j�t�}|jd�|j	|j
jtj�|j|j
j�|j|j
jjd��y)z�
        L{TwistOptions.opt_log_file} exits with L{ExitStatus.EX_IOERR} if
        unable to open the log file due to an L{EnvironmentError}.
        r+z%Unable to open log file 'nocanopen': N)
r%r3rrerCr rDr�EX_IOERR�assertIsNotNonerFr;�
startswithr>s  r$�test_logFileCantOpenz!OptionsTests.test_logFileCantOpen�s���
	
���������.�����[�)����$�)�)�*�*�J�,?�,?�@����T�Y�Y�.�.�/�����I�I���(�(�7�
�	
r&�format�expectedObserverFactoryc��t�}|j|�|j|d|�|j|d|�y)z�
        Set log file format and check the selected observer factory.

        @param format: The format of the file.
        @param expectedObserverFactory: The expected observer factory.
        �fileLogObserverFactory�	logFormatN)r�opt_log_formatrXrK)r#rwrxr?s    r$�_testLogFormatzOptionsTests._testLogFormat�sE���.�����v�&����W�%=�>�@W�X������-�v�6r&c�0�|jdt�y)�g
        L{TwistOptions.opt_log_format} given C{"text"} uses a
        L{textFileLogObserver}.
        �textN)r}rr"s r$�test_logFormatTextzOptionsTests.test_logFormatText����
	
���F�$7�8r&c�0�|jdt�y)r�jsonN)r}rr"s r$�test_logFormatJSONzOptionsTests.test_logFormatJSON�r�r&c�Z�t�}|jt|jd�y)zk
        L{TwistOptions.opt_log_format} given an invalid format name raises
        L{UsageError}.
        �frommageN)rrTrr|r>s  r$�test_logFormatInvalidz"OptionsTests.test_logFormatInvalid�s#��
�.�����*�g�&<�&<�j�Ir&c��|j�t�}|jd�|jd�|j	�|j|dt�|j|dd�y)�r
        L{TwistOptions.selectDefaultLogObserver} will not override an already
        selected observer.
        r��quesorzr{N)r3rr|re�selectDefaultLogObserverrXrrKr>s  r$�'test_selectDefaultLogObserverNoOverridez4OptionsTests.test_selectDefaultLogObserverNoOverride�sk��
	
�����.�����v�&����W�%��(�(�*�	
���W�%=�>�@S�T������-�v�6r&c��Gd�d�}|jtd|��t�}|jd�|j	�|j|dt�|j|dd�y)	r�c��eZdZdefd�Zy)�IOptionsTests.test_selectDefaultLogObserverDefaultWithTTY.<locals>.TTYFilerc��y)NT�r"s r$�isattyzPOptionsTests.test_selectDefaultLogObserverDefaultWithTTY.<locals>.TTYFile.isattys��r&N)�__name__�
__module__�__qualname__�boolr�r�r&r$�TTYFiler�s��
��
r&r�rrhrzr{r�N)r!rrrer�rXrrK)r#r�r?s   r$�+test_selectDefaultLogObserverDefaultWithTTYz8OptionsTests.test_selectDefaultLogObserverDefaultWithTTYsm��	�	�
	
�
�
�8�X�w�y�1��.�����S�!��(�(�*����W�%=�>�@S�T������-�v�6r&c���|j�t�}|jd�|j�|j	|dt
�|j
|dd�y)r�r�rzr{r�N)r3rrer�rXrrKr>s  r$�.test_selectDefaultLogObserverDefaultWithoutTTYz;OptionsTests.test_selectDefaultLogObserverDefaultWithoutTTYs[��
	
�����.�����W�%��(�(�*����W�%=�>�@S�T������-�v�6r&c��t�}|j}|D]1}|j|t�|j||t��3y)zM
        L{TwistOptions.plugins} is a mapping of available plug-ins.
        N)r�plugins�assertIsInstancer2r)r#r?r�r(s    r$�test_pluginsTypezOptionsTests.test_pluginsType-sG���.���/�/���	?�D��!�!�$��,��!�!�'�$�-��>�	?r&c�P�t�}|jd|j�y)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.
        �webN)r�assertInr�r>s  r$�test_pluginsIncludeWebz#OptionsTests.test_pluginsIncludeWeb8s���.���
�
�e�W�_�_�-r&c���t�}|jD]_\}}}}|j|t�|j	|d�|jt
|��|j|t��ay)z~
        L{TwistOptions.subCommands} is an iterable of tuples as expected by
        L{twisted.python.usage.Options}.
        N)r�subCommandsr�r2rXr;�callable)r#r?r(�shortcut�parser�docs      r$�test_subCommandsTypez!OptionsTests.test_subCommandsTypeBsj��
�.��+2�+>�+>�	,�'�D�(�F�C��!�!�$��,�� � ��4�0��O�O�H�V�,�-��!�!�#�s�+�		,r&c
��t�}t|j�}|jD����chc]	\}}}}|��}}}}}|j	||�ycc}}}}w)zW
        L{TwistOptions.subCommands} includes a sub-command for every plug-in.
        N)rrLr�r�rK)r#r?r�r(r�r�r�r�s        r$�test_subCommandsIncludeWebz'OptionsTests.test_subCommandsIncludeWebOsT���.���g�o�o�&��?F�?R�?R�S�S� ;��h���t�S��S�����g�.��Ts�A
c�x�|j�t�}|jt|j�y)zd
        L{TwistOptions.postOptions} raises L{UsageError} is it has no
        sub-command.
        N)r9rrTr�postOptionsr>s  r$�test_postOptionsNoSubCommandz)OptionsTests.test_postOptionsNoSubCommandZs-��
	
� � �"��.�����*�g�&9�&9�:r&)rN)$r�r�r��__doc__r%r3r9r@rGrMrQrUrYr^rar2r	rfrirmrqrvrrr}r�r�r�r�r�r�r�r�r�r�r�r�r&r$rrs����0�
3�?�"T�6�<�B�C�I�A�G�
A��
A�f�
A��
A�'�'�	8�
�&
7��
7�4<�f�X��=V�4W�
7�	
�
7�9�9�J�7�"7�(7�	?�.�,�	/�	;r&r)+r��sysrr�typingrrrrr	r
�twisted.trial.unittest�twisted�twisted.copyrightr�twisted.internetr�twisted.internet.interfacesr
�twisted.internet.testingr�twisted.loggerrrrr�twisted.python.usager�reactorsr�runner._exitr�runner.test.test_runnerr�servicer�twistrr�trial�unittest�TestCaserr�r&r$�<module>r�sc����@�@��%�$�4�2���,�%�&�0�#��#�D;�7�=�=�)�)�2�2�D;r&

Zerion Mini Shell 1.0