
    dafE                         d Z ddlZddlmZ ddlmZ ddlmZ  G d dej                        Z	 G d d	ej                        Z
ed
k(  r ej                          yy)z$Test equality and order comparisons.    N)	ALWAYS_EQ)Fraction)Decimalc                       e Zd ZdZ G d d      Z G d d      Zdddd ed      gZd	gd
d e       gZeez   Zd Z	d Z
d Zd Zd Zd Zd Zy)ComparisonSimpleTestz:Test equality and order comparisons for some simple cases.c                       e Zd Zd Zy)ComparisonSimpleTest.Emptyc                      y)Nz<Empty> selfs    ,/root/Python-3.12.4/Lib/test/test_compare.py__repr__z#ComparisonSimpleTest.Empty.__repr__   s        N)__name__
__module____qualname__r   r   r   r   Emptyr	      s    	r   r   c                       e Zd Zd Zd Zd Zy)ComparisonSimpleTest.Cmpc                     || _         y Narg)r   r   s     r   __init__z!ComparisonSimpleTest.Cmp.__init__   s	    DHr   c                      d| j                   z  S )Nz<Cmp %s>r   r   s    r   r   z!ComparisonSimpleTest.Cmp.__repr__   s    ((r   c                      | j                   |k(  S r   r   r   others     r   __eq__zComparisonSimpleTest.Cmp.__eq__   s    88u$$r   N)r   r   r   r   r   r    r   r   r   Cmpr      s    		)	%r   r!      g       @y       @           )   Nc                     | j                   D ]X  }| j                   D ]G  }|| j                  v r|| j                  v s||u r| j                  ||       6| j                  ||       I Z y r   )
candidatesset1assertEqualassertNotEqualr   abs      r   test_comparisonsz%ComparisonSimpleTest.test_comparisons   sc     	.A__ .$))^!tyy.a1f$$Q*''1-	.	.r   c           
          g }t        d      D ].  }|j                  t        |      dz  | j                                0 |D ]'  }|D ]   }| j	                  ||k(  ||u d|d|       " ) y )N
   r"   za=z, b=)rangeinsertlenr   r(   )r   Lir+   r,   s        r   test_id_comparisonsz(ComparisonSimpleTest.test_id_comparisons%   sw    r 	.AHHSVQY

