
    f%!                        d Z ddlZd Zd Z G d dej                        Z G d dej                        Z G d	 d
ej                        Z G d dej                        Z G d dej                        Z	 G d dej                        Z
y)zSchema field tests
    Nc                  :    ddl m}  ddlm  G fdd|       }|S )Nr   	InterfaceBytesc                   \    e Zd Z W  dddd      Z W  dddd      Z W  dddd      Zy) _makeSchema.<locals>.ISchemaTestTitle    TtitledescriptiondefaultrequiredDescriptionSpamN)__name__
__module____qualname__r   r   spamr   s   u/var/dept/share/cheung/public_html/OutSchool/python/env/lib/python3.12/site-packages/zope/schema/tests/test_schema.pyISchemaTestr	      sI     	
  &	
 	r   r   )zope.interfacer   zope.schemar   )r   r   r   s     @r   _makeSchemar      s    (!i   r   c                  B    ddl m t               }  G fdd|       }|S )Nr   r   c                   (    e Zd Z W  dddd      Zy)/_makeDerivedSchema.<locals>.ISchemaTestSubclassFooFoonessr   Fr   N)r   r   r   foor   s   r   ISchemaTestSubclassr   2   s    "	r   r"   )r   r   r   )baser"   r   s     @r   _makeDerivedSchemar$   ,   s!    !=Dd  r   c                       e Zd Zd Zd Zd Zy)Test_getFieldsc                     ddl m}  ||      S )Nr   )	getFields)r   r(   )selfschemar(   s      r   _callFUTzTest_getFields._callFUT=   s    )  r   c                    | j                  t                     }| j                  d|v        | j                  d|v        | j                  d|v        |j                         D ]%  \  }}| j	                  ||j                                ' y )Nr   r   r   )r+   r   
