diff options
Diffstat (limited to 'Lib/idlelib/idle_test/mock_tk.py')
-rw-r--r-- | Lib/idlelib/idle_test/mock_tk.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/Lib/idlelib/idle_test/mock_tk.py b/Lib/idlelib/idle_test/mock_tk.py index 576f7d5..b736bd0 100644 --- a/Lib/idlelib/idle_test/mock_tk.py +++ b/Lib/idlelib/idle_test/mock_tk.py @@ -3,6 +3,9 @@ A gui object is anything with a master or parent parameter, which is typically required in spite of what the doc strings say. """ +import re +from _tkinter import TclError + class Event: '''Minimal mock with attributes for testing event handlers. @@ -22,6 +25,7 @@ class Event: "Create event with attributes needed for test" self.__dict__.update(kwds) + class Var: "Use for String/Int/BooleanVar: incomplete" def __init__(self, master=None, value=None, name=None): @@ -33,6 +37,7 @@ class Var: def get(self): return self.value + class Mbox_func: """Generic mock for messagebox functions, which all have the same signature. @@ -50,6 +55,7 @@ class Mbox_func: self.kwds = kwds return self.result # Set by tester for ask functions + class Mbox: """Mock for tkinter.messagebox with an Mbox_func for each function. @@ -85,7 +91,6 @@ class Test(unittest.TestCase): showinfo = Mbox_func() # None showwarning = Mbox_func() # None -from _tkinter import TclError class Text: """A semi-functional non-gui replacement for tkinter.Text text editors. @@ -154,6 +159,8 @@ class Text: if char.endswith(' lineend') or char == 'end': return line, linelength # Tk requires that ignored chars before ' lineend' be valid int + if m := re.fullmatch(r'end-(\d*)c', char, re.A): # Used by hyperparser. + return line, linelength - int(m.group(1)) # Out of bounds char becomes first or last index of line char = int(char) @@ -177,7 +184,6 @@ class Text: n -= 1 return n, len(self.data[n]) + endflag - def insert(self, index, chars): "Insert chars before the character at index." @@ -193,7 +199,6 @@ class Text: self.data[line+1:line+1] = chars[1:] self.data[line+len(chars)-1] += after - def get(self, index1, index2=None): "Return slice from index1 to index2 (default is 'index1+1')." @@ -212,7 +217,6 @@ class Text: lines.append(self.data[endline][:endchar]) return ''.join(lines) - def delete(self, index1, index2=None): '''Delete slice from index1 to index2 (default is 'index1+1'). @@ -297,6 +301,7 @@ class Text: "Bind to this widget at event sequence a call to function func." pass + class Entry: "Mock for tkinter.Entry." def focus_set(self): |