
    h                        S r SSKJrJr  SSKJr  SSKJrJrJ	r	J
r
JrJr   " S S\5      r " S S\5      r " S	 S
\\5      r " S S\\5      r " S S\5      r " S S\\\5      r " S S\\5      r " S S\\5      r " S S\\5      r " S S\\5      r " S S\5      r " S S\5      r " S S\5      r " S S \
5      r " S! S"\5      rg#)$z
Unit tests for L{constantly}.
    )divisionabsolute_import)TestCase)NamedConstantNamesValueConstantValuesFlagConstantFlagsc                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)NamedConstantTests   z_
Tests for the L{constantly.NamedConstant} class which is used
to represent individual values.
c                 .     " S S[         5      nXl        g)z>
Create a dummy container into which constants can be placed.
c                       \ rS rSrSrg)%NamedConstantTests.setUp.<locals>.foo    N)__name__
__module____qualname____firstlineno____static_attributes__r       e/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/constantly/test/test_constants.pyfoor      s    r   r   N)r   	container)selfr   s     r   setUpNamedConstantTests.setUp   s    	% 	r   c                     [        5       nUR                  U R                  SS5        U R                  SUR                  5        g)zr
The C{name} attribute of a L{NamedConstant} refers to the value passed
for the C{name} parameter to C{_realize}.
barN)r   _realizer   assertEqualnamer   r$   s     r   	test_nameNamedConstantTests.test_name    s3    
 dnneT2		*r   c                     [        5       nUR                  U R                  SS5        U R                  S[	        U5      5        g)z
The string representation of an instance of L{NamedConstant} includes
the container the instances belongs to as well as the instance's name.
r!   Nz	<foo=bar>)r   r"   r   r#   reprr%   s     r   test_representation&NamedConstantTests.test_representation*   s3    
 dnneT2d4j1r   c                     [        5       nUR                  U R                  SS5        U R                  X:H  5        U R	                  X:g  5        g)z7
A L{NamedConstant} instance compares equal to itself.
r!   N)r   r"   r   
assertTrueassertFalser%   s     r   test_equality NamedConstantTests.test_equality4   s=     dnneT2%&r   c                     [        5       nUR                  U R                  SS5        [        5       nUR                  U R                  SS5        U R                  X:H  5        U R	                  X:g  5        g)zN
Two different L{NamedConstant} instances do not compare equal to each
other.
r!   N)r   r"   r   r.   r-   r   firstseconds      r   test_nonequality#NamedConstantTests.test_nonequality>   sX    
 t~~ud3t4)(r   c                     [        5       nUR                  U R                  SS5        [        5       nUR                  U R                  SS5        U R                  [	        U5      [	        U5      5        g)z
Because two different L{NamedConstant} instances do not compare as
equal to each other, they also have different hashes to avoid
collisions when added to a C{dict} or C{set}.
r!   N)r   r"   r   assertNotEqualhashr2   s      r   	test_hashNamedConstantTests.test_hashK   sR     t~~ud3t4DKf6r   )r   N)r   r   r   r   __doc__r   r&   r*   r/   r5   r:   r   r   r   r   r   r      s%    +2'
)
7r   r   c                   $    \ rS rSrSrS rS rSrg)_ConstantsTestsMixinY   zP
Mixin defining test helpers common to multiple types of constants
collections.
c                 l    U R                  [        U5      nU R                  US-   [        U5      5        g)z
Assert that an attempt to instantiate the constants class raises
C{TypeError}.

@param name: A C{str} giving the name of the constants collection.
@param cls: The constants class to test.
z may not be instantiated.N)assertRaises	TypeErrorr#   str)r   r$   clsexcs       r   _notInstantiableTest)_ConstantsTestsMixin._notInstantiableTest^   s0     	3/ ;;SXFr   c                 l    UR                   n[        X5        UR                   nU R                  X45        g)a#  
Assert that C{container._enumerants} does not change as a side-effect
of one of its attributes being accessed.

@param container: A L{_ConstantsContainer} subclass which will be
    tested.
@param constantName: The name of one of the constants which is an an
    attribute of C{container}.
N)_enumerantsgetattrassertIdentical)r   r   constantNamer3   r4   s        r   _initializedOnceTest)_ConstantsTestsMixin._initializedOnceTestj   s2     %% 		(&&U+r   r   N)r   r   r   r   r<   rF   rM   r   r   r   r   r>   r>   Y   s    	G,r   r>   c                   x    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rSrg)
NamesTests   zS
Tests for L{constantly.Names}, a base class for containers of
related constaints.
c                 .     " S S[         5      nXl        g)z
Create a fresh new L{Names} subclass for each unit test to use.  Since
L{Names} is stateful, re-using the same subclass across test methods
makes exercising all of the implementation code paths difficult.
c                   ^    \ rS rSrSr\" 5       r\" 5       r\" 5       r\" 5       r	\
" 5       rSrg) NamesTests.setUp.<locals>.METHOD   zI
A container for some named constants to use in unit tests for
L{Names}.
r   N)r   r   r   r   r<   r   GETPUTPOSTDELETEobjectextrar   r   r   r   METHODrT      s,      /C/C ?D"_FHEr   r\   N)r   r\   )r   r\   s     r   r   NamesTests.setUp   s    
	U 
	 r   c                 <    U R                  SU R                  5        g)zU