-	. 	HA H  aaA1FGH	Hr   c                     | j                  d      }| j                  d      }| j                  d      }| j                  ||k(  d       | j                  ||k7  d       | j                  ||k7  d       y )Nr#   r"   TF)r!   assertIs)r   r+   r,   cs       r   test_ne_defaults_to_not_eqz/ComparisonSimpleTest.test_ne_defaults_to_not_eq.   s_    HHQKHHQKHHQKa1fd#a1fe$a1fd#r   c                     g  G fdd      } G fdd      } |        |       k7   | j                  ddg       y)z;object.__ne__() should allow reflected __ne__() to be triedc                       e Zd Z fdZy)8ComparisonSimpleTest.test_ne_high_priority.<locals>.Leftc                  2    j                  d       t        S )NLeft.__eq__appendNotImplementedargscallss    r   r    z?ComparisonSimpleTest.test_ne_high_priority.<locals>.Left.__eq__;       ]+%%r   Nr   r   r   r    rD   s   r   Leftr<   9       &r   rH   c                   "    e Zd Z fdZ fdZy)9ComparisonSimpleTest.test_ne_high_priority.<locals>.Rightc                  2    j                  d       t        S )NzRight.__eq__r?   rB   s    r   r    z@ComparisonSimpleTest.test_ne_high_priority.<locals>.Right.__eq__?       ^,%%r   c                  2    j                  d       t        S )NRight.__ne__r?   rB   s    r   __ne__z@ComparisonSimpleTest.test_ne_high_priority.<locals>.Right.__ne__B   rM   r   Nr   r   r   r    rP   rG   s   r   RightrK   >       &&r   rR   r>   rO   NassertSequenceEqual)r   rH   rR   rD   s      @r   test_ne_high_priorityz*ComparisonSimpleTest.test_ne_high_priority6   s?    	& 	&
	& 	& 	%'  (GHr   c                     g  G fdd      } G fdd|      } |        |       k7   | j                  ddg       y)z4object.__ne__() should not invoke reflected __eq__()c                       e Zd Z fdZy)7ComparisonSimpleTest.test_ne_low_priority.<locals>.Basec                  2    j                  d       t        S )NBase.__eq__r?   rB   s    r   r    z>ComparisonSimpleTest.test_ne_low_priority.<locals>.Base.__eq__M   rE   r   NrF   rG   s   r   BaserY   K   rI   r   r\   c                   "    e Zd Z fdZ fdZy):ComparisonSimpleTest.test_ne_low_priority.<locals>.Derivedc                  2    j                  d       t        S )NzDerived.__eq__r?   rB   s    r   r    zAComparisonSimpleTest.test_ne_low_priority.<locals>.Derived.__eq__Q       -.%%r   c                  2    j                  d       t        S )NDerived.__ne__r?   rB   s    r   rP   zAComparisonSimpleTest.test_ne_low_priority.<locals>.Derived.__ne__T   r`   r   NrQ   rG   s   r   Derivedr^   P   rS   r   rc   rb   r[   NrT   )r   r\   rc   rD   s      @r   test_ne_low_priorityz)ComparisonSimpleTest.test_ne_low_priorityH   sB    	& 	&
	&d 	& 	')  )9=(IJr   c           	          dd fdd fdd fdd fd	d
 ff}|D ]  \  }} j                  |      5   fd G fdd      }|D ]  \  }}||k7  st        ||        |dk(  r' j                   | |       t                     d       n% j	                  t
        | |       t                      ddd        y# 1 sw Y   xY w)z8No default delegation between operations except __ne__()r    c                     | |k(  S r   r   r+   r,   s     r   <lambda>z<ComparisonSimpleTest.test_other_delegation.<locals>.<lambda>]   
    AF r   __lt__c                     | |k  S r   r   rg   s     r   rh   z<ComparisonSimpleTest.test_other_delegation.<locals>.<lambda>^   
    AE r   __le__c                     | |k  S r   r   rg   s     r   rh   z<ComparisonSimpleTest.test_other_delegation.<locals>.<lambda>_   ri   r   __gt__c                     | |kD  S r   r   rg   s     r   rh   z<ComparisonSimpleTest.test_other_delegation.<locals>.<lambda>`   rl   r   __ge__c                     | |k\  S r   r   rg   s     r   rh   z<ComparisonSimpleTest.test_other_delegation.<locals>.<lambda>a   ri   r   c                  (    j                  d       y )Nz!Unexpected operator method called)fail)rC   r   s    r   
unexpectedz>ComparisonSimpleTest.test_other_delegation.<locals>.unexpectede   s    IIABr   c                       e Zd ZW  Zy)5ComparisonSimpleTest.test_other_delegation.<locals>.CN)r   r   r   rP   )ru   s   r   Crw   g   s    'Fr   rx   FN)subTestsetattrr7   objectassertRaises	TypeError)r   opsnamefuncrx   r   _ru   s   `      @r   test_other_delegationz*ComparisonSimpleTest.test_other_delegationZ   s     *+)**+)**+
  	FJD$d# FC( ( # 6HE1}5*56 8#MM$qsFH"5u=%%iqsFHEF F	FF Fs   B=A B==C	c                     d }| j                  |t               | j                  t        |       t               }| j                  |t               | j                  t        |       y )Nc                       y r   r   r   r   r   rh   z6ComparisonSimpleTest.test_issue_1393.<locals>.<lambda>r   s    r   )r(   r   r{   )r   xys      r   test_issue_1393z$ComparisonSimpleTest.test_issue_1393q   sN    I&A&HI&A&r   )r   r   r   __doc__r   r!   r'   set2r&   r-   r5   r9   rV   rd   r   r   r   r   r   r   r      sq    D % % sAtSX&DCtUW%DJ.H$I$K$F.'r   r   c            
          e Zd ZdZ G d d      Z G d de      Z G d de      Z G d d	e      Z G d
 de      Z G d de      Z	 G d de      Z
 G d de      Z G d de      Z G d de      Z G d de      Zeeeee	e
