o
    qoi                     @   s  d Z ddlZddlZddlZddlZddlZddlZddlmZm	Z	 ddl
mZ ddl
mZ ddlZddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlZd/ddZdd ZG dd dZejddG dd dZejddG dd dZejdddedej fddZ!ejdd Z"e	d Z#d!e#de#fd"d#Z$d$d% Z%G d&d' d'ej&ej&Z'G d(d) d)ej&ej&Z(G d*d+ d+ej&Z)G d,d- d-ej&Z*e+d.kre,  dS dS )0zTests for auto_config.    N)AnyTypeVar)absltest)parameterized)arg_factoryauto_config)auto_config_policy)autobuilders)	test_utiltestc                 C   s
   | |dS )Nargkwarg r   r   r   ]/home/ubuntu/.local/lib/python3.10/site-packages/fiddle/_src/experimental/auto_config_test.pybasic_fn%   s   
r   c                  K   s   d| iS )Nkwargsr   )r   r   r   r   fn_with_kwargs)      r   c                   @   s   e Zd Zdd ZdS )NonDataclassSampleClassc                 C   s   || _ || _d S Narg1arg2)selfr   r   r   r   r   __init__/   s   
z NonDataclassSampleClass.__init__N)__name__
__module____qualname__r   r   r   r   r   r   -   s    r   Ffrozenc                   @   s   e Zd ZU eed< eed< dS )MutableSampleClassr   r   N)r   r   r   r   __annotations__r   r   r   r   r"   4   s   
 r"   Tc                   @   s4   e Zd ZU eed< eed< dd Zejdd ZdS )FrozenSampleClassr   r   c                 C      dS N*   r   r   r   r   r   method?      zFrozenSampleClass.methodc                 C   s   t | S r   r   r(   r   r   r   autoconfig_methodB      z#FrozenSampleClass.autoconfig_methodN)r   r   r   r   r#   r)   r   r,   r   r   r   r   r$   :   s   
 r$   experimental_always_inlinexreturnc                 C   s   t jtd| dS )N   r   )fdlConfigr   r0   r   r   r   explicit_config_building_fnG      r7   c                   C      t dS )aP  Function to test that auto_config globals act correctly.

  In particular, we're testing that symbols that are added to `globals` *after*
  the auto_config decorator runs are visible when we call `as_buildable`.  For
  that reason, this function definition must be placed before the definition for
  `pass_through`.

  Returns:
    5
  r2   pass_throughr   r   r   r   globals_test_fnL   s   r<   Tr   c                 C   s   | S r   r   r   r   r   r   r;   ^   r*   r;   c                   C   s   t djS N   )sys	_getframef_linenor   r   r   r   _line_numberb      rD   c                   @   s2   e Zd Zeddddddddd	d

dddZdS )AutoConfigTransformerTest)z
a.b = x, yz1__auto_config_attr_save_handler__(a, 'b', (x, y)))z	x.y.z = vzT__auto_config_attr_save_handler__(__auto_config_attr_load_handler__(x, 'y'), 'z', v))za.b.c = c.dz|__auto_config_attr_save_handler__(__auto_config_attr_load_handler__(a, 'b'), 'c', __auto_config_attr_load_handler__(c, 'd')))z
a, b.c = vzW(a, _attr_save_temp_0) = v
__auto_config_attr_save_handler__(b, 'c', _attr_save_temp_0)zUa, _attr_save_temp_0 = v
__auto_config_attr_save_handler__(b, 'c', _attr_save_temp_0))	a = b = crG   )za, b.c = x.y.z = foo.barz(a, _attr_save_temp_0) = _attr_save_temp_1 = __auto_config_attr_load_handler__(foo, 'bar')
__auto_config_attr_save_handler__(b, 'c', _attr_save_temp_0)
__auto_config_attr_save_handler__(__auto_config_attr_load_handler__(x, 'y'), 'z', _attr_save_temp_1)za, _attr_save_temp_0 = _attr_save_temp_1 = __auto_config_attr_load_handler__(foo, 'bar')
__auto_config_attr_save_handler__(b, 'c', _attr_save_temp_0)
__auto_config_attr_save_handler__(__auto_config_attr_load_handler__(x, 'y'), 'z', _attr_save_temp_1))z#a.b.c = functools.partial(foo, x.y)z__auto_config_attr_save_handler__(__auto_config_attr_load_handler__(a, 'b'), 'c', __auto_config_call_handler__(functools.partial, foo, __auto_config_attr_load_handler__(x, 'y'))))z)a.b.c = bar = functools.partial(foo, x.y)z_attr_save_temp_0 = bar = __auto_config_call_handler__(functools.partial, foo, __auto_config_attr_load_handler__(x, 'y'))
__auto_config_attr_save_handler__(__auto_config_attr_load_handler__(a, 'b'), 'c', _attr_save_temp_0))za.b[1] = 123z2__auto_config_attr_load_handler__(a, 'b')[1] = 123)za, *a.b = foo.barz9(a, *a.b) = __auto_config_attr_load_handler__(foo, 'bar')z7a, *a.b = __auto_config_attr_load_handler__(foo, 'bar')Nc                 C   s   t j}|jdkr=|jdkr?t|dd}t|}||}|jdkr2|d ur2| 	t
|| d S | 	t
|| d S d S d S )N   	   zdummy.pyr      )rA   version_infomajorminorr   _AutoConfigNodeTransformerastparsevisitassertEqualunparse)r   sourceexpectedpy11_expectedversion
transfomernoder   r   r   test_attribute_saveh   s   V

z-AutoConfigTransformerTest.test_attribute_saver   )r   r   r   r   
parametersrZ   r   r   r   r   rF   f   s    	UrF   c                       s`  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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#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Z d=d> Z! fd?d@Z"dAdB Z#dCdD Z$dEdF Z%dGdH Z&dIdJ Z'dKdL Z(dMdN Z)dOdP Z*dQdR Z+e,-dSdT dUfdVdT dWfdXdT dYfdZdT d[fd\dT d]fd^d_ Z.d`da Z/dbdc Z0ddde Z1dfdg Z2dhdi Z3djdk Z4dldm Z5dndo Z6dpdq Z7drds Z8dtdu Z9e:;dvdwdx Z<dydz Z=d{d| Z>d}d~ Z?dd Z@dd ZAdd ZBdd ZCdd ZDdd ZEdd ZFdd ZG  ZHS )AutoConfigTestc                 C   sF   t jtddd}tjdd }| ||  | tdd|  d S )Nr@      r   c                   S   
   t ddS Nr@   r]   r$   r   r   r   r   test_class_config      
