
    j/                         d 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mZ dee	         ddfdZd	ed
edefdZdedefdZdee         deej                 fdZdS )z!Utilities that ease unit-testing.    N)ListOptional)Element)elements_from_jsonelements_to_jsonelementsreturnc                     t          |           }|J t          |          }t          |          }|J ||k    sJ t          d||                      dS )ab  Raises AssertionError if `elements -> JSON -> List[Element] -> JSON` are not equal.

    The procedure is:

        1. Serialize `elements` to (original) JSON.
        2. Deserialize that JSON to `List[Element]`.
        3. Serialize that `List[Element]` to JSON.
        3. Compare the original and round-tripped JSON, raise if they are different.

    N)textzJSON differs:)r   r   _diff)r   original_jsonround_tripped_elementsround_tripped_jsons       f/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/test_unstructured/unit_utils.pyassert_round_trips_through_JSONr      sz     %X..M$$$/]CCC)*@AA)))...+]1 1.....    headingactualexpectedc                     |                     d          }|                     d          }d} | d                    t          j                                        ||                    z   S )z~Diff of actual compared to expected.

    "+" indicates unexpected lines actual, "-" indicates lines missing from actual.
    T)keependszFdiff: '+': unexpected lines in actual, '-': lines missing from actual
 )
splitlinesjoindifflibDiffercompare)r   r   r   expected_linesactual_liness        r   r   r   $   sd    
 (($(77N$$d$33LWGRWWW^--55lNSSTTTTr   	file_namec                     t          j        t                    j        j        dz  }|| z  }t	          |                                          S )zGResolve the absolute-path to `file_name` in the example-docs directory.zexample-docs)pathlibPath__file__parentstrresolve)r    example_docs_dir	file_paths      r   example_doc_pathr*   /   sA    |H--4;nL 9,Iy  ""###r   datetime_strc                 H    | rt           j                            |           ndS )zWParse `datetime_str` to a datetime.datetime instance or None if `datetime_str` is None.N)dtdatetimefromisoformat)r+   s    r   parse_optional_datetimer0   6   s"    6BL2;$$\222Lr   )__doc__r.   r-   r   r"   typingr   r   unstructured.documents.elementsr   unstructured.staging.baser   r   r   r&   r   r*   r0    r   r   <module>r6      s"   ' '       ! ! ! ! ! ! ! ! 3 3 3 3 3 3 J J J J J J J Jd7m     0U3 U Us U U U U$ $ $ $ $ $M(3- MHR[<Q M M M M M Mr   