eeeef
Zd Zd Zd+dZd Zd Zd Zd Zd  Zd! Zd" Zd# Zd$ Zd% Zd& Zd' Zd( Zd) Z d* Z!y),ComparisonFullTestzTest equality and ordering comparisons for built-in types and
    user-defined classes that implement relevant combinations of rich
    comparison methods.
    c                       e Zd ZdZy)ComparisonFullTest.CompBasea  Base class for classes with rich comparison methods.

        The "x" attribute should be set to an underlying value to compare.

        Derived classes have a "meth" tuple attribute listing names of
        comparison methods implemented. See assert_total_order().
        N)r   r   r   r   r   r   r   CompBaser      s    	r   r   c                       e Zd ZdZy)ComparisonFullTest.CompNoner   N)r   r   r   methr   r   r   CompNoner      s    r   r   c                       e Zd ZdZd Zy)ComparisonFullTest.CompEq)eqc                 4    | j                   |j                   k(  S r   r   r   s     r   r    z ComparisonFullTest.CompEq.__eq__       66UWW$$r   N)r   r   r   r   r    r   r   r   CompEqr          	%r   r   c                       e Zd ZdZd Zy)ComparisonFullTest.CompNe)nec                 4    | j                   |j                   k7  S r   r   r   s     r   rP   z ComparisonFullTest.CompNe.__ne__   r   r   N)r   r   r   r   rP   r   r   r   CompNer      r   r   r   c                       e Zd ZdZd Zd Zy)ComparisonFullTest.CompEqNe)r   r   c                 4    | j                   |j                   k(  S r   r   r   s     r   r    z"ComparisonFullTest.CompEqNe.__eq__   r   r   c                 4    | j                   |j                   k7  S r   r   r   s     r   rP   z"ComparisonFullTest.CompEqNe.__ne__   r   r   N)r   r   r   r   r    rP   r   r   r   CompEqNer          	%	%r   r   c                       e Zd ZdZd Zy)ComparisonFullTest.CompLt)ltc                 4    | j                   |j                   k  S r   r   r   s     r   rj   z ComparisonFullTest.CompLt.__lt__       66EGG##r   N)r   r   r   r   rj   r   r   r   CompLtr          	$r   r   c                       e Zd ZdZd Zy)ComparisonFullTest.CompGt)gtc                 4    | j                   |j                   kD  S r   r   r   s     r   ro   z ComparisonFullTest.CompGt.__gt__   r   r   N)r   r   r   r   ro   r   r   r   CompGtr      r   r   r   c                       e Zd ZdZd Zd Zy)ComparisonFullTest.CompLtGt)r   r   c                 4    | j                   |j                   k  S r   r   r   s     r   rj   z"ComparisonFullTest.CompLtGt.__lt__   r   r   c                 4    | j                   |j                   kD  S r   r   r   s     r   ro   z"ComparisonFullTest.CompLtGt.__gt__   r   r   N)r   r   r   r   rj   ro   r   r   r   CompLtGtr      s    	$	$r   r   c                       e Zd ZdZd Zy)ComparisonFullTest.CompLe)lec                 4    | j                   |j                   k  S r   r   r   s     r   rm   z ComparisonFullTest.CompLe.__le__   r   r   N)r   r   r   r   rm   r   r   r   CompLer      r   r   r   c                       e Zd ZdZd Zy)ComparisonFullTest.CompGe)gec                 4    | j                   |j                   k\  S r   r   r   s     r   rq   z ComparisonFullTest.CompGe.__ge__   r   r   N)r   r   r   r   rq   r   r   r   CompGer      r   r   r   c                       e Zd ZdZd Zd Zy)ComparisonFullTest.CompLeGe)r   r   c                 4    | j                   |j                   k  S r   r   r   s     r   rm   z"ComparisonFullTest.CompLeGe.__le__   r   r   c                 4    | j                   |j                   k\  S r   r   r   s     r   rq   z"ComparisonFullTest.CompLeGe.__ge__   r   r   N)r   r   r   r   rm   rq   r   r   r   CompLeGer      r   r   r   c                     t        t        |            D cg c]	  } |        }}|j                  t               t	        ||      D ]  \  }}||_         |S c c}w )a  Create objects of type `class_` and return them in a list.

        `values` is a list of values that determines the value of data
        attribute `x` of each object.

        Objects in the returned list are sorted by their identity.  They
        assigned values in `values` list order.  By assign decreasing
        values to objects with increasing identities, testcases can assert
        that order comparison is performed by value and not by identity.
        )key)r0   r2   sortidzipr   )r   class_values__	instancesinstvalues          r   create_sorted_instancesz*ComparisonFullTest.create_sorted_instances   s\     ).c&k(:;"VX;	;2y&1 	KD%DF	 <s   Ac                    | j                  ||k(  |       | j                  ||k(  |       | j                  ||k7  |        | j                  ||k7  |        | j                  t        d      5  ||k   ddd       | j                  t        d      5  ||k   ddd       | j                  t        d      5  ||kD   ddd       | j                  t        d      5  ||k\   ddd       | j                  t        d      5  ||k   ddd       | j                  t        d      5  ||k   ddd       | j                  t        d      5  ||kD   ddd       | j                  t        d      5  ||k\   ddd       y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   wxY w# 1 sw Y   yxY w)zAssert equality result and that ordering is not implemented.

        a, b: Instances to be tested (of same or different type).
        equal: Boolean indicating the expected equality comparison results.
        not supportedNr(   assertRaisesRegexr}   )r   r+   r,   equals       r   assert_equality_onlyz'ComparisonFullTest.assert_equality_only   s    	a'a'aU+aU+##I? 	E	##I? 	F	##I? 	E	##I? 	F	##I? 	E	##I? 	F	##I? 	E	##I? 	F	 		 		 		 		 		 		 		 		 	s`   -E8F5FF=F)!F5G)G8FFFF&)F25F>G
