Your IP : 18.222.182.226


Current Path : /opt/alt/python36/lib64/python3.6/idlelib/idle_test/__pycache__/
Upload File :
Current File : //opt/alt/python36/lib64/python3.6/idlelib/idle_test/__pycache__/mock_tk.cpython-36.pyc

3

� fk-�@shdZGdd�d�ZGdd�d�ZGdd�d�ZGdd�d�Zd	d
lmZGdd�d�ZGd
d�d�ZdS)z�Classes that replace tkinter gui objects used by an object being tested.

A gui object is anything with a master or parent parameter, which is
typically required in spite of what the doc strings say.
c@seZdZdZdd�ZdS)�Eventa�Minimal mock with attributes for testing event handlers.

    This is not a gui object, but is used as an argument for callbacks
    that access attributes of the event passed. If a callback ignores
    the event, other than the fact that is happened, pass 'event'.

    Keyboard, mouse, window, and other sources generate Event instances.
    Event instances have the following attributes: serial (number of
    event), time (of event), type (of event as number), widget (in which
    event occurred), and x,y (position of mouse). There are other
    attributes for specific events, such as keycode for key events.
    tkinter.Event.__doc__ has more but is still not complete.
    cKs|jj|�dS)z,Create event with attributes needed for testN)�__dict__�update)�self�kwds�r�>/opt/alt/python36/lib64/python3.6/idlelib/idle_test/mock_tk.py�__init__szEvent.__init__N)�__name__�
__module__�__qualname__�__doc__rrrrrrs
rc@s*eZdZdZd	dd�Zdd�Zdd�ZdS)
�Varz)Use for String/Int/BooleanVar: incompleteNcCs||_||_||_dS)N)�master�value�name)rrrrrrrrszVar.__init__cCs
||_dS)N)r)rrrrr�setszVar.setcCs|jS)N)r)rrrr�get!szVar.get)NNN)r	r
rrrrrrrrrr
s
r
c@s"eZdZdZddd�Zdd�ZdS)�	Mbox_funcaGeneric mock for messagebox functions, which all have the same signature.

    Instead of displaying a message box, the mock's call method saves the
    arguments as instance attributes, which test functions can then examime.
    The test can set the result returned to ask function
    NcCs
||_dS)N)�result)rrrrrr+szMbox_func.__init__cOs||_||_||_||_|jS)N)�title�message�argsrr)rrrrrrrr�__call__-s
zMbox_func.__call__)N)r	r
rrrrrrrrr$s
rc@s@eZdZdZe�Ze�Ze�Ze�Ze�Z	e�Z
e�Ze�ZdS)�Mboxa5Mock for tkinter.messagebox with an Mbox_func for each function.

    This module was 'tkMessageBox' in 2.x; hence the 'import as' in  3.x.
    Example usage in test_module.py for testing functions in module.py:
    ---
from idlelib.idle_test.mock_tk import Mbox
import module

orig_mbox = module.tkMessageBox
showerror = Mbox.showerror  # example, for attribute access in test methods

class Test(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        module.tkMessageBox = Mbox

    @classmethod
    def tearDownClass(cls):
        module.tkMessageBox = orig_mbox
    ---
    For 'ask' functions, set func.result return value before calling the method
    that uses the message function. When tkMessageBox functions are the
    only gui alls in a method, this replacement makes the method gui-free,
    N)
r	r
rrrZaskokcancelZaskquestionZaskretrycancelZaskyesnoZaskyesnocancelZ	showerrorZshowinfo�showwarningrrrrr5sr�)�TclErrorc@s�eZdZdZdifdd�Zdd�Zd"dd	�Zd
d�Zdd
�Zd#dd�Z	d$dd�Z
dd�Zdd�Zdd�Z
d%dd�Zdd�Zdd�Zdd�Zd&d d!�ZdS)'�Texta�A semi-functional non-gui replacement for tkinter.Text text editors.

    The mock's data model is that a text is a list of 
-terminated lines.
    The mock adds an empty string at  the beginning of the list so that the
    index of actual lines start at 1, as with Tk. The methods never see this.
    Tk initializes files with a terminal 
 that cannot be deleted. It is
    invisible in the sense that one cannot move the cursor beyond it.

    This class is only tested (and valid) with strings of ascii chars.
    For testing, we are not concerned with Tk Text's treatment of,
    for instance, 0-width characters or character + accent.
   NcKsddg|_dS)z�Initialize mock, non-gui, text-only Text widget.

        At present, all args are ignored. Almost all affect visual behavior.
        There are just a few Text-only options that affect text behavior.
        ��
N)�data)rrZcnf�kwrrrrgsz
Text.__init__cCsd|j|dd�S)zAReturn string version of index decoded according to current text.z%s.%s�)�endflag)�_decode)r�indexrrrr%osz
Text.indexrcCst|ttf�rt|�}y|j�}Wn"tk
rDtd|�d�YnXt|j�d}|dkrr|t|j|�dfS|dkr�|j	|�S|j
d�\}}t|�}|dkr�d	S||kr�|j	|�St|j|�d}|jd�s�|dkr�||fSt|�}|dk�r�d}n||k�r
|}||fS)
a8Return a (line, char) tuple of int indexes into self.data.

        This implements .index without converting the result back to a string.
        The result is constrained by the number of lines and linelengths of
        self.data. For many indexes, the result is initially (1, 0).

        The input index may have any of several possible forms:
        * line.char float: converted to 'line.char' string;
        * 'line.char' string, where line and char are decimal integers;
        * 'line.char lineend', where lineend='lineend' (and char is ignored);
        * 'line.end', where end='end' (same as above);
        * 'insert', the positions before terminal 
;
        * 'end', whose meaning depends on the endflag passed to ._endex.
        * 'sel.first' or 'sel.last', where sel is a tag -- not implemented.
        zbad text index "%s"Nr"�insert�end�.rz lineend)r"r)
�
isinstance�float�bytes�str�lower�AttributeErrorr�lenr �_endex�split�int�endswith)rr%r#Zlastline�line�charZ
linelengthrrrr$ss4



zText._decodecCs<t|j�}|dkr|dfS|d8}|t|j|�|fSdS)aReturn position for 'end' or line overflow corresponding to endflag.

       -1: position before terminal 
; for .insert(), .delete
       0: position after terminal 
; for .get, .delete index 1
       1: same viewed as beginning of non-existent next line (for .index)
       r"rN)r/r )rr#�nrrrr0�s

zText._endexcCs�|sdS|jd�}|dddkr,|jd�|j|d	�\}}|j|d|�}|j||d�}||d|j|<|dd�|j|d|d�<|j|t|�d|7<dS)
z+Insert chars before the character at index.NTr"rrr���r7r7)�
splitlines�appendr$r r/)rr%�charsr4r5Zbefore�afterrrrr&�s

zText.insertc	Cs�|j|�\}}|dkr&||d}}n|j|�\}}||krN|j|||�S|j||d�g}x&t|d|�D]}|j|j|�qrW|j|j|d|��dj|�SdS)z;Return slice from index1 to index2 (default is 'index1+1').Nr"r)r$r �ranger9�join)	r�index1�index2�	startline�	startchar�endline�endchar�lines�irrrr�szText.getcCs|j|d�\}}|dkrf|t|j|�dkr>||d}}qv|t|j�dkr`|dd}}qvdSn|j|d�\}}||kr�||kr�|j|d|�|j||d�|j|<n^||k�r|j|d|�|j||d�|j|<|d7}x t||d�D]}|j|=�q�WdS)z�Delete slice from index1 to index2 (default is 'index1+1').

        Adjust default index2 ('index+1) for line ends.
        Do not delete the terminal 
 at the very end of self.data ([-1][-1]).
        r"Nrr7r7)r$r/r r<)rr>r?r@rArBrCrErrr�delete�s"
zText.deletecCs�|j|�\}}|j|�\}}|dkr<||kp:||ko:||kS|dkr\||kpZ||koZ||kS|dkr|||kpz||koz||kS|dkr�||kp�||ko�||kS|dkr�||ko�||kS|dkr�||kp�||kStd|��dS)N�<z<=�>z>=z==z!=z=bad comparison operator "%s": must be <, <=, ==, >=, >, or !=)r$r)rr>�opr?Zline1Zchar1Zline2Zchar2rrr�compare�s zText.comparecCsdS)z.Set mark *name* before the character at index.Nr)rrr%rrr�mark_set
sz
Text.mark_setcGsdS)zDelete all marks in markNames.Nr)rZ	markNamesrrr�
mark_unsetszText.mark_unsetcCsdS)zARemove tag tagName from all characters between index1 and index2.Nr)rZtagNamer>r?rrr�
tag_removeszText.tag_removecCsdS)z2Adjust the view of the text according to scan_markNr)r�x�yrrr�scan_dragtoszText.scan_dragtocCsdS)z&Remember the current X, Y coordinates.Nr)rrNrOrrr�	scan_markszText.scan_markcCsdS)z8Scroll screen to make the character at INDEX is visible.Nr)rr%rrr�see!szText.seecCsdS)z>Bind to this widget at event sequence a call to function func.Nr)Zsequence�func�addrrr�bind(sz	Text.bind)r)N)N)N)NNN)r	r
rrrr%r$r0r&rrFrJrKrLrMrPrQrRrUrrrrrZs 
3


rc@seZdZdZdd�ZdS)�EntryzMock for tkinter.Entry.cCsdS)Nr)rrrr�	focus_set.szEntry.focus_setN)r	r
rrrWrrrrrV,srVN)	rrr
rrZ_tkinterrrrVrrrr�<module>s#S

?>