zBAutoConfigTest.test_create_basic_config.<locals>.test_class_configr4   r5   r$   r   rR   as_buildabler   expected_configrb   r   r   r   test_create_basic_config   s
   
z'AutoConfigTest.test_create_basic_configc                 C   sH   t jtddd}t dd }| ||  | tdd|  d S )Nr@   r]   r^   c                   S   r_   r`   ra   r   r   r   r   rb      rc   zJAutoConfigTest.test_create_basic_config_parents.<locals>.test_class_configrd   rf   r   r   r    test_create_basic_config_parents   s
   
z/AutoConfigTest.test_create_basic_config_parentsc                 C   s2   t jtddd}tjdd }| ||  d S )Nr@   r   r3   c                   S   s   t tddS )Nr@   r   )	functoolspartialr   r   r   r   r   test_fn_config      z@AutoConfigTest.test_create_basic_partial.<locals>.test_fn_config)r4   Partialr   r   rR   re   r   rg   rl   r   r   r   test_create_basic_partial   s   
z(AutoConfigTest.test_create_basic_partialc                 C   sn   t jtddd}tjdd }| ||  | |  ddddi | t |  ddddi d S )Nr@   r]   abc                   S   s   t jt jtddddS Nr@   rr   r]   rs   )rj   rk   r   r   r   r   r   rl      s   zDAutoConfigTest.test_nested_functools_partial.<locals>.test_fn_configr   )r4   rn   r   r   rR   re   buildro   r   r   r   test_nested_functools_partial   s   
z,AutoConfigTest.test_nested_functools_partialc                 C   H   t j dd }| td |  W d    d S 1 sw   Y  d S )Nc                   S   s   t t tddS r`   rj   rk   r$   r   r   r   r   rl      s   z`AutoConfigTest.test_nested_functools_partial_unsupported_positional_args.<locals>.test_fn_configz&chained.*partial.*calls.*only.*keywordr   assertRaisesRegex
ValueErrorre   )r   rl   r   r   r   9test_nested_functools_partial_unsupported_positional_args   s   

"zHAutoConfigTest.test_nested_functools_partial_unsupported_positional_argsc                 C   s8   t tt jtdd}tjdd }| ||  d S )Nrs   ru   c                   S   s   t ttjtddS )Nrs   ru   )r   rk   r   rj   r   r   r   r   r   rl   	  s   zDAutoConfigTest.test_create_basic_arg_factory.<locals>.test_fn_config)r4   rn   r   
ArgFactoryr   r   rR   re   ro   r   r   r   test_create_basic_arg_factory  s   
z,AutoConfigTest.test_create_basic_arg_factoryc                    s   ddifdd t j  fdd}| }| | ddd	 | | d
dd	 | | ddd	 t| }| | ddd	 | | ddd	 | | ddd	 d S )Ncountr   c                          d  d7  <  d S Nr   r@   r   r   counterr   r   r        z6AutoConfigTest.test_arg_factory_counter.<locals>.countc                      s   t t S r   )r   rk   r   r   r   r   r   rl        z?AutoConfigTest.test_arg_factory_counter.<locals>.test_fn_configr@   r   r   r]   rH      r2      r   rR   r4   rw   re   r   rl   py_callablebuilt_from_configr   r   r   r   test_arg_factory_counter     z'AutoConfigTest.test_arg_factory_counterc                 C   s`   t jtt tdt tdd}tjdd }tjdd }| ||  | ||  d S )Nr@   r]   rq   c                   S   s$   t jtjttddttddS rt   )r   rk   rj   r   r   r   r   r   r   test_fn_config_1*  s   
zWAutoConfigTest.test_arg_factory_functools_partial_alternation.<locals>.test_fn_config_1c                   S   s$   t jtjtt tddtddS )Nr]   rv   r@   ru   )rj   rk   r   r   r   r   r   r   r   test_fn_config_24  s   
zWAutoConfigTest.test_arg_factory_functools_partial_alternation.<locals>.test_fn_config_2)	r4   rn   r   r5   r   r   r   rR   re   )r   rg   r   r   r   r   r   .test_arg_factory_functools_partial_alternation%  s   
	
	z=AutoConfigTest.test_arg_factory_functools_partial_alternationc                 C   sL   t jtddd}tjddd}| ||d | tdd|d d S )N
positionaldefaultr^   c                 S   
   t | |S r   ra   r   r   r   r   rb   F  rc   zFAutoConfigTest.test_create_config_with_args.<locals>.test_class_config)r   rd   rf   r   r   r   test_create_config_with_argsA  s   z+AutoConfigTest.test_create_config_with_argsc                 C   sP   t jtddd}tjdddd}| ||d | tdd|d d S )Nr   r   r^   c                S   r   r   ra   r   r   r   r   rb   V  rc   zMAutoConfigTest.test_create_config_with_kwonly_args.<locals>.test_class_configrd   rf   r   r   r   #test_create_config_with_kwonly_argsQ  s   z2AutoConfigTest.test_create_config_with_kwonly_argsc                    sp   t jtdt tddd}tjdddd  tj fdd	}| ||  | dtddd
d|  d S )Nr@   r]   r3   Tr.   c                   S      t dddS )Nr@   r]   r^   ra   r   r   r   r   rb   f  r   zBAutoConfigTest.test_calling_auto_config.<locals>.test_class_configc                      s   t d  S r?   r+   r   rb   r   r   rl   j  r   z?AutoConfigTest.test_calling_auto_config.<locals>.test_fn_configr^   r   )r4   r5   r   r$   r   rR   re   ro   r   r   r   test_calling_auto_configa  s   

z'AutoConfigTest.test_calling_auto_configc                 C   sV   t jtdt tddd}tjdd }| ||  | tdddd|  d S )Nr@   r]   r   r^   c                   S   s   t dtddS )Nr@   r]   r   r$   r   r   r   r   r   rb   x  r8   z;AutoConfigTest.test_nested_calls.<locals>.test_class_configr   r4   r5   r$   r   r   rR   re   rf   r   r   r   test_nested_callss  s   
z AutoConfigTest.test_nested_callsc                 C   s<   t jtdt tddd}tjdd }| ||  d S )Nr@   r2   
   r^   c                   S   s   t dtdS )Nr@   r   )r$   r7   r   r   r   r   test_nested_call  rm   zGAutoConfigTest.test_calling_explicit_function.<locals>.test_nested_callr   )r   rg   r   r   r   r   test_calling_explicit_function  s   
