| 1 | n/a | '''Mock classes that imitate idlelib modules or classes. |
|---|
| 2 | n/a | |
|---|
| 3 | n/a | Attributes and methods will be added as needed for tests. |
|---|
| 4 | n/a | ''' |
|---|
| 5 | n/a | |
|---|
| 6 | n/a | from idlelib.idle_test.mock_tk import Text |
|---|
| 7 | n/a | |
|---|
| 8 | n/a | class Func: |
|---|
| 9 | n/a | '''Mock function captures args and returns result set by test. |
|---|
| 10 | n/a | |
|---|
| 11 | n/a | Attributes: |
|---|
| 12 | n/a | self.called - records call even if no args, kwds passed. |
|---|
| 13 | n/a | self.result - set by init, returned by call. |
|---|
| 14 | n/a | self.args - captures positional arguments. |
|---|
| 15 | n/a | self.kwds - captures keyword arguments. |
|---|
| 16 | n/a | |
|---|
| 17 | n/a | Most common use will probably be to mock methods. |
|---|
| 18 | n/a | Mock_tk.Var and Mbox_func are special variants of this. |
|---|
| 19 | n/a | ''' |
|---|
| 20 | n/a | def __init__(self, result=None): |
|---|
| 21 | n/a | self.called = False |
|---|
| 22 | n/a | self.result = result |
|---|
| 23 | n/a | self.args = None |
|---|
| 24 | n/a | self.kwds = None |
|---|
| 25 | n/a | def __call__(self, *args, **kwds): |
|---|
| 26 | n/a | self.called = True |
|---|
| 27 | n/a | self.args = args |
|---|
| 28 | n/a | self.kwds = kwds |
|---|
| 29 | n/a | if isinstance(self.result, BaseException): |
|---|
| 30 | n/a | raise self.result |
|---|
| 31 | n/a | else: |
|---|
| 32 | n/a | return self.result |
|---|
| 33 | n/a | |
|---|
| 34 | n/a | |
|---|
| 35 | n/a | class Editor: |
|---|
| 36 | n/a | '''Minimally imitate editor.EditorWindow class. |
|---|
| 37 | n/a | ''' |
|---|
| 38 | n/a | def __init__(self, flist=None, filename=None, key=None, root=None): |
|---|
| 39 | n/a | self.text = Text() |
|---|
| 40 | n/a | self.undo = UndoDelegator() |
|---|
| 41 | n/a | |
|---|
| 42 | n/a | def get_selection_indices(self): |
|---|
| 43 | n/a | first = self.text.index('1.0') |
|---|
| 44 | n/a | last = self.text.index('end') |
|---|
| 45 | n/a | return first, last |
|---|
| 46 | n/a | |
|---|
| 47 | n/a | |
|---|
| 48 | n/a | class UndoDelegator: |
|---|
| 49 | n/a | '''Minimally imitate undo.UndoDelegator class. |
|---|
| 50 | n/a | ''' |
|---|
| 51 | n/a | # A real undo block is only needed for user interaction. |
|---|
| 52 | n/a | def undo_block_start(*args): |
|---|
| 53 | n/a | pass |
|---|
| 54 | n/a | def undo_block_stop(*args): |
|---|
| 55 | n/a | pass |
|---|