ó {fc@sˆdZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZd d lmZd efd „ƒYZd S(sÈ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. tEventcBseZdZd„ZRS(sª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(s,Create event with attributes needed for testN(t__dict__tupdate(tselftkwds((s1/usr/lib64/python2.7/idlelib/idle_test/mock_tk.pyt__init__s(t__name__t __module__t__doc__R(((s1/usr/lib64/python2.7/idlelib/idle_test/mock_tk.pyRs tVarcBs2eZdZdddd„Zd„Zd„ZRS(s)Use for String/Int/BooleanVar: incompletecCs||_||_||_dS(N(tmastertvaluetname(RR R R ((s1/usr/lib64/python2.7/idlelib/idle_test/mock_tk.pyRs  cCs ||_dS(N(R (RR ((s1/usr/lib64/python2.7/idlelib/idle_test/mock_tk.pytsetscCs|jS(N(R (R((s1/usr/lib64/python2.7/idlelib/idle_test/mock_tk.pytget!sN(RRRtNoneRR R(((s1/usr/lib64/python2.7/idlelib/idle_test/mock_tk.pyR s t Mbox_funccBs#eZdZdd„Zd„ZRS(sGeneric 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 cCs ||_dS(N(tresult(RR((s1/usr/lib64/python2.7/idlelib/idle_test/mock_tk.pyR+scOs+||_||_||_||_|jS(N(ttitletmessagetargsRR(RRRRR((s1/usr/lib64/python2.7/idlelib/idle_test/mock_tk.pyt__call__-s     N(RRRRRR(((s1/usr/lib64/python2.7/idlelib/idle_test/mock_tk.pyR$s tMboxcBsVeZdZeƒZeƒZeƒZeƒZeƒZeƒZ eƒZ eƒZ RS(s5Mock 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, ( RRRRt askokcancelt askquestiontaskretrycanceltaskyesnotaskyesnocancelt showerrortshowinfot showwarning(((s1/usr/lib64/python2.7/idlelib/idle_test/mock_tk.pyR5s       iÿÿÿÿ(tTclErrortTextcBs°eZdZdid„Zd„Zdd„Zd„Zd„Zdd„Z dd„Z d „Z d „Z d „Z dd „Zd „Zd„Zd„Zdddd„ZRS(sƒ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. cKsddg|_dS(sÑ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. ts N(tdata(RR tcnftkw((s1/usr/lib64/python2.7/idlelib/idle_test/mock_tk.pyRgscCsd|j|ddƒS(sAReturn string version of index decoded according to current text.s%s.%stendflagi(t_decode(Rtindex((s1/usr/lib64/python2.7/idlelib/idle_test/mock_tk.pyR'osicCsqt|ttfƒr$t|ƒ}ny|jƒ}Wn!tk rWtd|ƒ‚nXt|jƒd}|dkr’|t|j|ƒdfS|dkr«|j |ƒS|j dƒ\}}t |ƒ}|dkrÜdS||krõ|j |ƒSt|j|ƒd}|j dƒs'|dkr1||fSt |ƒ}|dkrRd}n||krg|}n||fS( s7Return a (line, char) tuple of int indexes into self.data. This implements .index without converting the result back to a string. The result is contrained 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. sbad text index "%s"itinserttendt.is lineend(ii( t isinstancetfloattbyteststrtlowertAttributeErrorRtlenR"t_endextsplittinttendswith(RR'R%tlastlinetlinetchart linelength((s1/usr/lib64/python2.7/idlelib/idle_test/mock_tk.pyR&ss4              cCsNt|jƒ}|dkr%|dfS|d8}|t|j|ƒ|fSdS(sReturn 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) iiN(R1R"(RR%tn((s1/usr/lib64/python2.7/idlelib/idle_test/mock_tk.pyR2¦s    cCsÍ|s dS|jtƒ}|dddkr=|jdƒn|j|dƒ\}}|j|| }|j||}||d|j|<|d|j|d|d+|j|t|ƒdc|7s>=s==s!=s=bad comparison operator "%s": must be <, <=, ==, >=, >, or !=(R&R(RRCtopRDtline1tchar1tline2tchar2((s1/usr/lib64/python2.7/idlelib/idle_test/mock_tk.pytcompare÷s  " " " "  cCsdS(s.Set mark *name* before the character at index.N((RR R'((s1/usr/lib64/python2.7/idlelib/idle_test/mock_tk.pytmark_set scGsdS(sDelete all marks in markNames.N((Rt markNames((s1/usr/lib64/python2.7/idlelib/idle_test/mock_tk.pyt mark_unsetR!cCsdS(sARemove tag tagName from all characters between index1 and index2.N((RttagNameRCRD((s1/usr/lib64/python2.7/idlelib/idle_test/mock_tk.pyt tag_removescCsdS(s2Adjust the view of the text according to scan_markN((Rtxty((s1/usr/lib64/python2.7/idlelib/idle_test/mock_tk.pyt scan_dragtoR!cCsdS(s&Remember the current X, Y coordinates.N((RRYRZ((s1/usr/lib64/python2.7/idlelib/idle_test/mock_tk.pyt scan_markR!cCsdS(s8Scroll screen to make the character at INDEX is visible.N((RR'((s1/usr/lib64/python2.7/idlelib/idle_test/mock_tk.pytsee!scCsdS(s>Bind to this widget at event sequence a call to function func.N((tsequencetfunctadd((s1/usr/lib64/python2.7/idlelib/idle_test/mock_tk.pytbind(sN(RRRRRR'R&R2R(RRKRSRTRVRXR[R\R]Ra(((s1/usr/lib64/python2.7/idlelib/idle_test/mock_tk.pyR Zs    3           N( RtobjectRR RRt_tkinterRR (((s1/usr/lib64/python2.7/idlelib/idle_test/mock_tk.pyts  #