z-AutoConfigTest.test_calling_explicit_functionc                    s:   d t jtd d}tj fdd}| ||  d S )NrH   r@   r3   c                      s
   t d S r?   r+   r   nonlocal_varr   r   rl     rc   z>AutoConfigTest.test_reference_nonlocal.<locals>.test_fn_config)r4   r5   r   r   rR   re   ro   r   r   r   test_reference_nonlocal  s
   z&AutoConfigTest.test_reference_nonlocalc                    sT   d  fdd}| }|  }d}| |j| | ||  | |t| d S )Nr   c                     s   d t j  fdd} | S )Nr@   c                     s   d} t  | fS Nr]   r:   )var_level_2)var_level_0var_level_1r   r   inner  s   zQAutoConfigTest.test_closures_in_multi_level_nesting.<locals>.outer.<locals>.innerr   )r   r   )r   r   outer  s   zBAutoConfigTest.test_closures_in_multi_level_nesting.<locals>.outerr   r@   r]   )re   rR   r   r4   rw   )r   r   inner_fncfgexpected_resultr   r   r   $test_closures_in_multi_level_nesting  s   
z3AutoConfigTest.test_closures_in_multi_level_nestingc                 C   s8   t tg dddg}tjdd }| ||  d S )Nr   rr   rs   c                   S   s    t ttdtddd S )NrH   r   r@   rq   )r$   listrangekeysr   r   r   r   test_config  s    z9AutoConfigTest.test_calling_builtins.<locals>.test_configrd   )r   rg   r   r   r   r   test_calling_builtins  s   
z$AutoConfigTest.test_calling_builtinsc                 C   s   t tfD ]
}| t| qttttt	t
fD ]
}| t| q| tg j | ti j tdd}| t|j | ttj | ttj d S r`   )r   dict
assertTruer	   v1r   tuplesumanyalliterappendr   r$   assertFalser)   r4   r5   rn   )r   builtin_typebuiltin
test_classr   r   r   test_auto_config_eligibility  s   
z+AutoConfigTest.test_auto_config_eligibilityc                 C   s:   t jttjtddd}tjdd }| ||  d S )NFrequire_skeletonr>   c                  S   s   t jtdd} t| S )NFr   )abconfigr$   r   r6   r   r   r   autobuilder_using_fn  s   zMAutoConfigTest.test_autobuilders_in_auto_config.<locals>.autobuilder_using_fn)	r4   r5   r   r   r   r$   r   rR   re   )r   rg   r   r   r   r    test_autobuilders_in_auto_config  s   
z/AutoConfigTest.test_autobuilders_in_auto_configc                 C   s<   |  td td W d    d S 1 sw   Y  d S )Nzonly compatible with functionsrH   )r|   r}   r   r(   r   r   r   "test_auto_configuring_non_function  s   "z1AutoConfigTest.test_auto_configuring_non_functionc                 C   sX   t jtdddt tdddgt tddfd	}tjd
d }| }| || d S )Nr@   r]   r^   rH   r   r2   r   r   	test_key1	test_key2	test_key3c                   S   s(   t ddt dddgttddfdS )	Nr@   r]   rH   r   r2   r   r   r   )r$   rj   rk   r;   r   r   r   r   r     s   z9AutoConfigTest.test_return_structure.<locals>.test_config)r4   r5   r$   rn   r;   r   re   rR   )r   rg   r   	buildabler   r   r   test_return_structure  s   
z$AutoConfigTest.test_return_structurec                 C   ry   )Nc                   S   s
   ddgiS )Nzno buildablezinside herer   r   r   r   r   r     rc   zIAutoConfigTest.test_require_buildable_in_return_type.<locals>.test_configzThe `auto_config` rewritten version of `AutoConfigTest\.\w+\.<locals>\.test_config` returned a `dict`, which is not \(or did not contain\) a `fdl\.Buildable`\.)r   r|   	TypeErrorre   r   r   r   r   r   %test_require_buildable_in_return_type  s   

"z4AutoConfigTest.test_require_buildable_in_return_typec                    s   G dd dt j}G dd dt j}G dd dt j}tj|||d}dtfd	d
 tj|d fdd}|t|t| |t| d}|	 }| 
|| d S )Nc                   @      e Zd ZdS )zCAutoConfigTest.test_experimental_config_types.<locals>.CustomConfigNr   r   r   r   r   r   r   CustomConfig      r   c                   @   r   )zDAutoConfigTest.test_experimental_config_types.<locals>.CustomPartialNr   r   r   r   r   CustomPartial  r   r   c                   @   r   )zGAutoConfigTest.test_experimental_config_types.<locals>.CustomArgFactoryNr   r   r   r   r   CustomArgFactory  r   r   )
config_clspartial_clsarg_factory_clsr1   c                   S   r%   r&   r   r   r   r   r   make_int  r*   z?AutoConfigTest.test_experimental_config_types.<locals>.make_int)experimental_config_typesc                      s   t tt  tt dS Nr   )r$   rj   rk   r   r   r   r   r   r   fn  s   
z9AutoConfigTest.test_experimental_config_types.<locals>.fnr   )r4   r5   rn   r   r   ConfigTypesintr$   r   re   assertDagEqual)r   r   r   r   config_typesr   rU   r   r   r   r   test_experimental_config_types  s$   
z-AutoConfigTest.test_experimental_config_typesc                 C   s|   G dd d}|  ttdd|j  |  tdd|  | }|  ttdd|j  |  tdd|  d S )Nc                   @      e Zd Zejedd ZdS )z9AutoConfigTest.test_staticmethod_nullary.<locals>.MyClassc                   S   r_   )Nr]   r@   ra   r   r   r   r   my_fn     
z?AutoConfigTest.test_staticmethod_nullary.<locals>.MyClass.my_fnNr   r   r   r   staticmethodr   r   r   r   r   MyClass      r   r]   r@   rR   r4   r5   r$   r   re   r   r   instancer   r   r   test_staticmethod_nullary  s   z(AutoConfigTest.test_staticmethod_nullaryc                 C   s   G dd d}|  ttdd|jd |  tdd|d | }|  ttdd|jd |  tdd|d d S )Nc                   @   r   )z;AutoConfigTest.test_staticmethod_arguments.<locals>.MyClassc                 S   s   t | | d S r?   ra   r6   r   r   r   r   /     zAAutoConfigTest.test_staticmethod_arguments.<locals>.MyClass.my_fnNr   r   r   r   r   r   -  r   r   r2   r   r   r   r   r   r   test_staticmethod_arguments+  s   z*AutoConfigTest.test_staticmethod_argumentsc                 C   D   d}|  t| G dd d}W d    d S 1 sw   Y  d S )Nz@staticmethod placed above @auto_config on function my_fn at .+:\d+\. Reorder decorators so that @auto_config is placed above @staticmethod.c                   @      e Zd Zeejdd ZdS )z8AutoConfigTest.test_staticmethod_on_top.<locals>.MyClassc                 S      d S r   r   r0   yr   r   r   r   J     z>AutoConfigTest.test_staticmethod_on_top.<locals>.MyClass.my_fnN)r   r   r   r   r   r   r   r   r   r   r   H      r   r|   AssertionErrorr   expected_msgr   r   r   r   test_staticmethod_on_top@  
   "z'AutoConfigTest.test_staticmethod_on_topc                    sJ   t jddG  fddd  jd}| |jd | |jd d S )NTr    c                       s6   e Zd ZU eed< eed< ejed fdd	ZdS )zHAutoConfigTest.test_staticmethod_ctor.<locals>.ClassWithStaticmethodCtorrr   rs         ?c                    s
    d| S r?   r   rv   ClassWithStaticmethodCtorr   r   staticmethod_initV  r   zZAutoConfigTest.test_staticmethod_ctor.<locals>.ClassWithStaticmethodCtor.staticmethod_initN)r  )	r   r   r   r   r#   floatr   r   r  r   r  r   r   r  Q  s   
 r         @r@   )dataclasses	dataclassr  re   rR   rr   rs   )r   r   r   r  r   test_staticmethod_ctorO  s
   
	z%AutoConfigTest.test_staticmethod_ctorc                 C   s>  t jG dd d}G dd d|}|j }| |t| | d|j | d|j | d|j	 |dd}|j }| |t| | d|j | d|j | d|j	 | |jj
d	 | |jjd
 | |jjt
 | |jjd | |jj
d	 | |jjd
 | |jjt
 | |jjd d S )Nc                   @   s<   e Zd ZU eed< eed< dZeed< eje	dd Z
dS )z0AutoConfigTest.test_classmethod.<locals>.MyClassr0   r   r  zc                 S   s   | ddddS )Test simple docstring.r@   1r  )r0   r   r  r   clsr   r   r   simpleg  s   7AutoConfigTest.test_classmethod.<locals>.MyClass.simpleN)r   r   r   r   r#   strr  r  r   classmethodr  r   r   r   r   r   a  s   
 r   c                   @   r   )z3AutoConfigTest.test_classmethod.<locals>.MySubclassNr   r   r   r   r   
MySubclassm  r   r  r@   r  r  2r  r  r  )r  r	  r  re   rR   r4   get_callabler0   r   r  r   r   r   __doc__)r   r   r  r   class_instancer   r   r   test_classmethod_  s4   




zAutoConfigTest.test_classmethodc                 C   r   )N@classmethod placed above @auto_config on function my_fn at .+:\d+\. Reorder decorators so that @auto_config is placed above @classmethod.c                   @   r   )z7AutoConfigTest.test_classmethod_on_top.<locals>.MyClassc                 S   r   r   r   r  r0   r   r   r   r   r     r   z=AutoConfigTest.test_classmethod_on_top.<locals>.MyClass.my_fnNr   r   r   r  r   r   r   r   r   r   r     r   r   r   r   r   r   r   test_classmethod_on_top  r  z&AutoConfigTest.test_classmethod_on_topc                 C   r   )Nr  c                   @   s$   e Zd Zeejdddd ZdS )zRAutoConfigTest.test_classmethod_on_top_with_auto_config_arguments.<locals>.MyClassTexperimental_allow_control_flowc                 S   r   r   r   r  r   r   r   r     r   zXAutoConfigTest.test_classmethod_on_top_with_auto_config_arguments.<locals>.MyClass.my_fnNr  r   r   r   r   r     s    
r   r   r   r   r   r   2test_classmethod_on_top_with_auto_config_arguments  r  zAAutoConfigTest.test_classmethod_on_top_with_auto_config_argumentsc                 C   s   t j dd }| d t|}| || | | |  W d    n1 s,w   Y  | d t|}| || | | |  W d    d S 1 sWw   Y  d S )Nc                   S   r_   r`   ra   r   r   r   r   test_fn  rc   z)AutoConfigTest.test_copy.<locals>.test_fnshallow_copy	deep_copy)r   subTestcopyassertIsNotrR   re   deepcopy)r   r!  r"  r#  r   r   r   	test_copy  s   