A subclass of L{Names} raises C{TypeError} if an attempt is made to
instantiate it.
r\   N)rF   r\   r   s    r   test_notInstantiableNamesTests.test_notInstantiable       
 	!!(DKK8r   c                 ,   U R                  [        U R                  S5      5        U R                  [        U R                  S5      5        U R                  [        U R                  S5      5        U R                  [        U R                  S5      5        g)z
Each name associated with a L{NamedConstant} instance in the definition
of a L{Names} subclass is available as an attribute on the resulting
class.
rV   rW   rX   rY   N)r-   hasattrr\   r_   s    r   test_symbolicAttributes"NamesTests.test_symbolicAttributes   s`     	U34U34V45X67r   c                 N    U R                  [        U R                  S5      5        g)z
As usual, names not defined in the class scope of a L{Names}
subclass are not available as attributes on the resulting class.
r   N)r.   rd   r\   r_   s    r   test_withoutOtherAttributes&NamesTests.test_withoutOtherAttributes       
 	e45r   c                 b    U R                  S[        U R                  R                  5      5        g)z
The string representation of a constant on a L{Names} subclass includes
the name of the L{Names} subclass and the name of the constant itself.
z<METHOD=GET>N)r#   r)   r\   rV   r_   s    r   r*   NamesTests.test_representation   s!    
 	dkkoo)>?r   c                     U R                   R                  S5      nU R                  U R                   R                  U5        g)zA
