o
    YiM,                  
   @   s  d dl mZ d dlZd dlZd dlmZ d dlZd dlZd dl	m
Z
mZ d dlmZmZmZmZ d dlmZmZmZmZ ejdd Zejd	d
 Zejdd Zdd Zdd Zdd Zejdd Zdd Zdd Zdd Z dd Z!dd Z"dd  Z#ej$%d!d"efd#efd$efeefeefeefgd%d& Z&d'd( Z'd)d* Z(d+d, Z)d-d. Z*ej$%d/d"efd#efd$efeefeefeefgd0d1 Z+d2d3 Z,ejd4d5 Z-ejd6d7 Z.ejd8d9 Z/d:d; Z0d<d= Z1d>d? Z2d@dA Z3ej$%d!d"efd#efd$efeefeefeefgdBdC Z4dDdE Z5ej$%d/d"efd#efd$efeefeefeefgdFdG Z6ejdHdI Z7dJdK Z8dLdM Z9ejdNdO Z:dPdQ Z;ejdRdS Z<ejdTdU Z=dVdW Z>dXdY Z?dZd[ Z@ej$%d\d]d^gd_d` ZAej$%d\d]d^gdadb ZBdS )c    )absolute_importN)GeneratorType)flatten	unflatten)tuple_reducerpath_reducerunderscore_reducermake_reducer)tuple_splitterpath_splitterunderscore_splittermake_splitterc                   C   s   ddddddddddS 	N01.01.1ab2.02.1.02.1.1r   r   c r   r   r   X/home/ubuntu/.local/lib/python3.10/site-packages/flatten_dict/tests/flatten_dict_test.pynormal_dict   s   r   c                   C   s   dddddddS )Nr   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   flat_tuple_dict+   s   r#   c                   C   s   ddddddddS )	Nr   r   r   r   r   r   r   r   r   r   r    )r   r   r   r   r   r   r   flat_tuple_dict_depth27   s   r%   c                 C   s   | S Nr   r#   r   r   r   get_flat_tuple_dictB   s   r(   c                 C      dd t | D S )Nc                 S   s   i | ]\}}t jj| |qS r   )ospathjoin.0kvr   r   r   
<dictcomp>G   s    z&get_flat_path_dict.<locals>.<dictcomp>six	viewitemsr'   r   r   r   get_flat_path_dictF      r5   c                 C   r)   )Nc                 S   s   i | ]
\}}d  ||qS )_)r,   r-   r   r   r   r1   K   s    z,get_flat_underscore_dict.<locals>.<dictcomp>r2   r'   r   r   r   get_flat_underscore_dictJ   r6   r8   c                 C   r)   )Nc                 S   s   i | ]\}}||qS r   r   r-   r   r   r   r1   P   s    z'inv_flat_tuple_dict.<locals>.<dictcomp>r2   r'   r   r   r   inv_flat_tuple_dictN   s   r9   c                 C      t | |ksJ d S r&   r   r   r#   r   r   r   test_flatten_dictS   r6   r=   c                 C   s<   t t t| dd W d    d S 1 sw   Y  d S )Nr   max_flatten_depthpytestraises
ValueErrorr   )r   r   r   r   %test_flatten_dict_invalid_depth_limitW   s   "rD   c                 C   sD   t | dd}t| dd d}t|  dd d}||ks J d S )N   r>   c                 S      t j| ddS NT)	sort_keysjsondumpsxr   r   r   <lambda>_       z1test_flatten_dict_depth_limit_1.<locals>.<lambda>keyc                 S   rF   rG   rI   rL   r   r   r   rN   b   rO   )r   sortedvalues)r   	flattenedvalues_beforevalues_afterr   r   r   test_flatten_dict_depth_limit_1\   s   rW   c                 C      t | dd|ks
J d S N   r>   r;   )r   r%   r   r   r   test_flatten_dict_depth_limit_2g      r[   c                 C   rX   N   r>   r;   r<   r   r   r   (test_flatten_dict_irrelevant_depth_limitk   r\   r_   c                   C   s8   t t tg  W d    d S 1 sw   Y  d S r&   r@   r   r   r   r    test_flatten_nonflattenable_typeo   s   
"r`   z reducer, expected_flat_dict_functupler+   
underscorec                 C       ||}t | |d|ksJ d S N)reducerr;   )r   r#   re   expected_flat_dict_funcexpected_flat_dictr   r   r   test_flatten_dict_with_reducert      rh   c                 C   rX   NTinverser;   r   r9   r   r   r   test_flatten_dict_inverse   r\   rn   c                 C   sL   |   }d|d< tt t|dd W d    d S 1 sw   Y  d S )Nr   r   Trk   )copyrA   rB   rC   r   )r   dup_val_dictr   r   r   /test_flatten_dict_inverse_with_duplicated_value   s
   "rq   c                 C      t || ksJ d S r&   r   r<   r   r   r   test_unflatten_dict   r6   rt   c                 C   s   t |dd| ks