"zAutoConfigTest.test_copyc                 C   s   t jddG dd d}| d  t|j}| ||j | | |j  W d    n1 s5w   Y  | d! t|j}| ||j | | |j  W d    d S 1 scw   Y  d S )NTr    c                   @   0   e Zd ZU eed< eed< ejedd ZdS )z7AutoConfigTest.test_copy_classmethod.<locals>.SomeClassrr   rs   c                 S   s
   | ddS r`   r   r  r   r   r   test_method  r   zCAutoConfigTest.test_copy_classmethod.<locals>.SomeClass.test_methodN)r   r   r   r   r#   r   r  r*  r   r   r   r   	SomeClass     
 r+  r"  r#  )	r  r	  r$  r%  r*  r&  rR   re   r'  )r   r+  r"  r#  r   r   r   test_copy_classmethod  s    
	

"z$AutoConfigTest.test_copy_classmethodc                    sb   G dd dt }| }|jd}| t|t | |jd | |jt	t
||j d S )Nc                       s.   e Zd Z fddZej fddZ  ZS )z/AutoConfigTest.test_call_super.<locals>.MyClassc                    s   t  dd d S r`   )superr   r(   	__class__r   r   r     s   z8AutoConfigTest.test_call_super.<locals>.MyClass.__init__c                    s   t |t  dS )Nr3   )r   r.  r)   r   r0   r/  r   r   r        z5AutoConfigTest.test_call_super.<locals>.MyClass.my_fn)r   r   r   r   r   r   __classcell__r   r   r/  r   r     s    r   rr   )r$   r   re   rR   r4   r  r   r   r   r5   r.  r)   )r   r   r   r   r/  r   r   test_call_super  s   	 zAutoConfigTest.test_call_superc                    s   dd   fdd} fdd}t j |d|}t  |}ttt dd }ttttdd }| |d| | |d| d S )	Nc                 S   s   t t| S r   )r   r   	max_valuer   r   r   	make_list  rE   z4AutoConfigTest.test_custom_policy.<locals>.make_listc                    s   |  u rdS t | S )NT)r	   r   )r   r7  r   r   custom_policy  s   
z8AutoConfigTest.test_custom_policy.<locals>.custom_policyc                    s   t  | d dS r   ra   r5  r8  r   r   make_sample  s   z6AutoConfigTest.test_custom_policy.<locals>.make_sampleexperimental_exemption_policyr2   )r   r4   r5   r$   r   r   rR   re   )r   r9  r:  with_policywithout_policyexpected_without_policyexpected_with_policyr   r8  r   test_custom_policy  s   
z!AutoConfigTest.test_custom_policyc                 C   sR   t j dd }|d}| |jd | |jjttd | |jjd d S )Nc                 S   s0   t t}tt t| tt| || ddS r   )r   exemptr;   r$   )r6  exempted_funcr   r   r   r:    s   
z9AutoConfigTest.test_inline_exemption.<locals>.make_sampler2   )r   re   rR   r   r   r4   r5   r;   )r   r:  r   r   r   r   test_inline_exemption   s   