Constants can be looked up by name using L{Names.lookupByName}.
rV   N)r\   lookupByNamerK   rV   r   methods     r   test_lookupByNameNamesTests.test_lookupByName   s0     ))%0T[[__f5r   c                 \   U R                  [        U R                  R                  S5        U R                  [        U R                  R                  S5        U R                  [        U R                  R                  S5        U R                  [        U R                  R                  S5        g)ze
Names not defined with a L{NamedConstant} instance cannot be looked up
using L{Names.lookupByName}.
rn   __init__r   r[   N)rA   
ValueErrorr\   rn   r_   s    r   test_notLookupMissingByName&NamesTests.test_notLookupMissingByName   st    
 	*dkk&>&>O*dkk&>&>
K*dkk&>&>F*dkk&>&>Hr   c                 d    U R                  SU R                  R                  R                  5        g)zQ
The C{name} attribute of one of the named constants gives that
constant's name.
rV   N)r#   r\   rV   r$   r_   s    r   r&   NamesTests.test_name   s"    
 	 4 45r   c                 x    U R                  U R                  R                  U R                  R                  5        g)z}
Repeated access of an attribute associated with a L{NamedConstant}
value in a L{Names} subclass results in the same object.
N)rK   r\   rV   r_   s    r   test_attributeIdentity!NamesTests.test_attributeIdentity   s$    
 	T[[__dkkoo>r   c                    [        U R                  R                  5       5      nU R                  U R                  R                  U R                  R
                  U R                  R                  U R                  R                  /U5        g)z|
L{Names.iterconstants} returns an iterator over all of the constants
defined in the class, in the order they were defined.
N)listr\   iterconstantsr#   rV   rW   rX   rY   r   	constantss     r   test_iterconstantsNamesTests.test_iterconstants   s_    
 2245	[[__dkkoo[[t{{113	r   c                    [        U R                  R                  5       5      nU R                  U R                  R                  US   5        U R                  U R                  R
                  US   5        U R                  U R                  R                  US   5        U R                  U R                  R                  US   5        g)zp
The constants returned from L{Names.iterconstants} are identical to the
constants accessible using attributes.
r            N)r~   r\   r   rK   rV   rW   rX   rY   r   s     r   #test_attributeIterconstantsIdentity.NamesTests.test_attributeIterconstantsIdentity   s    
 2245	T[[__il;T[[__il;T[[--y|<T[[//1>r   c                 P   [        U R                  R                  5       5      n[        U R                  R                  5       5      nU R                  US   US   5        U R                  US   US   5        U R                  US   US   5        U R                  US   US   5        g)z_
The constants returned from L{Names.iterconstants} are identical on
each call to that method.
r   r   r   r   N)r~   r\   r   rK   r   r   agains      r   test_iterconstantsIdentity%NamesTests.test_iterconstantsIdentity   s    
 2245	T[[..01U1Xy|4U1Xy|4U1Xy|4U1Xy|4r   c                 <    U R                  U R                  S5        g)zV
L{Names._enumerants} is initialized once and its value re-used on
subsequent access.
rV   N)rM   r\   r_   s    r   test_initializedOnceNamesTests.test_initializedOnce  s    
 	!!$++u5r   c                    ^   " U 4S jS[         5      nT R                  T R                  R                  UR                  5        g)z
A constant defined on a L{Names} subclass may be set as an attribute of
another class and then retrieved using that attribute.
c                   D   > \ rS rSr Y R                  R
                  rSrg)8NamesTests.test_asForeignClassAttribute.<locals>.Anotheri  r   Nr   r   r   r   r\   rV   	somethingr   r_   s   r   Anotherr         Ir   r   NrZ   rK   r\   rV   r   r   r   s   ` r   test_asForeignClassAttribute'NamesTests.test_asForeignClassAttribute  s/    
	(f 	( 	T[[__g.?.?@r   c                    ^   " U 4S jS[         5      nT R                  T R                  R                  U" 5       R                  5        g)z
A constant defined on a L{Names} subclass may be set as an attribute of
another class and then retrieved from an instance of that class using
that attribute.
c                   D   > \ rS rSr Y R                  R
                  rSrg)CNamesTests.test_asForeignClassAttributeViaInstance.<locals>.Anotheri  r   Nr   r_   s   r   r   r     r   r   r   Nr   r   s   ` r   'test_asForeignClassAttributeViaInstance2NamesTests.test_asForeignClassAttributeViaInstance  s1    	(f 	( 	T[[__gi.A.ABr   c                 t   ^  U 4S jnT R                  [        U5      nT R                  S[        U5      5        g)z
It is explicitly disallowed (via a L{ValueError}) to use a constant
defined on a L{Names} subclass as the value of an attribute of another
L{Names} subclass.
c                  *   >  " U4S jS[         5      n g )Nc                   D   > \ rS rSr Y R                  R
                  rSrg)XNamesTests.test_notAsAlternateContainerAttribute.<locals>.defineIt.<locals>.AnotherNamesi+  r   Nr   r_   s   r   AnotherNamesr   +  s     KKOO	r   r   )r   )r   r   s    r   defineItBNamesTests.test_notAsAlternateContainerAttribute.<locals>.defineIt*  s    ,u ,r   zDCannot use <METHOD=GET> as the value of an attribute on AnotherNamesN)rA   ru   r#   rC   )r   r   rE   s   `  r   %test_notAsAlternateContainerAttribute0NamesTests.test_notAsAlternateContainerAttribute$  s6    	, 
H5H	r   )r\   N)r   r   r   r   r<   r   r`   re   rh   r*   rq   rv   r&   r{   r   r   r   r   r   r   r   r   r   r   r   rP   rP      s[    *9	86@6I6?		?
56A	Cr   rP   c                   x    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rSrg)ValuesTestsi6  zi
Tests for L{constantly.Names}, a base class for containers of
related constaints with arbitrary values.
c                 .     " S S[         5      nXl        g)z
Create a fresh new L{Values} subclass for each unit test to use.  Since
L{Values} is stateful, re-using the same subclass across test methods
makes exercising all of the implementation code paths difficult.
c                   4    \ rS rSr\" S5      r\" S5      rSrg)!ValuesTests.setUp.<locals>.STATUSiA  200404r   N)r   r   r   r   r   OK	NOT_FOUNDr   r   r   r   STATUSr   A  s    u%B%e,Ir   r   N)r	   r   )r   r   s     r   r   ValuesTests.setUp;  s    	-V 	- r   c                 <    U R                  SU R                  5        g)zV
A subclass of L{Values} raises C{TypeError} if an attempt is made to
instantiate it.
r   N)rF   r   r_   s    r   r`    ValuesTests.test_notInstantiableH  rb   r   c                     U R                  [        U R                  S5      5        U R                  [        U R                  S5      5        g)z
Each name associated with a L{ValueConstant} instance in the definition
of a L{Values} subclass is available as an attribute on the resulting
class.
r   r   N)r-   rd   r   r_   s    r   re   #ValuesTests.test_symbolicAttributesP  s2     	T23[9:r   c                 N    U R                  [        U R                  S5      5        g)z
As usual, names not defined in the class scope of a L{Values}
subclass are not available as attributes on the resulting class.
r   N)r.   rd   r   r_   s    r   rh   'ValuesTests.test_withoutOtherAttributesZ  rj   r   c                 b    U R                  S[        U R                  R                  5      5        g)z
The string representation of a constant on a L{Values} subclass
includes the name of the L{Values} subclass and the name of the
constant itself.
z<STATUS=OK>N)r#   r)   r   r   r_   s    r   r*   ValuesTests.test_representationb  s!     	T[[^^(<=r   c                     U R                   R                  S5      nU R                  U R                   R                  U5        g)zB
Constants can be looked up by name using L{Values.lookupByName}.
r   N)r   rn   rK   r   ro   s     r   rq   ValuesTests.test_lookupByNamek  s0     ))$/T[[^^V4r   c                    U R                  [        U R                  R                  S5        U R                  [        U R                  R                  S5        U R                  [        U R                  R                  S5        g)zf
Names not defined with a L{ValueConstant} instance cannot be looked up
using L{Values.lookupByName}.
rn   rt   r   N)rA   ru   r   rn   r_   s    r   rv   'ValuesTests.test_notLookupMissingByNames  sX    
 	*dkk&>&>O*dkk&>&>
K*dkk&>&>Fr   c                     U R                   R                  S5      nU R                  U R                   R                  U5        g)z
Constants can be looked up by their associated value, defined by the
argument passed to L{ValueConstant}, using L{Values.lookupByValue}.
r   N)r   lookupByValuerK   r   )r   statuss     r   test_lookupByValueValuesTests.test_lookupByValue}  s0    
 **51T[[^^V4r   c                 x     " S S[         5      nU R                  UR                  S5      UR                  5        g)z
If more than one constant is associated with a particular value,
L{Values.lookupByValue} returns whichever of them is defined first.
c                   8    \ rS rSrSr\" S5      r\" S5      rSrg)BValuesTests.test_lookupDuplicateByValue.<locals>.TRANSPORT_MESSAGEi  z.
Message types supported by an SSH transport.
   r   N)	r   r   r   r   r<   r   KEX_DH_GEX_REQUEST_OLD
KEXDH_INITr   r   r   r   TRANSPORT_MESSAGEr     s     &32%6"&r*Jr   r   r   N)r	   rK   r   r   )r   r   s     r   test_lookupDuplicateByValue'ValuesTests.test_lookupDuplicateByValue  s5    
	+ 	+ 	++B/44	6r   c                    U R                  [        U R                  R                  S5        U R                  [        U R                  R                  S5        U R                  [        U R                  R                  S5        g)zm
L{Values.lookupByValue} raises L{ValueError} when called with a value
with which no constant is associated.
r      z200.1N)rA   ru   r   r   r_   s    r   test_notLookupMissingByValue(ValuesTests.test_notLookupMissingByValue  sX    
 	*dkk&?&?F*dkk&?&?E*dkk&?&?Ir   c                 d    U R                  SU R                  R                  R                  5        g)K
The C{name} attribute of one of the constants gives that constant's
name.
r   N)r#   r   r   r$   r_   s    r   r&   ValuesTests.test_name  s"    
 	t{{~~223r   c                 x    U R                  U R                  R                  U R                  R                  5        g)z~
Repeated access of an attribute associated with a L{ValueConstant}
value in a L{Values} subclass results in the same object.
N)rK   r   r   r_   s    r   r{   "ValuesTests.test_attributeIdentity  s$    
 	T[[^^T[[^^<r   c                     [        U R                  R                  5       5      nU R                  U R                  R                  U R                  R
                  /U5        g)z}
L{Values.iterconstants} returns an iterator over all of the constants
defined in the class, in the order they were defined.
N)r~   r   r   r#   r   r   r   s     r   r   ValuesTests.test_iterconstants  sF    
 2245	[[^^T[[223	r   c                     [        U R                  R                  5       5      nU R                  U R                  R                  US   5        U R                  U R                  R
                  US   5        g)zq
The constants returned from L{Values.iterconstants} are identical to
the constants accessible using attributes.
r   r   N)r~   r   r   rK   r   r   r   s     r   r   /ValuesTests.test_attributeIterconstantsIdentity  sU    
 2245	T[[^^Yq\:T[[22IaLAr   c                     [        U R                  R                  5       5      n[        U R                  R                  5       5      nU R                  US   US   5        U R                  US   US   5        g)z`
The constants returned from L{Values.iterconstants} are identical on
each call to that method.
r   r   N)r~   r   r   rK   r   s      r   r   &ValuesTests.test_iterconstantsIdentity  sb    
 2245	T[[..01U1Xy|4U1Xy|4r   c                 <    U R                  U R                  S5        g)zW
L{Values._enumerants} is initialized once and its value re-used on
subsequent access.
r   N)rM   r   r_   s    r   r    ValuesTests.test_initializedOnce  s    
 	!!$++t4r   )r   N)r   r   r   r   r<   r   r`   re   rh   r*   rq   rv   r   r   r   r&   r{   r   r   r   r   r   r   r   r   r   r   6  sZ    
9;6>5G56"J4=B55r   r   c                       \ rS rSrSrS rSrg)_FlagsTestsMixini  z
Mixin defining setup code for any tests for L{Flags} subclasses.

@ivar FXF: A L{Flags} subclass created for each test method.
c                 .     " S S[         5      nXl        g)z
Create a fresh new L{Flags} subclass for each unit test to use.  Since
L{Flags} is stateful, re-using the same subclass across test methods
makes exercising all of the implementation code paths difficult.
c                   \    \ rS rSr\" 5       r\" 5       r\" 5       r\" S5      r\" 5       r	Sr
g)#_FlagsTestsMixin.setUp.<locals>.FXFi      r   N)r   r   r   r   r
   READWRITEAPPEND	EXCLUSIVETEXTr   r   r   r   FXFr     s,    >D NE!^F %T*I  >Dr   r   N)r   r   )r   r   s     r   r   _FlagsTestsMixin.setUp  s    	"% 	" r   )r   N)r   r   r   r   r<   r   r   r   r   r   r   r     s    
r   r   c                   r    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rSrg)
FlagsTestsi  zu
Tests for L{constantly.Flags}, a base class for containers of
related, combinable flag or bitvector-like constants.
c                 <    U R                  SU R                  5        g)zU
A subclass of L{Flags} raises L{TypeError} if an attempt is made to
instantiate it.
r   N)rF   r   r_   s    r   r`   FlagsTests.test_notInstantiable  s    
 	!!%2r   c                 v   U R                  [        U R                  S5      5        U R                  [        U R                  S5      5        U R                  [        U R                  S5      5        U R                  [        U R                  S5      5        U R                  [        U R                  S5      5        g)z
Each name associated with a L{FlagConstant} instance in the definition
of a L{Flags} subclass is available as an attribute on the resulting
class.
r   r   r   r   r   N)r-   rd   r   r_   s    r   re   "FlagsTests.test_symbolicAttributes  sw     	&12'23(34+67&12r   c                 N    U R                  [        U R                  S5      5        g)z
As usual, names not defined in the class scope of a L{Flags} subclass
are not available as attributes on the resulting class.
r   N)r.   rd   r   r_   s    r   rh   &FlagsTests.test_withoutOtherAttributes  s    
 	512r   c                 b    U R                  S[        U R                  R                  5      5        g)z
The string representation of a constant on a L{Flags} subclass includes
the name of the L{Flags} subclass and the name of the constant itself.
z
<FXF=READ>N)r#   r)   r   r   r_   s    r   r*   FlagsTests.test_representation  s!    
 	tDHHMM':;r   c                     U R                   R                  S5      nU R                  U R                   R                  U5        g)zA
Constants can be looked up by name using L{Flags.lookupByName}.
r   N)r   rn   rK   r   r   flags     r   rq   FlagsTests.test_lookupByName!  s0     xx$$V,TXX]]D1r   c                    U R                  [        U R                  R                  S5        U R                  [        U R                  R                  S5        U R                  [        U R                  R                  S5        g)zd
Names not defined with a L{FlagConstant} instance cannot be looked up
using L{Flags.lookupByName}.
rn   rt   r   N)rA   ru   r   rn   r_   s    r   rv   &FlagsTests.test_notLookupMissingByName)  sX    
 	*dhh&;&;^L*dhh&;&;ZH*dhh&;&;UCr   c                    U R                   R                  S5      nU R                  XR                   R                  5        U R                   R                  S5      nU R                  XR                   R                  5        U R                   R                  S5      nU R                  XR                   R
                  5        U R                   R                  S5      nU R                  XR                   R                  5        U R                   R                  S5      nU R                  XR                   R                  5        g)z
Constants can be looked up by their associated value, defined
implicitly by the position in which the constant appears in the class
definition or explicitly by the argument passed to L{FlagConstant}.
r   r      r   @   N)r   r   rK   r   r   r   r   r   r   s     r   r   FlagsTests.test_lookupByValue3  s     xx%%d+T88==1xx%%d+T88>>2xx%%d+T88??3xx%%d+T88#5#56xx%%d+T88==1r   c                 x     " S S[         5      nU R                  UR                  S5      UR                  5        g)z
If more than one constant is associated with a particular value,
L{Flags.lookupByValue} returns whichever of them is defined first.
c                   4    \ rS rSr\" S5      r\" S5      rSrg)5FlagsTests.test_lookupDuplicateByValue.<locals>.TIMEXiN  r   r   N)r   r   r   r   r
   
ADJ_OFFSET
MOD_OFFSETr   r   r   r   TIMEXr  N  s    %f-J &f-Jr   r  r   N)r   rK   r   r  )r   r  s     r   r   &FlagsTests.test_lookupDuplicateByValueI  s1    
	.E 	. 	U008%:J:JKr   c                 Z    U R                  [        U R                  R                  S5        g)zl
L{Flags.lookupByValue} raises L{ValueError} when called with a value
with which no constant is associated.
   N)rA   ru   r   r   r_   s    r   r   'FlagsTests.test_notLookupMissingByValueX  s     
 	*dhh&<&<dCr   c                 d    U R                  SU R                  R                  R                  5        g)r   r   N)r#   r   r   r$   r_   s    r   r&   FlagsTests.test_name`  s"    
 	!3!34r   c                 x    U R                  U R                  R                  U R                  R                  5        g)z|
Repeated access of an attribute associated with a L{FlagConstant} value
in a L{Flags} subclass results in the same object.
N)rK   r   r   r_   s    r   r{   !FlagsTests.test_attributeIdentityh  s$    
 	TXX]]DHHMM:r   c                 @   [        U R                  R                  5       5      nU R                  U R                  R                  U R                  R
                  U R                  R                  U R                  R                  U R                  R                  /U5        g)z|
L{Flags.iterconstants} returns an iterator over all of the constants
defined in the class, in the order they were defined.
N)	r~   r   r   r#   r   r   r   r   r   r   s     r   r   FlagsTests.test_iterconstantsp  sg    
 //12	XX]]DHHNNDHHOOXX0	r   c                    [        U R                  R                  5       5      nU R                  U R                  R                  US   5        U R                  U R                  R
                  US   5        U R                  U R                  R                  US   5        U R                  U R                  R                  US   5        U R                  U R                  R                  US   5        g)zp