assertTrueitemsassertEqualgetNamer)   fieldskeyvalues       r   test_simplezTest_getFields.test_simpleA   sv    {}-6)*/0&() !,,. 	3JCS%--/2	3r   c                 >   | j                  t                     }| j                  d|v        | j                  d|v        | j                  d|v        | j                  d|v        |j                         D ]%  \  }}| j	                  ||j                                ' y )Nr   r   r   r!   )r+   r$   r-   r.   r/   r0   r1   s       r   test_derivedzTest_getFields.test_derivedL   s    1346)*/0&()( !,,. 	3JCS%--/2	3r   Nr   r   r   r+   r5   r7    r   r   r&   r&   ;   s    !	3
3r   r&   c                       e Zd Zd Zd Zd Zy)Test_getFieldsInOrderc                     ddl m}  ||      S )Nr   )getFieldsInOrder)r   r=   )r)   r*   r=   s      r   r+   zTest_getFieldsInOrder._callFUT[   s    0''r   c                     | j                  t                     }|D cg c]  \  }}|	 }}}| j                  |g d       |D ]%  \  }}| j                  ||j                                ' y c c}}w N)r   r   r   )r+   r   r/   r0   r)   r2   namefieldfield_namesr3   r4   s          r   r5   z!Test_getFieldsInOrder.test_simple_   sh    {}-/56et66&FG  	3JCS%--/2	3 7   A-c                     | j                  t                     }|D cg c]  \  }}|	 }}}| j                  |g d       |D ]%  \  }}| j                  ||j                                ' y c c}}w N)r   r   r   r!   )r+   r$   r/   r0   r@   s          r   r7   z"Test_getFieldsInOrder.test_derivedf   sj    134/56et66&MN  	3JCS%--/2	3 7rD   Nr8   r9   r   r   r;   r;   Y   s    (33r   r;   c                       e Zd Zd Zd Zd Zy)Test_getFieldNamesc                     ddl m}  ||      S )Nr   )getFieldNames)r   rJ   )r)   r*   rJ   s      r   r+   zTest_getFieldNames._callFUTp   s    -V$$r   c                     | j                  t                     }| j                  t        |      d       | j	                  d|v        | j	                  d|v        | j	                  d|v        y )N   r   r   r   )r+   r   r/   lenr-   r)   namess     r   r5   zTest_getFieldNames.test_simplet   sX    km,UQ'5()./%(r   c                    | j                  t                     }| j                  t        |      d       | j	                  d|v        | j	                  d|v        | j	                  d|v        | j	                  d|v        y )N   r   r   r   r!   )r+   r$   r/   rM   r-   rN   s     r   r7   zTest_getFieldNames.test_derived{   sj    023UQ'5()./%('r   Nr8   r9   r   r   rH   rH   n   s    %)(r   rH   c                       e Zd Zd Zd Zd Zy)Test_getFieldNamesInOrderc                     ddl m}  ||      S )Nr   )getFieldNamesInOrder)r   rU   )r)   r*   rU   s      r   r+   z"Test_getFieldNamesInOrder._callFUT   s    4#F++r   c                 ^    | j                  t                     }| j                  |g d       y r?   )r+   r   r/   rN   s     r   r5   z%Test_getFieldNamesInOrder.test_simple   s#    km, @Ar   c                 ^    | j                  t                     }| j                  |g d       y rF   )r+   r$   r/   rN   s     r   r7   z&Test_getFieldNamesInOrder.test_derived   s%    023 GHr   Nr8   r9   r   r   rS   rS      s    ,BIr   rS   c                   *    e Zd Zd Zd Zd Zd Zd Zy)Test_getValidationErrorsc                      ddl m}  |||      S )Nr   )getValidationErrors)r   r[   )r)   r*   objectr[   s       r   r+   z!Test_getValidationErrors._callFUT   s    3"6622r   c                     ddl m}  G d d|      }| j                  |t                     }| j	                  t        |      d       y )Nr   r   c                       e Zd Zy)4Test_getValidationErrors.test_schema.<locals>.IEmptyN)r   r   r   r9   r   r   IEmptyr_      s    r   r`   )r   r   r+   r\   r/   rM   )r)   r   r`   errorss       r   test_schemaz$Test_getValidationErrors.test_schema   s9    ,	Y 	 vvx0Va(r   c                    ddl m} ddlm ddlm}  G fdd|      }| j                  |t                     }| j                  t        |      d       | j                  |d   d   d       | j                  |d   d   j                  |       | j                  |d   d   j                         | j                  |d   |d   d   j                         y )	Nr   r   TextSchemaNotFullyImplementedc                   "    e Zd Z W  d      Zy)MTest_getValidationErrors.test_schema_with_field_errors.<locals>.IWithRequiredTr   Nr   r   r   mustrd   s   r   IWithRequiredri          &Dr   rm      rl   r   r   r   re   zope.schema.interfacesrg   r+   r\   r/   rM   	__class__assertIsNoner4   rB   r)   r   rg   rm   ra   re   s        @r   test_schema_with_field_errorsz6Test_getValidationErrors.test_schema_with_field_errors       ,$D	'I 	' }fh7Va(1v.1//1JK&)A,,,-v.1++	-r   c                 &   ddl m} ddl m ddlm  G fdd|      }| j                  |t                     }| j                  t        |      d       | j                  |d   d   d        | j                  |d   d   j                         y )Nr   r   	invariant)Invalidc                   $    e Zd ZW  fd       Zy)YTest_getValidationErrors.test_schema_with_invariant_errors.<locals>.IWithFailingInvariantc                      d      )Ntestingr9   )objrz   s    r   
_epic_failzdTest_getValidationErrors.test_schema_with_invariant_errors.<locals>.IWithFailingInvariant._epic_fail   s    i((r   N)r   r   r   r   )rz   ry   s   r   IWithFailingInvariantr|      s    ) )r   r   ro   )
r   r   ry   zope.interface.exceptionsrz   r+   r\   r/   rM   rr   )r)   r   r   ra   rz   ry   s       @@r   !test_schema_with_invariant_errorsz:Test_getValidationErrors.test_schema_with_invariant_errors   sw    ,,5	)I 	)
 4fh?Va(1t,1//9r   c                     ddl m} ddl m  G fdd|      }| j                  |t	                     }| j                  t        |      d       y )Nr   r   rx   c                        e Zd ZW  d        Zy)UTest_getValidationErrors.test_schema_with_invariant_ok.<locals>.IWithPassingInvariantc                      y )Nr9   )r   s    r   
_hall_passz`Test_getValidationErrors.test_schema_with_invariant_ok.<locals>.IWithPassingInvariant._hall_pass   s    r   N)r   r   r   r   rx   s   r   IWithPassingInvariantr      s     r   r   )r   r   ry   r+   r\   r/   rM   )r)   r   r   ra   ry   s       @r   test_schema_with_invariant_okz6Test_getValidationErrors.test_schema_with_invariant_ok   s>    ,,	I 	
 4fh?Va(r   N)r   r   r   r+   rb   ru   r   r   r9   r   r   rY   rY      s    3)-":
)r   rY   c                   *    e Zd Zd Zd Zd Zd Zd Zy)Test_getSchemaValidationErrorsc                      ddl m}  |||      S )Nr   )getSchemaValidationErrors)r   r   )r)   r*   r\   r   s       r   r+   z'Test_getSchemaValidationErrors._callFUT   s    9(88r   c                     ddl m ddl m}  G fdd|      }| j                  |t	                     }| j                  t        |      d       y )Nr   	Attributer   c                   &    e Zd Zd Z W  d      Zy)GTest_getSchemaValidationErrors.test_schema_wo_fields.<locals>.INoFieldsc                       y)z	A method.Nr9   r9   r   r   methodzNTest_getSchemaValidationErrors.test_schema_wo_fields.<locals>.INoFields.method   s    r   ignoremeN)r   r   r   r   attrr   s   r   	INoFieldsr      s    Z(Dr   r   )r   r   r   r+   r\   r/   rM   )r)   r   r   ra   r   s       @r   test_schema_wo_fieldsz4Test_getSchemaValidationErrors.test_schema_wo_fields   s=    ,,	)	 	)
 y&(3Va(r   c                     ddl m} ddlm  G fdd|      } G d dt              }| j                  | |             }| j                  t        |      d       y )Nr   r   rd   c                   .    e Zd Z W         Z W         Zy)NTest_getSchemaValidationErrors.test_schema_with_fields_ok.<locals>.IWithFieldsNr   r   r   r!   barrd   s   r   IWithFieldsr      s    &C&Cr   r   c                       e Zd ZdZdZy)FTest_getSchemaValidationErrors.test_schema_with_fields_ok.<locals>.Objr   BarNr   r9   r   r   Objr      s    CCr   r   )r   r   r   re   r\   r+   r/   rM   )r)   r   r   r   ra   re   s        @r   test_schema_with_fields_okz9Test_getSchemaValidationErrors.test_schema_with_fields_ok   sI    ,$	) 		& 	 {CE2Va(r   c                    ddl m} ddlm ddlm}  G fdd|      }| j                  |t                     }| j                  t        |      d       | j                  |d   d   d       | j                  |d   d   j                  |       | j                  |d   d   j                         | j                  |d   |d   d   j                         y )	Nr   r   rd   rf   c                   "    e Zd Z W  d      Zy)TTest_getSchemaValidationErrors.test_schema_with_missing_field.<locals>.IWithRequiredTrj   Nrk   rd   s   r   rm   r      rn   r   rm   ro   rl   rp   rt   s        @r   test_schema_with_missing_fieldz=Test_getSchemaValidationErrors.test_schema_with_missing_field   rv   r   c                 :   ddl m} ddlm ddlm}  G fdd|      } G d dt              }| j                  | |             }| j                  t        |      d	       | j                  |d   d   d
       | j                  |d   d	   j                  |       y )Nr   r   Int)TooSmallc                   $    e Zd Z W  dd      Zy)RTest_getSchemaValidationErrors.test_schema_with_invalid_field.<locals>.IWithMiniumTr   )r   minNr   r   r   r4   r   s   r   IWithMiniumr     s    1-Er   r   c                       e Zd ZdZy)JTest_getSchemaValidationErrors.test_schema_with_invalid_field.<locals>.ObjNr   r9   r   r   r   r     s    Er   r   ro   r4   )r   r   r   r   rq   r   r\   r+   r/   rM   rr   )r)   r   r   r   r   ra   r   s         @r   test_schema_with_invalid_fieldz=Test_getSchemaValidationErrors.test_schema_with_invalid_field  s    ,#3	.) 	.	& 	 {CE2Va(1w/1//:r   N)r   r   r   r+   r   r   r   r   r9   r   r   r   r      s    9
)) -";r   r   )__doc__unittestr   r$   TestCaser&   r;   rH   rS   rY   r   r9   r   r   <module>r      s    23X&& 3<3H-- 3*(** (,I 1 1 I9)x00 9)xB;X%6%6 B;r   