o
    JAf	  ã                   @   s   d Z ddlZddd„ZdS )z"Utilities for testing with Tkinteré    Né   c                    s   ‡ fdd„}|S )a£  Decorator for running a test method with a real Tk mainloop.

    This starts a Tk mainloop before running the test, and stops it
    at the end. This is faster and more robust than the common
    alternative method of calling .update() and/or .update_idletasks().

    Test methods using this must be written as generator functions,
    using "yield" to allow the mainloop to process events and "after"
    callbacks, and then continue the test from that point.

    The delay argument is passed into root.after(...) calls as the number
    of ms to wait before passing execution back to the generator function.

    This also assumes that the test class has a .root attribute,
    which is a tkinter.Tk object.

    For example (from test_sidebar.py):

    @run_test_with_tk_mainloop()
    def test_single_empty_input(self):
        self.do_input('
')
        yield
        self.assert_sidebar_lines_end_with(['>>>', '>>>'])
    c                    s   t  ˆ ¡‡‡ fdd„ƒ}|S )Nc                    sJ   ˆ| ƒ‰| j ‰d ‰‡ ‡‡‡‡fdd„‰ ˆ dˆjˆ ¡ ˆ ¡  ˆr#ˆ‚d S )Nc               
      sn   zt ˆƒ W n& ty   ˆ ¡  Y d S  ty, }  z| ‰ˆ ¡  W Y d } ~ d S d } ~ ww ˆ ˆˆjˆ ¡ d S )N)ÚnextÚStopIterationÚquitÚ	ExceptionÚafterÚ
after_idle)Úexc)Úafter_callbackÚdelayÚ	exceptionÚrootÚtest_generator© ú>/usr/lib/python3.10/idlelib/idle_test/tkinter_testing_utils.pyr
   '   s   €þzVrun_in_tk_mainloop.<locals>.decorator.<locals>.new_test_method.<locals>.after_callbackr   )r   r   r   Zmainloop)Úself)r   Útest_method)r
   r   r   r   r   Únew_test_method   s   ÿz>run_in_tk_mainloop.<locals>.decorator.<locals>.new_test_method)Ú	functoolsÚwraps)r   r   ©r   )r   r   Ú	decorator   s   z%run_in_tk_mainloop.<locals>.decoratorr   )r   r   r   r   r   Úrun_in_tk_mainloop   s    r   )r   )Ú__doc__r   r   r   r   r   r   Ú<module>   s    