The constants returned from L{Flags.iterconstants} are identical to the
constants accessible using attributes.
r   r   r   r   r   N)	r~   r   r   rK   r   r   r   r   r   r   s     r   r   .FlagsTests.test_attributeIterconstantsIdentity|  s    
 //12	TXX]]IaL9TXX^^Yq\:TXX__il;TXX//1>TXX]]IaL9r   c                    [        U R                  R                  5       5      n[        U R                  R                  5       5      nU R                  US   US   5        U R                  US   US   5        U R                  US   US   5        U R                  US   US   5        U R                  US   US   5        g)z_
The constants returned from L{Flags.iterconstants} are identical on
each call to that method.
r   r   r   r   r   N)r~   r   r   rK   r   s      r   r   %FlagsTests.test_iterconstantsIdentity  s    
 //12	TXX++-.U1Xy|4U1Xy|4U1Xy|4U1Xy|4U1Xy|4r   c                 <    U R                  U R                  S5        g)zV
L{Flags._enumerants} is initialized once and its value re-used on
subsequent access.
r   N)rM   r   r_   s    r   r   FlagsTests.test_initializedOnce  s    
 	!!$((F3r   r   N)r   r   r   r   r<   r`   re   rh   r*   rq   rv   r   r   r   r&   r{   r   r   r   r   r   r   r   r   r   r     sU    3
33<2D2,LD5;	
:54r   r   c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)FlagConstantSimpleOrTestsi  z
Tests for the C{|} operator as defined for L{FlagConstant} instances, used
to create new L{FlagConstant} instances representing both of two existing
L{FlagConstant} instances from the same L{Flags} class.
c                    U R                   R                  U R                   R                  -  nU R                  U R                   R                  R                  U R                   R                  R                  -  UR                  5        g)z
The value of the L{FlagConstant} which results from C{|} has all of the
bits set which were set in either of the values of the two original
constants.
N)r   r   r   r#   valuer   s     r   
test_value$FlagConstantSimpleOrTests.test_value  sV     xx}}txx~~-HHMM$((.."6"66

	
r   c                     U R                   R                  U R                   R                  -  nU R                  SUR                  5        g)z|
The name of the L{FlagConstant} instance which results from C{|}
includes the names of both of the two original constants.
z{READ,WRITE}N)r   r   r   r#   r$   r   s     r   r&   #FlagConstantSimpleOrTests.test_name  s2    
 xx}}txx~~-3r   c                     U R                   R                  U R                   R                  -  nU R                  S[	        U5      5        g)z
The string representation of a L{FlagConstant} instance which results
from C{|} includes the names of both of the two original constants.
z<FXF={READ,WRITE}>N)r   r   r   r#   r)   r   s     r   r*   -FlagConstantSimpleOrTests.test_representation  s3    
 xx}}txx~~--tDz:r   c                 .   U R                  [        U R                  R                  U R                  R                  -  5      [        S5      5        U R                  [        U R                  R                  5      [        U R                  R                  45      5        U R                  [        U R                  R                  U R                  R
                  -  5      [        U R                  R                  U R                  R
                  45      5        g)zj
A L{FlagConstant} instance which results from C{|} can be
iterated upon to yield the original constants.
r   N)r#   setr   r   r   r   r_   s    r   test_iterate&FlagConstantSimpleOrTests.test_iterate  s    
 	./G	 	!"	$ 	!3!334!3!345	7r   c                     U R                   R                  U R                   R                  -  nU R                  U R                   R                  U5        U R	                  U R                   R
                  U5        g)zR
A L{FlagConstant} instance which results from C{|} can be
tested for membership.
N)r   r   r   assertInassertNotInr   )r   flagss     r   test_membership)FlagConstantSimpleOrTests.test_membership  sN    
 !3!33dhhnne,.r   c                 >   U R                  U R                  R                  5        U R                  U R                  R                  U R                  R                  -  5        U R	                  U R                  R                  U R                  R                  -  5        g)z0
Empty flags is false, non-empty flags is true.
N)r-   r   r   r   r.   r_   s    r   test_truthiness)FlagConstantSimpleOrTests.test_truthiness  s`     	'););;<$((*<*<<=r   r   N)r   r   r   r   r<   r  r&   r*   r$  r*  r-  r   r   r   r   r  r    s%    
	
4;7 />r   r  c                   *    \ rS rSrSrS rS rS rSrg)FlagConstantSimpleAndTestsi  z
Tests for the C{&} operator as defined for L{FlagConstant} instances, used
to create new L{FlagConstant} instances representing the common parts of
two existing L{FlagConstant} instances from the same L{Flags} class.
c                 4   U R                   R                  U R                   R                  -  nU R                   R                  U R                   R                  -  nX-  nU R	                  U R                   R                  R
                  UR
                  5        g)z
