ž
©ÿf’) c @ sf d Z Gd d „ d ƒ Z Gd d „ d ƒ Z Gd d „ d ƒ Z d d l m Z Gd d
„ d
ƒ Z d S( uÉ Classes that replace tkinter gui objects used by an object being tested.
A gui object is anything with a master or parent paramenter, which is typically
required in spite of what the doc strings say.
c B sG | Ee Z d Z d Z d d d d d „ Z d d „ Z d d „ Z d S( u Varu) Use for String/Int/BooleanVar: incompletec C s | | _ | | _ | | _ d S( N( u masteru valueu name( u selfu masteru valueu name( ( u> /opt/alt/python33/lib64/python3.3/idlelib/idle_test/mock_tk.pyu __init__ s u Var.__init__c C s
| | _ d S( N( u value( u selfu value( ( u> /opt/alt/python33/lib64/python3.3/idlelib/idle_test/mock_tk.pyu set
s u Var.setc C s | j S( N( u value( u self( ( u> /opt/alt/python33/lib64/python3.3/idlelib/idle_test/mock_tk.pyu get s u Var.getN( u __name__u
__module__u __qualname__u __doc__u Noneu __init__u setu get( u
__locals__( ( u> /opt/alt/python33/lib64/python3.3/idlelib/idle_test/mock_tk.pyu Var s u Varc B s2 | Ee Z d Z d Z d d „ Z d d „ Z d S( u Mbox_funcuæ Generic 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.
c C s
d | _ d S( N( u Noneu result( u self( ( u> /opt/alt/python33/lib64/python3.3/idlelib/idle_test/mock_tk.pyu __init__ s u Mbox_func.__init__c O s+ | | _ | | _ | | _ | | _ | j S( N( u titleu messageu argsu kwdsu result( u selfu titleu messageu argsu kwds( ( u> /opt/alt/python33/lib64/python3.3/idlelib/idle_test/mock_tk.pyu __call__ s
u Mbox_func.__call__N( u __name__u
__module__u __qualname__u __doc__u __init__u __call__( u
__locals__( ( u> /opt/alt/python33/lib64/python3.3/idlelib/idle_test/mock_tk.pyu Mbox_func s u Mbox_funcc B sb | Ee Z d Z d Z e ƒ Z e ƒ Z e ƒ Z e ƒ Z e ƒ Z e ƒ Z
e ƒ Z e ƒ Z d S( u Mboxu5 Mock 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(
u __name__u
__module__u __qualname__u __doc__u Mbox_funcu askokcancelu askquestionu askretrycancelu askyesnou askyesnocancelu showerroru showinfou showwarning( u
__locals__( ( u> /opt/alt/python33/lib64/python3.3/idlelib/idle_test/mock_tk.pyu Mbox" s u Mboxi ( u TclErrorc B sé | Ee Z d Z d Z d! i d d „ Z d d „ Z d d d „ Z d d
„ Z d d „ Z d! d
d „ Z
d! d d „ Z d d „ Z d d „ Z
d d „ Z d! d d „ Z d d „ Z d d „ Z d d „ Z d! d! d! d d „ Z d! S(" u Textuƒ 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.
c K s d d g | _ d S( uÑ 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.
u u
N( u data( u selfu masteru cnfu kw( ( u> /opt/alt/python33/lib64/python3.3/idlelib/idle_test/mock_tk.pyu __init__T s u
Text.__init__c C s d | j | d d ƒS( uA Return string version of index decoded according to current text.u %s.%su endflagi ( u _decode( u selfu index( ( u> /opt/alt/python33/lib64/python3.3/idlelib/idle_test/mock_tk.pyu index\ s u
Text.indexi c C su t | t t f ƒ r$ t | ƒ } n y | j ƒ } Wn% t k
r[ t d | ƒ d ‚ Yn Xt | j ƒ d } | d k r– | t | j | ƒ d f S| d k r¯ | j
| ƒ S| j d ƒ \ } } t | ƒ } | d k rà d S| | k rù | j
| ƒ St | j | ƒ d } | j
d ƒ s+| d k r5| | f St | ƒ } | d k rVd } n | | k rk| } n | | f S(
u7 Return 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.
u bad text index "%s"i u insertu endu .i u lineendN( i i ( u
isinstanceu floatu bytesu stru loweru AttributeErroru TclErroru Noneu lenu datau _endexu splitu intu endswith( u selfu indexu endflagu lastlineu lineu charu
linelength( ( u> /opt/alt/python33/lib64/python3.3/idlelib/idle_test/mock_tk.pyu _decode` s4
u Text._decodec C sN t | j ƒ } | d k r% | d f S| d 8} | t | j | ƒ | f Sd S( u Return 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)
i i N( u lenu data( u selfu endflagu n( ( u> /opt/alt/python33/lib64/python3.3/idlelib/idle_test/mock_tk.pyu _endex“ s
u Text._endexc C sà | s
d S| j d ƒ } | d d d k r= | j d ƒ n | j | d ƒ \ } } | j | d | … } | j | | d … } | | d | j | <| d d … | j | d | d … <| j | t | ƒ d | 7