GNc                     | j                  |||||       | j                  |||||       | j                  |||||       | j                  |||||       | j	                  |||||       | j                  |||||       y)aF  Test total ordering comparison of two instances.

        a, b: Instances to be tested (of same or different type).

        comp: -1, 0, or 1 indicates that the expected order comparison
           result for operations that are supported by the classes is
           a <, ==, or > b.

        a_meth, b_meth: Either None, indicating that all rich comparison
           methods are available, aa for builtins, or the tuple (subset)
           of "eq", "ne", "lt", "le", "gt", and "ge" that are available
           for the corresponding instance (of a user-defined class).
        N)assert_eq_subtestassert_ne_subtestassert_lt_subtestassert_le_subtestassert_gt_subtestassert_ge_subtestr   r+   r,   compa_methb_meths         r   assert_total_orderz%ComparisonFullTest.assert_total_order   s     	q!T66:q!T66:q!T66:q!T66:q!T66:q!T66:r   c                     |d|v sd|v r1| j                  ||k(  |dk(         | j                  ||k(  |dk(         y | j                  ||k(  ||u        | j                  ||k(  ||u        y )Nr   r   )r(   r   s         r   r   z$ComparisonFullTest.assert_eq_subtest  ss    >TV^tv~Q!VTQY/Q!VTQY/Q!VQ!V,Q!VQ!V,r   c                     |ddhj                  ||z         s1| j                  ||k7  |dk7         | j                  ||k7  |dk7         y | j                  ||k7  ||u       | j                  ||k7  ||u       y )Nr   r   r   )
isdisjointr(   r   s         r   r   z$ComparisonFullTest.assert_ne_subtest  s|    >$!8!8&!IQ!VTQY/Q!VTQY/Q!VQaZ0Q!VQaZ0r   c                 :   |d|v sd|v r1| j                  ||k  |dk         | j                  ||kD  |dk         y | j                  t        d      5  ||k   d d d        | j                  t        d      5  ||kD   d d d        y # 1 sw Y   .xY w# 1 sw Y   y xY w)Nr   r   r   r   r   r   s         r   r   z$ComparisonFullTest.assert_lt_subtest'      >TV^tv~QUD1H-QUD1H-''	?C A''	?C A      B6BBBc                 :   |d|v sd|v r1| j                  ||k  |dk         | j                  ||k\  |dk         y | j                  t        d      5  ||k   d d d        | j                  t        d      5  ||k\   d d d        y # 1 sw Y   .xY w# 1 sw Y   y xY w)Nr   r   r   r   r   r   s         r   r   z$ComparisonFullTest.assert_le_subtest1      >TV^tv~Q!VTQY/Q!VTQY/''	?C Q''	?C Q   r   c                 :   |d|v sd|v r1| j                  ||kD  |dkD         | j                  ||k  |dkD         y | j                  t        d      5  ||kD   d d d        | j                  t        d      5  ||k   d d d        y # 1 sw Y   .xY w# 1 sw Y   y xY w)Nr   r   r   r   r   r   s         r   r   z$ComparisonFullTest.assert_gt_subtest;  r   r   c                 :   |d|v sd|v r1| j                  ||k\  |dk\         | j                  ||k  |dk\         y | j                  t        d      5  ||k\   d d d        | j                  t        d      5  ||k   d d d        y # 1 sw Y   .xY w# 1 sw Y   y xY w)Nr   r   r   r   r   r   s         r   r   z$ComparisonFullTest.assert_ge_subtestE  r   r   c                 x    t               }t               }| j                  ||d       | j                  ||d       y)z#Compare instances of type 'object'.TFN)r{   r   r*   s      r   test_objectszComparisonFullTest.test_objectsO  s4    HH!!!Q-!!!Q.r   c           	         | j                   D ]  }| j                  |      5  | j                  |d      }| j                  |d   |d   d|j                  |j                         | j                  |d   |d   d|j                  |j                         | j                  |d   |d   d|j                  |j                         | j                  |d   |d   d|j                  |j                         ddd        y# 1 sw Y   xY w)z5Compare same-class instances with comparison methods.)r#   r"   r#   r   r"   r#   N)all_comp_classesry   r   r   r   )r   clsr   s      r   test_comp_classes_samez)ComparisonFullTest.test_comp_classes_sameV  s     (( 	<Cc" < 88iH	 ''	!ilA(+#((< ''	!ilA(+#((< ''	!ilB(+#((< ''	!ilB(+#((<%< <	<< <s   CC;;D	c           
         | j                   D ]  }| j                   D ]  }| j                  ||      5   |       }d|_         |       }d|_         |       }d|_        | j                  ||d|j                  |j                         | j                  ||d|j                  |j                         ddd         y# 1 sw Y   xY w)z:Compare different-class instances with comparison methods.rg   r#   r"   r   r   N)r   ry   r   r   r   )r   cls_acls_ba1b1b2s         r   test_comp_classes_differentz.ComparisonFullTest.test_comp_classes_differento  s     ** 	<E.. <\\EU\3 <BBDBBDBBD++B5::uzz;++BEJJ

