o
    i e                     @   s&  d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlZddl	m
  mZ ddlmZ ddlmZ ddlmZ ej
j  ddlZejZed	dd
 eddd eddd ed	dg eddg dZdd Zdd Zdd ZG dd dejjZ dd Z!e"dkre#  dS dS )zRun doctests for tensorflow.    )absolute_import)division)print_functionN)flags)absltest)keras_doctest_libmodulez$A specific module to run doctest on.listz2List all the modules in the core package imported.filez"A specific file to run doctest on.zkeras.c                  C   s0   g } t j D ]\}}|tr| | q| S )zFinds all the modules in the core package imported.

    Returns:
      A list containing all the modules in tensorflow.python.
    )sysmodulesitems
startswithPACKAGEappend)
tf_modulesnamer    r   L/var/www/myenv/lib/python3.10/site-packages/keras/src/tests/keras_doctest.pyfind_modules3   s   

r   c                    s    fdd| D }|S )a  Filters all the modules based on the module flag.

    The module flag has to be relative to the core package imported.
    For example, if `submodule=keras.layers` then, this function will return
    all the modules in the submodule.

    Args:
      all_modules: All the modules in the core package.
      submodule: Submodule to filter from all the modules.

    Returns:
      All the modules in the submodule.
    c                    s   g | ]}t   |jv r|qS r   )r   __name__).0mod	submoduler   r   
<listcomp>Q   s    z(filter_on_submodules.<locals>.<listcomp>r   )all_modulesr   filtered_modulesr   r   r   filter_on_submodulesB   s   
r   c                 C   s   t j| } | tdt j}t j| |d \}}tj	|t jd }t
| d}| }W d   n1 s:w   Y  ||_|gS )zReplaces the docstring of the module with the changed file's content.

    Args:
      file_path: Path to the file

    Returns:
      A list containing the module changed by the file.
    .Nr)ospathabspathfindr   replacesepsplitextr   r   openread__doc__)	file_path	mod_indexfile_mod_name_file_modulefcontentr   r   r   get_module_and_inject_docstringW   s   

r2   c                   @   s   e Zd Zdd Zdd ZdS )
TfTestCasec                 C      |    d S N)setUpselfr.   r   r   r   set_upo      zTfTestCase.set_upc                 C   r4   r5   )tearDownr7   r   r   r   	tear_downr   r:   zTfTestCase.tear_downN)r   
__module____qualname__r9   r<   r   r   r   r   r3   n   s    r3   c                 C   s   t  }tjrt|tj}tjr#td |D ]}t|j qtd |S tjr+ttj}|D ]*}t	 }|
tj|tjddtttd|j|jt tjtjB tjB tjB d q-|S )z4Loads all the tests in the docstrings and runs them.z2**************************************************F)exclude_empty)tfnpr!   )test_finder
extraglobsr6   r;   checkeroptionflags)r   FLAGSr   r   r	   printr   r
   r2   r3   addTestsdoctestDocTestSuiteDocTestFinderr@   rA   r!   r9   r<   r   KerasDoctestOutputCheckerELLIPSISNORMALIZE_WHITESPACEIGNORE_EXCEPTION_DETAILDONT_ACCEPT_BLANKLINE)unused_loadertestsunused_ignorer   r   r   testcaser   r   r   
load_testsv   s>   


rU   __main__)$r*   
__future__r   r   r   r!   r   numpyrA   tensorflow.compat.v2compatv2r@   abslr   absl.testingr   keras.src.testing_infrar   v1enable_v2_behaviorrI   rF   DEFINE_stringDEFINE_booleanmark_flags_as_mutual_exclusiver   r   r   r2   testTestCaser3   rU   r   mainr   r   r   r   <module>   s<   '