Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/python/test/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyc


oUNc@sdZddlZddlmZddlmZddlmZmZm	Z	ddl
mZmZm
Z
ddl
mZdefd	YZd
efdYZdZd
ejfdYZdejfdYZdejfdYZdejfdYZdejfdYZdefdYZdZdejfdYZdejfdYZdejfdYZd efd!YZ d"Z!d#Z"dS($s*
Test cases for twisted.python._shellcomp
iN(tStringIO(tunittest(t
_shellcomptusagetreflect(tCompletionst	Completert
CompleteFiles(tCompleteListtZshScriptTestMetacBseZdZdZRS(s*
    Metaclass of ZshScriptTestMixin.
    cCsfd}d|krPx8|dD])\}}|||}||d|<q Wntj||||S(Ncsfd}|S(Ncst|S(N(ttest_genZshFunction(tself(toptionsFQPNtcmdName(sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pytrunTests((R
RR((RR
sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pytmakeTeststgenerateForttest_genZshFunction_(ttypet__new__(tclstnametbasestattrsRR
Rttest((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyRs	(t__name__t
__module__t__doc__R(((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyR	stZshScriptTestMixincBseZdZeZRS(s
    Integration test helper to show that C{usage.Options} classes can have zsh
    completion functions generated for them without raising errors.

    In your subclasses set a class variable like so:

    #            | cmd name | Fully Qualified Python Name of Options class |
    #
    generateFor = [('conch',  'twisted.conch.scripts.conch.ClientOptions'),
                   ('twistd', 'twisted.scripts.twistd.ServerOptions'),
                   ]

    Each package that contains Twisted scripts should contain one TestCase
    subclass which also inherits from this mixin, and contains a C{generateFor}
    list appropriate for the scripts in that package.
    (RRRR	t
__metaclass__(((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyR'sc
Cst}|jtjd|ytj|}Wn)tk
r`}tjd|fnXy|j	dddgWn8t
k
r}tjd|fntk
rnX|jd|j
d|jd	t|jd	|j
d|jt|d
rx|jD]\}}}}	y|j	|dddgWn8t
k
rx}tjd|fntk
rnX|jd|j
d|jd	t|jd	|j
d|jqWn|jd
S(sI
    Generate completion functions for given twisted command - no errors
    should be raised

    @type cmdName: C{str}
    @param cmdName: The name of the command-line utility e.g. 'twistd'

    @type optionsFQPN: C{str}
    @param optionsFQPN: The Fully Qualified Python Name of the C{Options}
        class to be tested.
    t_shellCompFiles0Couldn't import or instantiate Options class: %sts--_shell-completionszsh:2s&ImportError calling parseOptions(): %ssSystemExit not raisediitsubCommandsszsh:3s4ImportError calling parseOptions() on subcommand: %sN(RtpatchRtOptionsRtnamedAnyt	ExceptionRtSkipTesttparseOptionstImportErrort
SystemExittfailtseektassertEqualtlentreadttruncatethasattrR t
flushWarnings(
RR
Rt
outputFiletotetcmdtshorttparsertdoc((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyR
<sD		




	



tZshTestCasecBseZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZRS(s'
    Tests for zsh completion code
    cCst}tj|dd}tjjj}|jtjj|j|j||j|j	t
tjj	|j|jtjjtjjj}|jtjj|j|j||j|j
tjj
dS(si
        Are `compData' attributes you can place on Options classes
        picked up correctly?
        tacetdummy_valueN(tFighterAceExtendedOptionsRtZshArgumentsGeneratortFighterAceOptionstcompDatatdescriptionstcopytupdateR+tmultiUsetsettmutuallyExclusivet
optActionstextraActions(RtoptstagR?RE((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyttest_accumulateMetadatas	
c
CsdtfdY}|}tj|dd}itddddd	d
dgd6td
ddddd	d
dgd6td
dddd	d
dgd6td
ddddd
dgd	6td
dddddd	gd6}|j|j|dS(s
        Exercise a corner-case of ZshArgumentsGenerator.makeExcludesDict()
        where the long option name already exists in the `excludes` dict being
        built.
        tOddFighterAceOptionscBs;eZdddggZeddddddggZRS(tanatras0Select the Anatra DS as your dogfighter aircraftRDtfokkertalbatrostspadtbristolN(RRtNonetoptFlagsRR>(((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyRJs
	R9R:RKtbROtfRLtsRNRMtaN(R;RR<RCR+texcludes(RRJRGRHtexpected((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyt test_mutuallyExclusiveCornerCases
	cCsnt}tj|dd}|jd|j|jd|j|jd|j|jd|jdS(s
        We pick up options that are only defined by having an
        appropriately named method on your Options class,
        e.g. def opt_foo(self, foo)
        R9R:tnocrasht
difficultyN(R;RR<tassertIntflagNameToDefinitiontallOptionsNameToDefinitiontparamNameToDefinition(RRGRH((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyt test_accumulateAdditionalOptionss	cCsndtfdY}|jttj|dddtfdY}|jttj|dddS(s\
        Using a parameter/flag name that doesn't exist
        will raise an error
        t
TmpOptionscBseZedidd6ZRS(REtdetaillN(RRRRPR>(((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyR`sR9R:tTmpOptions2cBseZeddgZRS(RDtfootbar(RcRd(RRRR>(((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyRbsN(R;tassertRaisest
ValueErrorRR<(RR`Rb((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyttest_verifyZshNamesscCstt}|jtjd||jtdddddgt}|jt|j|j	t
|jdS(st
        Generate a completion function, and test the textual output
        against a known correct output
        RtargvtsillyRs--_shell-completionszsh:2N(RR!RR"tsystSimpleProgOptionsReR(R&R+ttestOutput1tgetvalue(RR1RG((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyttest_zshCodes		cCstt}|jtjd||jtdddddgt}|jt|j|j	t
|jdS(s
        Generate a completion function with subcommands,
        and test the textual output against a known correct output
        RRhtsilly2Rs--_shell-completionszsh:2N(RR!RR"RjtSimpleProgWithSubcommandsReR(R&R+ttestOutput2Rm(RR1RG((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyttest_zshCodeWithSubss		c	Cst}|jtjd|t}|jt|jddddddg|jd|j	d	t
|jd	d
S(sx
        Completion still happens even if a command-line is given
        that would normally throw UsageError.
        Rs--fokkertservers--unknown-options--unknown-option2s--_shell-completionszsh:5iiN(RR!RR"R=ReR(R&R*R+R,R-(RR1RG((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyttest_incompleteCommandLines			

c	Cst}|jtjd|t}|jt|jddddddg|jd|j	d	t
|jd	|jd|jd
S(s
        Completion still happens even if a command-line is given
        that would normally throw UsageError.

        The existance of --unknown-option prior to the subcommand
        will break subcommand detection... but we complete anyway
        Rs--fokkers--unknown-optionRss
--list-servers--_shell-completionszsh:5iiN(
RR!RR"R=ReR(R&R*R+R,R-R.(RR1RG((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyt test_incompleteCommandLine_case2s			

cCs}t}|jtjd|t}|jt|jdddddg|jd|j	dt
|jdd	S(
s
        Completion still happens even if a command-line is given
        that would normally throw UsageError.

        Break subcommand detection in a different way by providing
        an invalid subcommand name.
        Rs--fokkersunknown-subcommands
--list-servers--_shell-completionszsh:4iiN(RR!RR"R=ReR(R&R*R+R,R-(RR1RG((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyt test_incompleteCommandLine_case3(s		
cCswt}|jtjd|t}|jt|jdddg|jd|j	dt
|jddS(s
        Ensure the optimization which skips building the subcommand list
        under certain conditions isn't broken.
        Rs--albas--_shell-completionszsh:2iiN(RR!RR"R=ReR(R&R*R+R,R-(RR1RG((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyttest_skipSubcommandList<s		
cCsAt}tj|dd}|jd}|j|ddS(sY
        Test corner case fetching an option description from a method docstring
        R9RiN(R=RR<RPtgetDescriptionR+(RRGtargGentdescr((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyttest_poorlyDescribedOptMethodLs	cCsadtjfdY}t}|}|j|d||jt|jdddgdS(su
        A C{Completer} with repeat=True may only be used as the
        last item in the extraActions list.
        t
BrokenActionscBs2eZejdejdeejgZRS(RFtrepeat(RRRRRtTrueR>(((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyR|_s	RRs--_shell-completionszsh:2N(RR"RR!ReRfR&(RR|R1RG((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyttest_brokenActionsZs		cCsmdtjfdY}|}tj|dd}|j|jdd|j|jdddS(	s~
        opt_* methods on Options classes should not override the
        data provided in optFlags or optParameters.
        R"cBsAeZdddggZddddggZdZdZRS(	tflagRSsA flagtparamtpsA paramcSsdS(s junk description N((R((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pytopt_flaguscSsdS(s junk description N((RR((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyt	opt_paramxsN(RRRQRPt
optParametersRR(((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyR"qs	R9RsA flagRsA paramN(RR"RR<RPR+Rx(RR"RGRy((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyttest_optMethodsDontOverridels

	(RRRRIRXR_RgRnRrRtRuRvRwR{RR(((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyR8s		"			
	
						tEscapeTestCasecBseZdZRS(cCsEtj}d}|j||dd}|j||ddS(s5
        Verify _shellcomp.escape() function
        t$s'$'sA--'$"\`--Bs"A--'\$\"\\\`--B"N(RtescapeR+(RtescR((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyttest_escapes
	(RRR(((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyRstCompleterNotImplementedTestCasecBseZdZdZRS(s
    Test that using an unknown shell constant with SubcommandAction
    raises NotImplementedError

    The other Completer() subclasses are tested in test_usage.py
    cCs)tj}|jt|jdddS(sM
        Using an unknown shellType should raise NotImplementedError
        tbad_shell_typeN(RtSubcommandActionRetNotImplementedErrort
_shellCodeRP(Rtaction((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyttest_unknownShells(RRRR(((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyRstFighterAceServerOptionscBs5eZdZdddggZddddggZRS(s4
    Options for FighterAce 'server' subcommand
    slist-servers3List this server with the online FighterAce networkspackets-per-seconds+Number of update packets to send per secondt20N(RRRRPRQR(((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyRs
R=c
Bs
eZdZdddgdddgddd	gd
ddgd
ddgdddgdddggZdd*ddgddddggZdd*edggZedid d
6d!d6d"dgd#dddd
ggd$ie	d%gd6d&e
d'd(gZd)ZRS(+sB
    Command-line options for an imaginary `Fighter Ace` game
    RLRSs2Select the Fokker Dr.I as your dogfighter aircraftRMRUs5Select the Albatros D-III as your dogfighter aircraftRNRTs1Select the SPAD S.VII as your dogfighter aircraftRORRs4Select the Bristol Scout as your dogfighter aircrafttphysicsRs$Enable secret Twisted physics enginetjamtjs6Enable a small chance that your machine guns will jam!tverbosetvs1Verbose logging (may be specified more than once)s
pilot-namesWhat's your name, Ace?sManfred von Richthofentdetailtds*Select the level of rendering detail (1-5)t3RssStart FighterAce game-server.R?sTwisted-PhysicssRendering detail levelRBRDREt12345RFRzssaved game file to loadcCsdS(t N((R((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyt	opt_sillysN(
RRRRQRPRRR RRRR>R(((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyR=s<		

		R;cBsseZdZdd
dggZdd
ddggZedidd6died	d
d6ZdZ	dZ
RS(s
    Extend the options and zsh metadata provided by FighterAceOptions.
    _shellcomp must accumulate options and metadata from all classes in the
    hiearchy so this is important to test.
    s	no-stallss+Turn off the ability to stall your aircrafts
reality-levels)Select the level of physics reality (1-5)t5R?sCan't stall your planeRERzsPhysics reality levelcCsdS(s8
        Select that you can't crash your plane
        N((R((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pytopt_nocrashscCsdS(s+
        How tough are you? (1-10)
        N((RRZ((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pytopt_difficultysN(RRRRPRQRRRR>RR(((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyR;s
	cCstdddgddS(Nt1t2RRzsAccuracy'`?(R(((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyt_accuracyActionsRkcBseZdZdddgdddgddd	ggZd
dddgd
dddggZedidd6dd
6ddgdddggdiedddddgddd
6ed
6de	ddgZ
dZRS( s>
    Command-line options for a `Silly` imaginary program
    tcolortcsTurn on color outputtgraytgsTurn on gray-scale outputRRs1Verbose logging (may be specified more than once)toptimizationRs&Select the level of optimization (1-5)taccuracyRURs"Select the level of accuracy (1-3)R?sColor onsOptimization levelRBRDRERRt4Rzs
Optimization?RFsoutput filecCsdS(sM
        usage.Options does not recognize single-letter opt_ methods
        N((R((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pytopt_XsN(RRRRQRPRRRRRR>R(((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyRks&		

	

tSimpleProgSub1cBseZdddggZRS(ssub-optRTsSub Opt One(RRRQ(((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyR%stSimpleProgSub2cBseZdddggZRS(ssub-optRTsSub Opt Two(RRRQ(((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyR*sRpcBsbeZdgddggZdgddgdddggZd	d
ed
gdd
edggZRS(ssome-optionsother-optionR2s
some-paramsother-paramRs
another-paramtPsYet Another Paramtsub1s
Sub Command 1tsub2s
Sub Command 2N(RRRQRRPRRR (((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyRp/s	s#compdef silly

_arguments -s -A "-*" \
':output file (*):_files -g "*"' \
"(--accuracy)-a[Select the level of accuracy (1-3)]:Accuracy'\`?:(1 2 3)" \
"(-a)--accuracy=[Select the level of accuracy (1-3)]:Accuracy'\`?:(1 2 3)" \
'(--color --gray -g)-c[Color on]' \
'(--gray -c -g)--color[Color on]' \
'(--color --gray -c)-g[Turn on gray-scale output]' \
'(--color -c -g)--gray[Turn on gray-scale output]' \
'--help[Display this help and exit.]' \
'--optimization=[Optimization level]:Optimization?:(1 2 3 4 5)' \
'*-v[Verbose logging (may be specified more than once)]' \
'*--verbose[Verbose logging (may be specified more than once)]' \
'--version[Display Twisted version and exit.]' \
&& return 0
s#compdef silly2

_arguments -s -A "-*" \
'*::subcmd:->subcmd' \
':output file (*):_files -g "*"' \
"(--accuracy)-a[Select the level of accuracy (1-3)]:Accuracy'\`?:(1 2 3)" \
"(-a)--accuracy=[Select the level of accuracy (1-3)]:Accuracy'\`?:(1 2 3)" \
'(--another-param)-P[another-param]:another-param:_files' \
'(-P)--another-param=[another-param]:another-param:_files' \
'(--color --gray -g)-c[Color on]' \
'(--gray -c -g)--color[Color on]' \
'(--color --gray -c)-g[Turn on gray-scale output]' \
'(--color -c -g)--gray[Turn on gray-scale output]' \
'--help[Display this help and exit.]' \
'--optimization=[Optimization level]:Optimization?:(1 2 3 4 5)' \
'(--other-option)-o[other-option]' \
'(-o)--other-option[other-option]' \
'(--other-param)-p[other-param]:other-param:_files' \
'(-p)--other-param=[other-param]:other-param:_files' \
'--some-option[some-option]' \
'--some-param=[some-param]:some-param:_files' \
'*-v[Verbose logging (may be specified more than once)]' \
'*--verbose[Verbose logging (may be specified more than once)]' \
'--version[Display Twisted version and exit.]' \
&& return 0
local _zsh_subcmds_array
_zsh_subcmds_array=(
"sub1:Sub Command 1"
"sub2:Sub Command 2"
)

_describe "sub-command" _zsh_subcmds_array
(#RRjt	cStringIORt
twisted.trialRttwisted.pythonRRRttwisted.python.usageRRRRRR	tobjectRR
tTestCaseR8RRR"RR=R;RRkRRRpRlRq(((sF/usr/lib/python2.7/dist-packages/twisted/python/test/test_shellcomp.pyt<module>s.	D/	##