ยปCore Development>Code coverage>Lib/idlelib/idle_test/mock_idle.py

Python code coverage for Lib/idlelib/idle_test/mock_idle.py

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