z$AutoConfigTest.test_inline_exemptionc                 C   s"   t t}|d}t|t d S r&   )r   rB  r;   pytype_extensionsassert_typer   )r   rC  valuer   r   r   test_exemption_type_inference  s   
z,AutoConfigTest.test_exemption_type_inferencec                 C   s:   t j dd ddd }tjtdd}| | | d S )Nc                 S   r%   )NFr   r6   r   r   r   <lambda>  s    zCAutoConfigTest.test_lambda_supported_in_decorator.<locals>.<lambda>r;  c                   S   s
   t ddS )NrH   r   )r   r   r   r   r   r:    rc   zFAutoConfigTest.test_lambda_supported_in_decorator.<locals>.make_samplerH   rJ  )r   r4   r5   r   rR   re   )r   r:  rU   r   r   r   "test_lambda_supported_in_decorator  s   
z1AutoConfigTest.test_lambda_supported_in_decoratorc                 C   s   t j ddtdtdtfdd}| dt| tjj}tjd|tdtjd|dtdf}tj	|td	}| |t
| | d
|j d S )Nr   r0   r1   c                 S   r   )A docstring.ra   r   r   r   r   my_helpful_function!  r   zBAutoConfigTest.test_function_metadata.<locals>.my_helpful_functionrL  )kind
annotation)rN  r   rO  )return_annotationrM  )r   )r   r   r  r$   rR   inspectgetdoc	ParameterPOSITIONAL_OR_KEYWORD	Signature	signaturer   )r   rM  
param_kindexpected_parametersexpected_signaturer   r   r   test_function_metadata  s&   z%AutoConfigTest.test_function_metadatac                 C   sz   G dd d}| }|  td |di}W d    n1 sw   Y  tjdd }||}| |tj|dd d S )Nc                   @   s4   e Zd ZU dZeed< dd ZdedefddZd	S )
zCAutoConfigTest.test_unhashable_callable.<locals>.UnhashableCallabler@   rr   c                 S   s   | |u S r   r   )r   otherr   r   r   __eq__:  r   zJAutoConfigTest.test_unhashable_callable.<locals>.UnhashableCallable.__eq__r   r1   c                 S   s   |S r   r   )r   r   r   r   r   __call__=  r*   zLAutoConfigTest.test_unhashable_callable.<locals>.UnhashableCallable.__call__N)r   r   r   rr   r   r#   r\  r]  r   r   r   r   UnhashableCallable6  s   
 r^  zunhashable typer@   c                 S   s   | dS r?   r   )objr   r   r   r:  E  r-   z<AutoConfigTest.test_unhashable_callable.<locals>.make_samplerJ  )r|   r   r   re   rR   r4   r5   )r   r^  r_  _r:  r   r   r   r   test_unhashable_callable5  s   



z'AutoConfigTest.test_unhashable_callablec                 C   s   dd }t  d }| tjd}t| W d    n1 s w   Y  | ||jj | d|jj | d|jj tj|ddj	}| d	t
|d | d
t
|d d S )Nc                 S   s   | rt dS t dS )Ntrue branchfalse branchr:   )	conditionr   r   r   r   N  s   z8AutoConfigTest.test_control_flow_if.<locals>.test_configr2   zVControl flow \(If\) is unsupported by auto_config\. \(auto_config_test\.py, line \d+\)z  if condition:r]   Tr  rb  rc  F)rD   r|   r   !UnsupportedLanguageConstructErrorrR   	exceptionlinenotextoffsetre   r4   rw   )r   r   error_line_numbercontextbuild_config_fnr   r   r   test_control_flow_ifL  s&   
z#AutoConfigTest.test_control_flow_ifc                 C   s|   dd }|  tjd t| W d    n1 sw   Y  ttdd tdD }tj|dd }| || d S )	Nc                  S   s*   g } t dD ]
}| t|| qt| S NrH   )r   r   r$   r;   )layersir   r   r   r   j  s   z9AutoConfigTest.test_control_flow_for.<locals>.test_configz4Control flow \(For\) is unsupported by auto_config\.c                 S   s   g | ]	}t t||qS r   )r4   r5   r$   .0rp  r   r   r   
<listcomp>v  s    z8AutoConfigTest.test_control_flow_for.<locals>.<listcomp>rH   Tr  )	r|   r   re  r4   r5   r;   r   re   rR   )r   r   rg   actual_configr   r   r   test_control_flow_forh  s    z$AutoConfigTest.test_control_flow_forc                 C   sh   dd }|  tjd t| W d    n1 sw   Y  tj|dd }| dt| d S )Nc                  S   s$   d} | dkr| d8 } | dkst | S )Nr   r   r@   r:   )rp  r   r   r   r   ~  s
   z;AutoConfigTest.test_control_flow_while.<locals>.test_configz6Control flow \(While\) is unsupported by auto_config\.Tr  r   )r|   r   re  re   rR   r4   rw   )r   r   pass_through_configr   r   r   test_control_flow_while|  s   z&AutoConfigTest.test_control_flow_whilec                   C      t dd dD S )Nc                 S      g | ]}|d  qS r@   r   rq  r   r   r   rs        z+AutoConfigTest.<lambda>.<locals>.<listcomp>r   r:   r   r   r   r   rI        zAutoConfigTest.<lambda>ListCompc                   C   rx  )Nc                 S   s   h | ]}|d  qS rz  r   rq  r   r   r   	<setcomp>  r{  z*AutoConfigTest.<lambda>.<locals>.<setcomp>r   r:   r   r   r   r   rI    r|  SetCompc                   C   rx  )Nc                 S   s   i | ]}|d  dqS r@   Nr   rq  r   r   r   
