o
    qoi                     @   s   d Z ddlZddlmZmZmZ ddlmZ ddlZ	ddl
mZ ejG dd dZG dd	 d	e	jZG d
d dejZedkrFe  dS dS )zTests for transform.    N)CallableOptionalTuple)absltest)	transformc                   @   sN   e Zd ZU ee ed< ee ed< dZeeg df  ed< dZ	ee ed< dS )Fooa_tupleanother_tupleN
a_callable{   a_field_with_default)
__name__
__module____qualname__r   int__annotations__r
   r   r   r    r   r   [/home/ubuntu/.local/lib/python3.10/site-packages/fiddle/_src/experimental/transform_test.pyr      s
   
 r   c                   @   s   e Zd ZdZdS )PartialSubclassz2A subclass of `fdl.Partial` used for testing only.N)r   r   r   __doc__r   r   r   r   r   "   s    r   c                   @   sL   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dS )TransformTestc                 C   s&   t jtddd}| |j|jd dS )a  Tests whether Python interns tuples.

    This test is unique in that it does not test our code's functionality but
    rather our assumptions about how Python works. Currently, we assume (and
    tested) that Python interns (i.e. share the same instance) tuples that have
    the same value but are declared in different locations in the code. If this
    test ever fails, then it likely means Python is no longer interning tuples,
    so there's no need for unintern_tuples_of_literals as each tuple will have a
    different ID.
             r   r	   zoThis likely means Python is no longer interning tuples. We can remove unintern_tuples_of_literals in that case.N)fdlConfigr   assertIsr   r	   )selffoo_cfgr   r   r   test_python_interns_tuples(   s
   z(TransformTest.test_python_interns_tuplesc                 C   8   t jtddd}t|}| t|jt|jd d S Nr   r   za_tuple and another_tuple have the same id indicating they're the same instance, expected them to be different instances after uninterning.	r   r   r   r   unintern_tuples_of_literalsassertNotEqualidr   r	   r   r    uninterned_foo_cfgr   r   r   test_unintern_tuple_of_literals9   s   
z-TransformTest.test_unintern_tuple_of_literalsc                 C   r"   r#   r$   r(   r   r   r   'test_unintern_tuple_of_literals_in_listC   s   
z5TransformTest.test_unintern_tuple_of_literals_in_listc                 C   sF   ddgddf}t jt||d}t|}| t|jt|jd d S )Nr   r   r      r   za_tuple and another_tuple have different id indicating they're the different instances, expected them to be the same instance after uninterning as the these are not tuples of literals.)	r   r   r   r   r%   assertEqualr'   r   r	   )r   not_tuple_of_literalsr    r)   r   r   r   #test_unintern_tuple_of_non_literalsN   s   
z1TransformTest.test_unintern_tuple_of_non_literalsc                 C   s   |  tttt d S Nr   r   r   ,replace_unconfigured_partials_with_callablesr   Partialr   r   r   r   Ctest_replace_unconfigured_partials_with_callables_replace_top_level[   s   zQTransformTest.test_replace_unconfigured_partials_with_callables_replace_top_levelc                 C   s8   t jtt td}t jttd}| |t| d S )N)r
   )r   r   r   r3   r-   r   r2   )r   cfgexpected_cfgr   r   r   @test_replace_unconfigured_partials_with_callables_replace_nesteda   s   zNTransformTest.test_replace_unconfigured_partials_with_callables_replace_nestedc              	   C   s    |  tttjtdd d S )Nr   )r   r1   r4   r   r   r   Jtest_replace_unconfigured_partials_with_callables_replace_if_only_defaultsh   s   zXTransformTest.test_replace_unconfigured_partials_with_callables_replace_if_only_defaultsc                 C   s   t t}| |t| d S r0   )r   r   r-   r   r2   )r   r6   r   r   r   Jtest_replace_unconfigured_partials_with_callables_ignores_partial_subclassr   s   
zXTransformTest.test_replace_unconfigured_partials_with_callables_ignores_partial_subclassN)r   r   r   r!   r*   r+   r/   r5   r8   r9   r:   r   r   r   r   r   &   s    

r   __main__)r   dataclassestypingr   r   r   absl.testingr   fiddler   fiddle._src.experimentalr   	dataclassr   r3   r   TestCaser   r   mainr   r   r   r   <module>   s   S