The value of the L{FlagConstant} which results from C{&} has all of the
bits set which were set in both of the values of the two original
constants.
Nr   r   r   r   r#   r  r   	readWritewriteAppendr   s       r   r  %FlagConstantSimpleAndTests.test_value  sb     XX]]TXX^^3	xx~~7&--tzz:r   c                     U R                   R                  U R                   R                  -  nU R                   R                  U R                   R                  -  nX-  nU R	                  SUR
                  5        g)z
The name of the L{FlagConstant} instance which results from C{&}
includes the names of only the flags which were set in both of the two
original constants.
r   Nr   r   r   r   r#   r$   r3  s       r   r&   $FlagConstantSimpleAndTests.test_name  sT     XX]]TXX^^3	xx~~7&$)),r   c                     U R                   R                  U R                   R                  -  nU R                   R                  U R                   R                  -  nX-  nU R	                  S[        U5      5        g)z
The string representation of a L{FlagConstant} instance which results
from C{&} includes the names of only the flags which were set in both
both of the two original constants.
z<FXF=WRITE>Nr   r   r   r   r#   r)   r3  s       r   r*   .FlagConstantSimpleAndTests.test_representation  sT     XX]]TXX^^3	xx~~7&T
3r   r   N	r   r   r   r   r<   r  r&   r*   r   r   r   r   r0  r0    s    
	;	-	4r   r0  c                   *    \ rS rSrSrS rS rS rSrg)"FlagConstantSimpleExclusiveOrTestsi  z