<dictcomp>      z+AutoConfigTest.<lambda>.<locals>.<dictcomp>r   r:   r   r   r   r   rI    r|  DictCompc                   C   rx  )Nc                 s   s    | ]}|d  V  qdS r  r   rq  r   r   r   	<genexpr>  s    z*AutoConfigTest.<lambda>.<locals>.<genexpr>r   r:   r   r   r   r   rI    r|  GeneratorExpc                   C   s   t t rd S g dS )Nr@   r]   rH   )r;   r   r   r   r   r   rI    s    IfExpc                 C   sl   |  tjd| d t| W d    n1 sw   Y  tj|dd }| g dt| d S )NzControl flow \(z"\) is unsupported by auto_config\.Tr  r  )r|   r   re  re   assertCountEqualr4   rw   )r   r   	node_namerv  r   r   r   test_control_flow_expression  s   
z+AutoConfigTest.test_control_flow_expressionc                 C   s2   t j dddd }| g dt|  d S )NTr  c                   S   s   t dd tdD S )Nc                 S   ry  rz  r   rq  r   r   r   rs    r{  zYAutoConfigTest.test_allow_control_flow_decorator.<locals>.test_config.<locals>.<listcomp>rH   )r;   r   r   r   r   r   r     s   zEAutoConfigTest.test_allow_control_flow_decorator.<locals>.test_configr  r   r   r   r   r   !test_allow_control_flow_decorator  s   

z0AutoConfigTest.test_allow_control_flow_decoratorc                 C   F   dd }|  tjd t| W d    d S 1 sw   Y  d S )Nc                   S   s   zW d S    Y d S r   r   r   r   r   r   r     s   z5AutoConfigTest.test_disallow_try.<locals>.test_configz4Control flow \(Try\) is unsupported by auto_config\.r|   r   re  r   r   r   r   test_disallow_try  s   "z AutoConfigTest.test_disallow_tryc                 C   sR   dd }|  tjd t| W d    n1 sw   Y  tj|dd d S )Nc                   S   s   t d)NzSome message.)r}   r   r   r   r   r     r   z7AutoConfigTest.test_disallow_raise.<locals>.test_configz6Control flow \(Raise\) is unsupported by auto_config\.Tr  r  r   r   r   r   test_disallow_raise  s   z"AutoConfigTest.test_disallow_raisec                 C   r  )Nc                   S   s.   t d	 W d    d S 1 sw   Y  d S )N )openr   r   r   r   r     s   
"z6AutoConfigTest.test_disallow_with.<locals>.test_configz5Control flow \(With\) is unsupported by auto_config\.r  r   r   r   r   test_disallow_with  s   "z!AutoConfigTest.test_disallow_withc                 C   r  )Nc                   s   s    d V  d S r   r   r   r   r   r   r     s   
z7AutoConfigTest.test_disallow_yield.<locals>.test_configz6Control flow \(Yield\) is unsupported by auto_config\.r  r   r   r   r   test_disallow_yield     "z"AutoConfigTest.test_disallow_yieldc                 C   r  )Nc                   s   s    dd t dD E d H  d S )Nc                 s   s    | ]}|V  qd S r   r   rq  r   r   r   r    s    zOAutoConfigTest.test_disallow_yield_from.<locals>.test_config.<locals>.<genexpr>r2   )r   r   r   r   r   r     s   z<AutoConfigTest.test_disallow_yield_from.<locals>.test_configz:Control flow \(YieldFrom\) is unsupported by auto_config\.r  r   r   r   r   test_disallow_yield_from  r  z'AutoConfigTest.test_disallow_yield_fromc                 C   r  )Nc                  S   s   dd } |  S )Nc                   S   r   r   r   r   r   r   r   	nested_fn  r*   zYAutoConfigTest.test_disallow_function_definitions.<locals>.test_config.<locals>.nested_fnr   )r  r   r   r   r     s   zFAutoConfigTest.test_disallow_function_definitions.<locals>.test_configz>Nested function definitions are not supported by auto_config\.r  r   r   r   r   "test_disallow_function_definitions     "z1AutoConfigTest.test_disallow_function_definitionsc                 C   r  )Nc                  S   s   G dd d} |  S )Nc                   @   r   )zXAutoConfigTest.test_disallow_class_definitions.<locals>.test_config.<locals>.NestedClassNr   r   r   r   r   NestedClass  r   r  r   )r  r   r   r   r     s   zCAutoConfigTest.test_disallow_class_definitions.<locals>.test_configz4Class definitions are not supported by auto_config\.r  r   r   r   r   test_disallow_class_definitions  r  z.AutoConfigTest.test_disallow_class_definitionsc                 C   r  )Nc                   S   s   t dd S )Nc                   S   r_   r`   ra   r   r   r   r   rI    s   
 zVAutoConfigTest.test_disallow_lambda_definitions.<locals>.test_config.<locals>.<lambda>r:   r   r   r   r   r     rE   zDAutoConfigTest.test_disallow_lambda_definitions.<locals>.test_configz5Lambda definitions are not supported by auto_config\.r  r   r   r   r    test_disallow_lambda_definitions  r  z/AutoConfigTest.test_disallow_lambda_definitionsc                 C   r  )Nc                      s   d S r   r   r   r   r   r   r     s   zLAutoConfigTest.test_disallow_async_function_definitions.<locals>.test_configz=Async function definitions are not supported by auto_config\.r  r   r   r   r   (test_disallow_async_function_definitions  r  z7AutoConfigTest.test_disallow_async_function_definitionsc                 C   s*   |  tddjtj |  tjtj d S r`   )assertIsInstancer$   r,   r   
AutoConfigr(   r   r   r   'test_access_autoconfig_method_via_class  s   z6AutoConfigTest.test_access_autoconfig_method_via_classz,Enable this after dropping pyhon 3.7 supportc                 C   sF   t dd}| t j|d|dd | t jj|dtt| d S )Nr@   r]   r(   r   r   )r$   rR   r,   r   re   r4   r5   r   r1  r   r   r   test_can_pass_self_as_keyword  s   

z,AutoConfigTest.test_can_pass_self_as_keywordc                 C   s   t   d S r   )r<   re   r(   r   r   r   test_globals$  s   zAutoConfigTest.test_globalsc                 C   s.   dd }t  |}| | ttd d S )Nc                   S   r9   )Nr2   r+   r   r   r   r   rI  .  s    zAAutoConfigTest.test_trailing_paren_after_lambda.<locals>.<lambda>r2   )r   r   re   r4   r5   r   r1  r   r   r    test_trailing_paren_after_lambda*  s   
z/AutoConfigTest.test_trailing_paren_after_lambdac                 C   sn   |  d dd dd f}t|d }t|d }| |dttd | |dttd	 d S )
Nz.multiple lambdas on one line not supported yetc                 S      t d|  S r   r+   ru   r   r   r   rI  5      zBAutoConfigTest.test_multiple_lambdas_on_one_line.<locals>.<lambda>c                 S   r  rn  r+   rv   r   r   r   rI  5  r  r   r@   r         )skipTestr   r   re   r4   r5   r   )r   r0   x0x1r   r   r   !test_multiple_lambdas_on_one_line2  s   
z0AutoConfigTest.test_multiple_lambdas_on_one_linec                 C   s\   t j ddddd }|dg}| t|dtdi |g }| t|i  d S )NFT)*experimental_result_must_contain_buildabler  c                 S   s   dd | D S )Nc                 S   s   i | ]}|t |qS r   r+   )rr  keyr   r   r   r  C  r  zeAutoConfigTest.test_experimental_result_must_contain_buildable.<locals>.make_dict.<locals>.<dictcomp>r   )r   r   r   r   	make_dict<  s   zQAutoConfigTest.test_experimental_result_must_contain_buildable.<locals>.make_dictfoo)r   re   rR   r4   rw   r   )r   r  r   r   r   r   /test_experimental_result_must_contain_buildable;  s   

z>AutoConfigTest.test_experimental_result_must_contain_buildablec                 C   ry   )Nc                  S      t dd} | j}| S r`   r   r   r  r`  r   r   r   fixtureL     
zAAutoConfigTest.test_non_dataclass_attribute_load.<locals>.fixtureCannot load attributer{   r   r  r   r   r   !test_non_dataclass_attribute_loadK  
   

"z0AutoConfigTest.test_non_dataclass_attribute_loadc              	   C   s   dd }t j |dd}t j |dd}| d" | td |  W d    n1 s-w   Y  W d    n1 s<w   Y  | d |  W d    d S 1 sVw   Y  d S )	Nc                  S   r  r`   r"   r   r  r   r   r   r  V     
z=AutoConfigTest.test_dataclass_attribute_load.<locals>.fixtureF-experimental_allow_dataclass_attribute_accessTdisabler  enabler   r$  r|   r}   re   )r   r  fixture_disablefixture_enabler   r   r   test_dataclass_attribute_loadU  s    