<< <<	<< <s   A=B<<Cc                     G d dt               }t        d      }t        d      } |d      } |d      } |d      }| j                  ||d       | j                  ||d       | j                  ||d       | j                  ||d       | j                  ||d       | j                  ||d       | j                  ||d       | j                  ||d       | j                  ||d       y)z(Compare instances of str and a subclass.c                       e Zd Zy)9ComparisonFullTest.test_str_subclass.<locals>.StrSubclassN)r   r   r   r   r   r   StrSubclassr     s    r   r   r+   r,   r   r   N)strr   )r   r   s1s2c1c2c3s          r   test_str_subclassz$ComparisonFullTest.test_str_subclass  s    	# 	 XXB!,B+B!,B+B!,B+B!,B+B!,r   c                    d}d}| j                  ||d       | j                  ||d       d}d}| j                  ||d       | j                  ||d       t        dd      }t        d	d      }| j                  ||d       | j                  ||d       t        d
      }t        d      }| j                  ||d       | j                  ||d       d}	d}
| j                  |	|	d       | j                  |	|
d       ||f||f||f||f||f||ffD ]  \  }}| j                  ||d        ||||fD ]  }| j                  ||	d        y)zCompare number types.i  i  r   r   g     H@gH@i  r"   i  z1001.0z1001.1y     H@        y     H@      ?TFN)r   r   r   r   )r   i1i2f1f2q1q2d1d2r  r  n1n2s                r   test_numberszComparisonFullTest.test_numbers  sx    B*B+B*B+dAdAB*B+XXB*B+!!"b$/!!"b%0 2wB"R2b'Br7RGL 	/FB##BA.	/r2r" 	4B%%b"d3	4r   c                    ddg}ddg}| j                  ||d       | j                  ||d       d}d}| j                  ||d       | j                  ||d       t        dd      }t        dd      }| j                  ||d       | j                  ||d	       | j                  ||d	       | j                  ||d	       | j                  ||d	       y
)zCompare list, tuple, and range.r#   r"   r$   r   r   r#   r"   r"   r$   TFN)r   r0   r   )r   l1l2t1t2r1r2s          r   test_sequencesz!ComparisonFullTest.test_sequences  s    VVB*B+B*B+1a[1a[!!"b$/!!"b%0!!"b%0!!"b%0!!"b%0r   c                 h   d}d}| j                  ||d       | j                  ||d       t        d      }t        d      }| j                  ||d       | j                  ||d       | j                  ||d       | j                  ||d       | j                  ||d       | j                  ||d       y)zCompare bytes and bytearray.s   a1s   b2r   r   N)r   	bytearray)r   bs1bs2ba1ba2s        r   
test_byteszComparisonFullTest.test_bytes  s    S!,S"-S1-S"-S!,S"-S!,S"-r   c                 p   ddh}h d}| j                  ||d       | j                  ||d       t        |      }t        |      }| j                  ||d       | j                  ||d       | j                  ||d       | j                  ||d       | j                  ||d       | j                  ||d       y)zCompare set and frozenset.r#   r"   >   r#   r"   r$   r   r   N)r   	frozenset)r   r  r  r
  r  s        r   	test_setszComparisonFullTest.test_sets  s    VB*B+r]r]B+B+B*B+B*B+r   c                     ddd}ddd}ddd}| j                  ||d       | j                  ||d       | j                  ||d       y	)
z Compare dict.
        r+   r,   r  r8   r  )r$   r"   TFN)r   )r   r  r  d3s       r   test_mappingsz ComparisonFullTest.test_mappings  sX     !!"b$/!!"b%0!!"b$/r   )NN)"r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r#  r&  r)  r   r   r   r   r   z   s   
 8 % %
% %
%8 %$ $
$ $
$8 $% %
% %
%8 % FHFHFH	&&6;8-1/<2<$-,"4H1*.","0r   r   __main__)r   unittesttest.supportr   	fractionsr   decimalr   TestCaser   r   r   mainr   r   r   <module>r1     sX    *  "  o'8,, o'd@0** @0F zHMMO r   