Tests for the C{^} operator as defined for L{FlagConstant} instances, used
to create new L{FlagConstant} instances representing the uncommon parts of
two existing L{FlagConstant} instances from the same L{Flags} class.
c                 v   U R                   R                  U R                   R                  -  nU R                   R                  U R                   R                  -  nX-  nU R	                  U R                   R                  R
                  U R                   R                  R
                  -  UR
                  5        g)z
The value of the L{FlagConstant} which results from C{^} has all of the
bits set which were set in exactly one of the values of the two
original constants.
Nr2  r3  s       r   r  -FlagConstantSimpleExclusiveOrTests.test_value  sx     XX]]TXX^^3	xx~~7&HHMM$((//"7"77	
r   c                     U R                   R                  U R                   R                  -  nU R                   R                  U R                   R                  -  nX-  nU R	                  SUR
                  5        g)z
The name of the L{FlagConstant} instance which results from C{^}
includes the names of only the flags which were set in exactly one of
the two original constants.
z{APPEND,READ}Nr8  r3  s       r   r&   ,FlagConstantSimpleExclusiveOrTests.test_name'  sT     XX]]TXX^^3	xx~~7&$))4r   c                     U R                   R                  U R                   R                  -  nU R                   R                  U R                   R                  -  nX-  nU R	                  S[        U5      5        g)z
The string representation of a L{FlagConstant} instance which results
from C{^} includes the names of only the flags which were set in
exactly one of the two original constants.
z<FXF={APPEND,READ}>Nr;  r3  s       r   r*   6FlagConstantSimpleExclusiveOrTests.test_representation3  sU     XX]]TXX^^3	xx~~7&.T
;r   r   Nr=  r   r   r   r?  r?    s    

	5	<r   r?  c                   *    \ rS rSrSrS rS rS rSrg)FlagConstantNegationTestsi@  z
Tests for the C{~} operator as defined for L{FlagConstant} instances, used
to create new L{FlagConstant} instances representing all the flags from a
L{Flags} class not set in a particular L{FlagConstant} instance.
c                    U R                   R                  ) nU R                  U R                   R                  R                  U R                   R
                  R                  -  U R                   R                  R                  -  U R                   R                  R                  -  UR                  5        U R                   R                  ) nU R                  U R                   R                  R                  U R                   R
                  R                  -  U R                   R                  R                  -  U R                   R                  R                  -  UR                  5        g)z