J d S rj   rs   rm   r   r   r   test_unflatten_dict_inverse   r\   ru   zsplitter, flat_dict_funcc                 C       ||}t ||d| ksJ d S N)splitterrs   )r   r#   rx   flat_dict_func	flat_dictr   r   r   !test_unflatten_dict_with_splitter   ri   r{   c                 C   sD   d|d< t t t|dd W d    d S 1 sw   Y  d S )Nr!   r   Trk   )rA   rB   rC   r   )r#   r9   r   r   r   1test_unflatten_dict_inverse_with_duplicated_value   s   "r|   c                   C   s$   ddddddddgg d	dd	S )
Nr   r   r   r   r   r   2.1.1.02.1.1.1r   r   r   r   r   r   dict_with_list   s   r   c                   C   s   dddddddgg dS )	Nr   r   r   r   r   r}   r~   r   r   r   r    r!   r"   )r   r   r   r   r   r   r   r   flat_tuple_dict_with_list   s   r   c                   C   s   dddddddgg dd	S )
Nr   r   r   r   r   r}   r~   r   r$   r   r   r   r   r    flat_tuple_dict_with_list_depth2   s   r   c                 C   r:   r&   r;   r   r   r   r   r   test_flatten_dict_with_list   r6   r   c                 C   sR   t | dd}t|  dd d}t| dd d}dd |D }||ks'J d S )	NrE   r>   c                 S      | d S Nr   r   rL   r   r   r   rN          z;test_flatten_dict_with_list_depth_limit_1.<locals>.<lambda>rP   c                 S   r   r   r   rL   r   r   r   rN      r   c                 S   s    g | ]}|d  d  |d fqS )r   rE   r   )r.   rM   r   r   r   
<listcomp>   s     z=test_flatten_dict_with_list_depth_limit_1.<locals>.<listcomp>)r   rR   items)r   rT   beforeafterr   r   r   )test_flatten_dict_with_list_depth_limit_1   s
   r   c                 C   rX   rY   r;   )r   r   r   r   r   )test_flatten_dict_with_list_depth_limit_2   s   r   c                 C   rX   r]   r;   r   r   r   r   2test_flatten_dict_with_list_irrelevant_depth_limit   s   r   c                 C   rc   rd   r;   )r   r   re   rf   rg   r   r   r   (test_flatten_dict_with_list_with_reducer   ri   r   c                 C   rr   r&   rs   r   r   r   r   test_unflatten_dict_with_list  r6   r   c                 C   rv   rw   rs   )r   r   rx   ry   rz   r   r   r   +test_unflatten_dict_with_list_with_splitter  ri   r   c                   C   s   ddddddddS )	Nr   r   r   r   r   r}   r~   )r   r   r   r    r!   )r   r   r   r   )r   r   r   rE   r   r   r   r   r   $flat_tuple_dict_with_enumerated_list%     r   c                 C      t | tfd|ksJ d S Nenumerate_typesr   list)r   r   r   r   r   0test_flatten_dict_with_list_with_enumerate_types2     r   c                   C   s$   t ddgtfddddksJ d S )NrE   rZ   r   ))r   )rE   r   r   r   r   r   test_flatten_list;  s   $r   c                   C   s8   dddddddd t d	D d
d dD dddS )Nr   r   r   r   r   r   c                 s   s    | ]}d | V  qdS )z2.1.1.%dNr   r.   ir   r   r   	<genexpr>K  s    z&dict_with_generator.<locals>.<genexpr>rZ   c                 s   s    | ]}|V  qd S r&   r   r   r   r   r   r   L  s    r   r   )ranger   r   r   r   dict_with_generator?  s   r   c                 C   r   r   )r   r   )r   r   r   r   r   5test_flatten_dict_with_generator_with_enumerate_typesR  r   r   c                   C   s    dddddddi dddS r   r   r   r   r   r   dict_with_empty_dict[  s   r   c                   C   s   ddddddi dS )Nr   r   r   r   r   r   r   r   r   r   r   r   flat_tuple_dict_with_empty_dictn  r   r   c                 C   r:   r&   r;   )r   r#   r   r   r   !test_flatten_dict_with_empty_dict{  r6   r   c                 C   r   N)keep_empty_types)r   dict)r   r   r   r   r   &test_flatten_dict_with_empty_dict_kept  r   r   c                 C   s   t | ttfd|ksJ d S r   )r   r   strr<   r   r   r   'test_flatten_dict_with_keep_empty_types  s   r   zdelimiter, delimiter_equivalent).dot)r7   rb   c                 C   s0   t |}t| |d}t| |d}||ksJ d S rd   )r	   r   )r   	delimiterdelimiter_equivalentre   !flattened_dict_using_make_reducer'flattened_dict_using_equivalent_reducerr   r   r   test_make_reducer  s   r   c                 C   s:   t |}t| |}t||d}t||d}||ksJ d S rw   )r   r   r   )r   r   r   rx   rz   $unflattened_dict_using_make_splitter*unflattened_dict_using_equivalent_splitterr   r   r   test_make_splitter  s   
r   )C
__future__r   os.pathr*   rJ   typesr   r3   rA   flatten_dictr   r   flatten_dict.reducersr   r   r   r	   flatten_dict.splittersr
   r   r   r   fixturer   r#   r%   r(   r5   r8   r9   r=   rD   rW   r[   r_   r`   markparametrizerh   rn   rq   rt   ru   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   <module>   s    









	


	
	

	
	