
    0h                     2   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
c mZ ddlmZ ddlmZ ddlmZ ej                  j&                  j)                          ddlZej,                  Z ej.                  d	dd
        ej0                  ddd        ej.                  ddd        ej2                  d	dg        ej2                  ddg       dZd Zd Zd Z G d dej<                  j>                        Z d Z!e"dk(  r ejF                          yy)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                      g } t         j                  j                         D ],  \  }}|j                  t              s| j                  |       . | 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	   s      Z/var/www/html/engine/venv/lib/python3.12/site-packages/tf_keras/src/tests/keras_doctest.pyfind_modulesr   3   sK     J))+ &f??7#f%&     c                 Z    | D cg c]  }t         |z   |j                  v s| }}|S c c}w )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.
    )r   __name__)all_modules	submodulemodfiltered_moduless       r   filter_on_submodulesr   B   s<      #g	&9S\\&I  s   ((c                    t         j                  j                  |       } | j                  t        j                  dt         j                              }t         j                  j                  | |d       \  }}t        j                  |j                  t         j                  d         }t        | d      5 }|j                         }ddd       |_        |gS # 1 sw Y   xY w)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contents          r   get_module_and_inject_docstringr3   W   s     	*IwsBFF;<Iww''	)*(=>M1++m33BFFC@AK	i	 &&( "K= s   5CC!c                       e Zd Zd Zd Zy)
TfTestCasec                 $    | j                          y N)setUpselfr/   s     r   set_upzTfTestCase.set_upo   s    

r   c                 $    | j                          y r7   )tearDownr9   s     r   	tear_downzTfTestCase.tear_downr   s    r   N)r   
__module____qualname__r;   r>    r   r   r5   r5   n   s    r   r5   c                    t               }t        j                  rt        |t        j                        }t        j                  r4t        d       |D ]  }t        |j                          t        d       |S t        j                  rt        t        j                        }|D ]  }t               }|j                  t        j                  |t        j                  d      t        t        t         d|j"                  |j$                  t'        j(                         t        j*                  t        j,                  z  t        j.                  z  t        j0                  z                |S )z4Loads all the tests in the docstrings and runs them.z2**************************************************F)exclude_empty)tfnpr"   )test_finder
extraglobsr8   r=   checkeroptionflags)r   FLAGSr	   r   r
   printr   r   r3   r5   addTestsdoctestDocTestSuiteDocTestFinderrD   rE   r"   r;   r>   r   KerasDoctestOutputCheckerELLIPSISNORMALIZE_WHITESPACEIGNORE_EXCEPTION_DETAILDONT_ACCEPT_BLANKLINE)unused_loadertestsunused_ignorer   r   r	   testcases          r   
load_testsrY   v   s    J||)*ellC
zzBC 	 C#,,	 BCzz4UZZ@
 
<  #11F"$Bb9oo!++)CCE$$223556 334	

$ Lr   __main__)$r+   
__future__r   r   r   r"   r   numpyrE   tensorflow.compat.v2compatv2rD   abslr   absl.testingr   tf_keras.src.testing_infrar   v1enable_v2_behaviorrM   rJ   DEFINE_stringDEFINE_booleanmark_flags_as_mutual_exclusiver   r   r   r3   testTestCaser5   rY   r   mainrA   r   r   <module>rk      s   # &  % 	 
  ! !  ! 8 		   !    Hd$J K   
DF   FD"F G $ $ $h%7 8 $ $ $ff%5 6
*.!! $N zHMMO r   