The value of the L{FlagConstant} which results from C{~} has all of the
bits set which were not set in the original constant.
N)r   r   r#   r   r  r   r   r   r   s     r   r  $FlagConstantNegationTests.test_valueF  s    
 ~HHNN  HHOO!!"HH$$% HHMM  JJ	 HHMMHHOO!!"HH$$% HHMM  JJ	r   c                 j    U R                   R                  ) nU R                  SUR                  5        g)z
The name of the L{FlagConstant} instance which results from C{~}
includes the names of all the flags which were not set in the original
constant.
z{APPEND,EXCLUSIVE,READ,TEXT}N)r   r   r#   r$   r   s     r   r&   #FlagConstantNegationTests.test_name\  s(     7Cr   c                 h    U R                   R                  ) nU R                  S[        U5      5        g)z
The string representation of a L{FlagConstant} instance which results
from C{~} includes the names of all the flags which were not set in the
original constant.
z"<FXF={APPEND,EXCLUSIVE,READ,TEXT}>N)r   r   r#   r)   r   s     r   r*   -FlagConstantNegationTests.test_representationf  s(     =tDzJr   r   Nr=  r   r   r   rG  rG  @  s    
,DKr   rG  c                       \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rSrg)OrderedConstantsTestsiq  z
Tests for the ordering of constants.  All constants are ordered by
the order in which they are defined in their container class.
The ordering of constants that are not in the same container is not
defined.
c                 d    U R                  [        R                  [        R                  :  5        g)zM
L{constantly.NamedConstant} preserves definition
order in C{<} comparisons.
Nr-   NamedLettersalphabetar_   s    r   test_orderedNameConstants_lt2OrderedConstantsTests.test_orderedNameConstants_ltx  s!    
 	**\->->>?r   c                     U R                  [        R                  [        R                  :*  5        U R                  [        R                  [        R                  :*  5        g)zN
L{constantly.NamedConstant} preserves definition
order in C{<=} comparisons.
NrQ  r_   s    r   test_orderedNameConstants_le2OrderedConstantsTests.test_orderedNameConstants_le  s>    
 	**l.@.@@A**l.?.??@r   c                 d    U R                  [        R                  [        R                  :  5        g)zM
L{constantly.NamedConstant} preserves definition
order in C{>} comparisons.
N)r-   rR  rT  rS  r_   s    r   test_orderedNameConstants_gt2OrderedConstantsTests.test_orderedNameConstants_gt  s!    
 	))L,>,>>?r   c                     U R                  [        R                  [        R                  :  5        U R                  [        R                  [        R                  :  5        g)zN
L{constantly.NamedConstant} preserves definition
order in C{>=} comparisons.
NrQ  r_   s    r   test_orderedNameConstants_ge2OrderedConstantsTests.test_orderedNameConstants_ge  s>    
 	**l.@.@@A))\-?-??@r   c                     U R                  [        R                  [        R                  :  5        U R                  [        R                  [        R                  :  5        g)zM
L{constantly.ValueConstant} preserves definition
order in C{<} comparisons.
Nr-   ValuedLettersrS  digammazetar_   s    r   test_orderedValueConstants_lt3OrderedConstantsTests.test_orderedValueConstants_lt  s>    
 	++m.C.CCD--0B0BBCr   c                 $   U R                  [        R                  [        R                  :*  5        U R                  [        R                  [        R                  :*  5        U R                  [        R                  [        R                  :*  5        g)zN
L{constantly.ValueConstant} preserves definition
order in C{<=} comparisons.
Nra  r_   s    r   test_orderedValueConstants_le3OrderedConstantsTests.test_orderedValueConstants_le  s[    
 	++}/B/BBC++}/D/DDE--1C1CCDr   c                     U R                  [        R                  [        R                  :  5        U R                  [        R                  [        R                  :  5        g)zM
L{constantly.ValueConstant} preserves definition
order in C{>} comparisons.
N)r-   rb  rc  rS  rd  r_   s    r   test_orderedValueConstants_gt3OrderedConstantsTests.test_orderedValueConstants_gt  s>    
 	--0C0CCD**]-B-BBCr   c                 $   U R                  [        R                  [        R                  :  5        U R                  [        R                  [        R                  :  5        U R                  [        R                  [        R                  :  5        g)zN
L{constantly.ValueConstant} preserves definition
order in C{>=} comparisons.
Nra  r_   s    r   test_orderedValueConstants_ge3OrderedConstantsTests.test_orderedValueConstants_ge  s[    
 	++}/B/BBC--1D1DDE**m.C.CCDr   c                     U R                  [        R                  [        R                  :  5        U R                  [        R                  [        R                  :  5        g)zL
L{constantly.FlagConstant} preserves definition
order in C{<} comparisons.
Nr-   PizzaToppings
mozzarellapesto	pepperonir_   s    r   test_orderedFlagConstants_lt2OrderedConstantsTests.test_orderedFlagConstants_lt  s>    
 	00=3F3FFG++m.E.EEFr   c                 $   U R                  [        R                  [        R                  :*  5        U R                  [        R                  [        R                  :*  5        U R                  [        R                  [        R                  :*  5        g)zM
L{constantly.FlagConstant} preserves definition
order in C{<=} comparisons.
Nrq  r_   s    r   test_orderedFlagConstants_le2OrderedConstantsTests.test_orderedFlagConstants_le  s[    
 	00M4L4LLM00M4G4GGH++}/F/FFGr   c                     U R                  [        R                  [        R                  :  5        U R                  [        R                  [        R                  :  5        g)zL
L{constantly.FlagConstant} preserves definition
order in C{>} comparisons.
N)r-   rr  rt  rs  ru  r_   s    r   test_orderedFlagConstants_gt2OrderedConstantsTests.test_orderedFlagConstants_gt  s>    
 	++m.F.FFG//-2E2EEFr   c                 $   U R                  [        R                  [        R                  :  5        U R                  [        R                  [        R                  :  5        U R                  [        R                  [        R                  :  5        g)zM
L{constantly.FlagConstant} preserves definition
order in C{>=} comparisons.
Nrq  r_   s    r   test_orderedFlagConstants_ge2OrderedConstantsTests.test_orderedFlagConstants_ge  s[    
 	00M4L4LLM++}/G/GGH//=3F3FFGr   c                     U R                  [        [        R                  R	                  [
        R                  5      5        g)zr
L{constantly._constants._Constant.__lt__} returns C{NotImplemented}
when comparing constants of different types.
N)assertEqualsNotImplementedrR  rS  __lt__rb  r_   s    r   !test_orderedDifferentConstants_lt7OrderedConstantsTests.test_orderedDifferentConstants_lt  /    
 	%%m&9&9:	
r   c                     U R                  [        [        R                  R	                  [
        R                  5      5        g)zr
L{constantly._constants._Constant.__le__} returns C{NotImplemented}
when comparing constants of different types.
N)r  r  rR  rS  __le__rb  r_   s    r   !test_orderedDifferentConstants_le7OrderedConstantsTests.test_orderedDifferentConstants_le  r  r   c                     U R                  [        [        R                  R	                  [
        R                  5      5        g)zr
L{constantly._constants._Constant.__gt__} returns C{NotImplemented}
when comparing constants of different types.
N)r  r  rR  rS  __gt__rb  r_   s    r   !test_orderedDifferentConstants_gt7OrderedConstantsTests.test_orderedDifferentConstants_gt  r  r   c                     U R                  [        [        R                  R	                  [
        R                  5      5        g)zr
L{constantly._constants._Constant.__ge__} returns C{NotImplemented}
when comparing constants of different types.
N)r  r  rR  rS  __ge__rb  r_   s    r   !test_orderedDifferentConstants_ge7OrderedConstantsTests.test_orderedDifferentConstants_ge  r  r   c                     U R                  [        [        R                  R	                  [
        R                  5      5        g)z
L{constantly._constants._Constant.__lt__} returns C{NotImplemented}
when comparing constants belonging to different containers.
N)r  r  rR  rS  r  MoreNamedLettersrc  r_   s    r   "test_orderedDifferentContainers_lt8OrderedConstantsTests.test_orderedDifferentContainers_lt  0    
 	%%&6&>&>?	
r   c                     U R                  [        [        R                  R	                  [
        R                  5      5        g)z
L{constantly._constants._Constant.__le__} returns C{NotImplemented}
when comparing constants belonging to different containers.
N)r  r  rR  rS  r  r  rc  r_   s    r   "test_orderedDifferentContainers_le8OrderedConstantsTests.test_orderedDifferentContainers_le  r  r   c                     U R                  [        [        R                  R	                  [
        R                  5      5        g)z
L{constantly._constants._Constant.__gt__} returns C{NotImplemented}
when comparing constants belonging to different containers.
N)r  r  rR  rS  r  r  rc  r_   s    r   "test_orderedDifferentContainers_gt8OrderedConstantsTests.test_orderedDifferentContainers_gt(  r  r   c                     U R                  [        [        R                  R	                  [
        R                  5      5        g)z
L{constantly._constants._Constant.__ge__} returns C{NotImplemented}
when comparing constants belonging to different containers.
N)r  r  rR  rS  r  r  rc  r_   s    r   "test_orderedDifferentContainers_ge8OrderedConstantsTests.test_orderedDifferentContainers_ge3  r  r   r   N)r   r   r   r   r<   rU  rX  r[  r^  re  rh  rk  rn  rv  ry  r|  r  r  r  r  r  r  r  r  r  r   r   r   r   rO  rO  q  sw    @A@ADEDEGHGH







r   rO  c                   4    \ rS rSrSr\" 5       r\" 5       rSrg)rR  i?  z
Some letters, named.
r   N)	r   r   r   r   r<   r   rS  rT  r   r   r   r   rR  rR  ?  s     OEODr   rR  c                   4    \ rS rSrSr\" 5       r\" 5       rSrg)r  iH  z
Some more letters, named.
r   N)	r   r   r   r   r<   r   rc  rd  r   r   r   r   r  r  H  s     oGODr   r  c                   H    \ rS rSrSr\" S5      r\" S5      r\" S5      rSr	g)rb  iQ  z7
Some more letters, with cooresponding unicode values.
u   Αu   Ϝu   Ζr   N)
r   r   r   r   r<   r   rS  rc  rd  r   r   r   r   rb  rb  Q  s'     I&EI&GI&Dr   rb  c                   H    \ rS rSrSr\" S5      r\" S5      r\" S5      rSr	g)rr  i_  z@
Some pizza toppings, with obviously meaningful bitwise values.
r   r
  r   r   N)
r   r   r   r   r<   r
   rs  rt  ru  r   r   r   r   rr  rr  _  s'     f%Jf%Ef%Ir   rr  N)r<   
__future__r   r   twisted.trial.unittestr   
constantlyr   r   r   r	   r
   r   r   rZ   r>   rP   r   r   r   r  r0  r?  rG  rO  rR  r  rb  rr  r   r   r   <module>r     s    1 + C7 C7N",6 ",Ls/ sn`5(0 `5Hv :e4!8-A e4RD> 0( D>P'4!18 '4V)<)98 )<Z-K 0( -KbJ
H J
\5 u 
'F 
'	&E 	&r   