"z,AutoConfigTest.test_dataclass_attribute_loadc              	   C   s   t j dd }| d+ | td |  W d    n1 s"w   Y  W d    d S W d    d S 1 s:w   Y  d S )Nc                  S   s   t dd} | jj}t d|S )Nr@   ABCr]   )r   r   lower)r  r  r   r   r   r  j  s   

z:AutoConfigTest.test_nested_attribute_load.<locals>.fixturer  r  r  r  r   r   r   test_nested_attribute_loadi  s   

"z)AutoConfigTest.test_nested_attribute_loadc                 C   ry   )Nc                  S   s   t dd} d| _| S r`   r  r  r   r   r   r  x  r  zAAutoConfigTest.test_non_dataclass_attribute_save.<locals>.fixtureCannot save attributer{   r  r   r   r   !test_non_dataclass_attribute_savew  r  z0AutoConfigTest.test_non_dataclass_attribute_savec              	   C   s   dd }t j |dd}t j |dd}| d" | td |  W d    n1 s-w   Y  W d    n1 s<w   Y  | d | }| |jd	 | |jd
 W d    d S 1 sdw   Y  d S )Nc                  S   s   t dd} d| _| S )Nr@   r]   rH   r  r  r   r   r   r    r  z=AutoConfigTest.test_dataclass_attribute_save.<locals>.fixtureFr  Tr  r  r  rH   r]   )r   r$  r|   r}   re   rR   r   r   )r   r  r  r  r   r   r   r   test_dataclass_attribute_save  s$   
"z,AutoConfigTest.test_dataclass_attribute_savec                 C   sN   t j dddd }| td |  W d    d S 1 s w   Y  d S )NTr  c                  S   s&   t dd} t| d}d|j_t d|S Nr   r  barbaz)r   r"   r   r   r  r  r   r   r   r       


z:AutoConfigTest.test_nested_attribute_save.<locals>.fixturer  r{   r  r   r   r   test_nested_attribute_save  s
   


"z)AutoConfigTest.test_nested_attribute_savec                 C   s2   t j dddd }| }| |jjjd d S )NTr  c                  S   s&   t dd} t | d}d|j_t d|S r  )r"   r   r   r  r   r   r   r    r  zDAutoConfigTest.test_nested_dataclass_attribute_save.<locals>.fixturer  )r   re   rR   r   r   )r   r  r   r   r   r   $test_nested_dataclass_attribute_save  s   

z3AutoConfigTest.test_nested_dataclass_attribute_save)Ir   r   r   rh   ri   rp   rx   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-  r4  rA  rD  rH  rK  rZ  ra  rm  ru  rw  r   r[   r  r  r  r  r  r  r  r  r  r  r  r  r   skipr  r  r  r  r  r  r  r  r  r  r  r  r3  r   r   r/  r   r\      s    

	

	$,












	

r\   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )AutoUnconfigTestc                    sd   t jdddtdtjt fdd t j  fdd}tjtttd	d
dd}| ||  d S )NTr.   r0   r1   c                 S      t t}| |_t| |_|S r   r4   r5   r$   r   r  r   r0   r   r   r   r   r       

z3AutoUnconfigTest.test_simple_inline.<locals>.simplec                         t  dddS Nr'   r2   r   ra   r   r  r   r   parent  r8   z3AutoUnconfigTest.test_simple_inline.<locals>.parentr'   42r2   r   r   auto_unconfigr   r4   r5   r$   rR   re   r   r  rU   r   r  r   test_simple_inline  s   
z#AutoUnconfigTest.test_simple_inlinec                    sb   t jdddtdtjt fdd t j  fdd}tjtt d	d
d}| ||  d S )NFr.   r0   r1   c                 S   r  r   r  r  r   r   r   r    r  z7AutoUnconfigTest.test_simple_not_inline.<locals>.simplec                      r  r  ra   r   r  r   r   r    r8   z7AutoUnconfigTest.test_simple_not_inline.<locals>.parentr'   r2   r   r  r  r   r  r   test_simple_not_inline  s   
z'AutoUnconfigTest.test_simple_not_inlinec                    s   ddifdd t j fdd}| }| | ddd	 | | d
dd	 | | ddd	 t| }| | ddd	 | | ddd	 | | ddd	 d S )Nr   r   c                      r   r   r   r   r   r   r   r     r   z8AutoUnconfigTest.test_arg_factory_counter.<locals>.countc                      s   t tt  S r   )r4   rn   r   r   r   r   r   r   rl     r2  zAAutoUnconfigTest.test_arg_factory_counter.<locals>.test_fn_configr@   r   r   r]   rH   r   r2   r   )r   r  rR   r4   rw   re   r   r   r   r   r     r   z)AutoUnconfigTest.test_arg_factory_counterc                    sT   t jdtdtjt fdd t j  fdd}ttddd	d
}| ||  d S )Nr0   r1   c                 S   r  r   r  r  r   r   r   r    r  z6AutoUnconfigTest.test_python_execution.<locals>.simplec                      r  r  ra   r   r  r   r   r    r8   z6AutoUnconfigTest.test_python_execution.<locals>.parentr'   r  r2   r   r   r  r   r4   r5   r$   rR   r  r   r  r   test_python_execution  s   z&AutoUnconfigTest.test_python_executionc                    sp   t jdtdtjt fdddtffdd t jdtjt f fdd}ttd	d
d}| ||  d S )Nr0   r1   c                 S   r  r   r  r  r   r   r   r    r  z=AutoUnconfigTest.test_nested_python_execution.<locals>.simplec                    s    | d S r?   r   r6   r  r   r   regular_python_wrapper  rE   zMAutoUnconfigTest.test_nested_python_execution.<locals>.regular_python_wrapperc                     s"   t t} t  d| _d| _| S )Nr'   r2   )r4   r5   r$   r   r   )r   )r  r   r   r    s   
z=AutoUnconfigTest.test_nested_python_execution.<locals>.parent)   41r2   r  r  r   )r  r  r   test_nested_python_execution  s   z-AutoUnconfigTest.test_nested_python_executionN)r   r   r   r  r  r   r  r  r   r   r   r   r    s    r  c                   @   sP   e Zd Zdd Zdd Zdd Zdd Zed	d
d Z	eddd Z
dS )
InlineTestc                 C   s   t j dtdtfdd}tj|ddd}t|}t | | tt	| | |j
d | |jtj | tt	|j | d|jj | |t| d S )Nr0   r   c                 S   s   t t| |S r   r   r   r   r   r   r     rm   z%InlineTest.test_simple.<locals>.my_fnr   r   )r   r   r  r4   r5   rw   inlinerR   r$   r  r   r  r   r   r   )r   r   r   origr   r   r   test_simple  s   

zInlineTest.test_simplec                 C   s|   t jG dd d}tj|jdd}t|}t| | |t	| | |j
d | |jd | |t| d S )Nc                   @   r)  )z:InlineTest.test_bound_auto_config.<locals>.AutoConfigClassr0   r   c                 S   s   | ||d S r   r   )r  r  r   r   r   r   ,  r   zBInlineTest.test_bound_auto_config.<locals>.AutoConfigClass.defaultN)r   r   r   r   r#   r   r  r   r   r   r   r   AutoConfigClass'  r,  r  r2   )r     )r  r	  r4   r5   r   rw   r   r  rR   r  r0   r   )r   r  r   r  r   r   r   test_bound_auto_config%  s   	

z!InlineTest.test_bound_auto_configc                    sH   t j dd  t j  fdd}tjtddd}| }| || d S )Nc                   S   r   )Nr@   r]   r   ra   r   r   r   r   
inlined_fn<  r   zAInlineTest.test_always_inline_default_is_true.<locals>.inlined_fnc                      s     S r   r   r   r  r   r   
calling_fn@  s   zAInlineTest.test_always_inline_default_is_true.<locals>.calling_fnr@   r]   r   )r   r4   r5   r$   re   rR   )r   r  rg   rt  r   r  r   "test_always_inline_default_is_true:  s   
z-InlineTest.test_always_inline_default_is_truec                    s   t j dddtdtdtfdd t j  fdd	}tjttjtd
dt d
dd}| }| || t 	|j
 tjttjtd
dttddd}| || d S )NFr.   r0   r   r1   c                 S   s   t | d d| dS )aW  A function that forms a configuration API boundary.

      These functions are often vended by libraries.

      Args:
       x: A sample argument to be configured.
       y: An additional argument to be configured.

      Returns:
        An instance of the sample class configured per the policy encapsulated
        by this function.
      r@   zHello r   ra   r   r   r   r   make_library_typeJ  s   zAInlineTest.test_inlining_nested_config.<locals>.make_library_typec                     s   t dd}  dd}t| |S )Nr2   r>   world)r   r$   )thing1thing2r  r   r   make_experimentZ  s   


z?InlineTest.test_inlining_nested_config.<locals>.make_experimentr2   r>   r  r   r   zHello world)r   r   r  r$   r4   r5   r   re   rR   r  r   )r   r  rg   rt  inline_expected_configr   r  r   test_inlining_nested_configH  s$   
z&InlineTest.test_inlining_nested_configz:Cannot inline a function that returns a partial currently.c                 C   sf   t j dtfdd}tj|dd}t | tjtdd}| || | t	|dtdd d S )Nr0   c                 S   s   t jt| dS )NrJ  rz   r6   r   r   r   r   w  rm   z;InlineTest.test_inlined_func_returns_partial.<locals>.my_fnr]   r6   rJ  r   )
r   r   r4   r5   r  rn   r$   r   rR   rw   )r   r   r   rU   r   r   r   !test_inlined_func_returns_partialt  s   
 z,InlineTest.test_inlined_func_returns_partialz6Cannot inline a function that returns a non-buildable.c                 C   s0   t j dtfdd}tj|dd}t | d S )Nr0   c                 S   s   t | | t | d | d gS r`   ra   r6   r   r   r   r     s   z8InlineTest.test_inlined_func_returns_list.<locals>.my_fnr]   r6   )r   r   r4   r5   r  )r   r   r   r   r   r   test_inlined_func_returns_list  s   z)InlineTest.test_inlined_func_returns_listN)r   r   r   r  r  r  r  r   r  r  r  r   r   r   r   r    s    ,
r  __main__)r   )-r  rO   r%  r  rj   rQ  rA   typingr   r   absl.testingr   r   fiddler4   r   fiddle._src.experimentalr   r	   r
   r   fiddle._src.testingr   rE  r   r   r   r	  r"   r$   r  r   r5   r7   r<   r=   r;   rD   TestCaserF   r\   r  r  r   mainr   r   r   r   <module>   sZ   




h       gd{