diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-06-03 00:14:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-03 00:14:41 (GMT) |
commit | 9c89d62073fa0bcfe68e59add5b55fbcbf7672ab (patch) | |
tree | 46272551d9b7c2eb3362fa1a0cdc8fdcd487c34f /Lib/idlelib/idle_test/tkinter_testing_utils.py | |
parent | 0e9af8cae314e4b0e770fe48d5f7b5f540c0b257 (diff) | |
download | cpython-9c89d62073fa0bcfe68e59add5b55fbcbf7672ab.zip cpython-9c89d62073fa0bcfe68e59add5b55fbcbf7672ab.tar.gz cpython-9c89d62073fa0bcfe68e59add5b55fbcbf7672ab.tar.bz2 |
bpo-44282: Fix occasional test_incremental_editing failures on buildbots (GH-26491) (GH-26499)
Signed-off-by: Tal Einat <532281+taleinat@users.noreply.github.com>
(cherry picked from commit adef445dc34685648bd0ea1c125df2ef143912ed)
Co-authored-by: Tal Einat <532281+taleinat@users.noreply.github.com>
Diffstat (limited to 'Lib/idlelib/idle_test/tkinter_testing_utils.py')
-rw-r--r-- | Lib/idlelib/idle_test/tkinter_testing_utils.py | 70 |
1 files changed, 38 insertions, 32 deletions
diff --git a/Lib/idlelib/idle_test/tkinter_testing_utils.py b/Lib/idlelib/idle_test/tkinter_testing_utils.py index a9f8386..a89839b 100644 --- a/Lib/idlelib/idle_test/tkinter_testing_utils.py +++ b/Lib/idlelib/idle_test/tkinter_testing_utils.py @@ -2,7 +2,7 @@ import functools -def run_in_tk_mainloop(test_method): +def run_in_tk_mainloop(delay=1): """Decorator for running a test method with a real Tk mainloop. This starts a Tk mainloop before running the test, and stops it @@ -13,44 +13,50 @@ def run_in_tk_mainloop(test_method): using "yield" to allow the mainloop to process events and "after" callbacks, and then continue the test from that point. + The delay argument is passed into root.after(...) calls as the number + of ms to wait before passing execution back to the generator function. + This also assumes that the test class has a .root attribute, which is a tkinter.Tk object. For example (from test_sidebar.py): - @run_test_with_tk_mainloop + @run_test_with_tk_mainloop() def test_single_empty_input(self): self.do_input('\n') yield self.assert_sidebar_lines_end_with(['>>>', '>>>']) """ - @functools.wraps(test_method) - def new_test_method(self): - test_generator = test_method(self) - root = self.root - # Exceptions raised by self.assert...() need to be raised - # outside of the after() callback in order for the test - # harness to capture them. - exception = None - def after_callback(): - nonlocal exception - try: - next(test_generator) - except StopIteration: - root.quit() - except Exception as exc: - exception = exc - root.quit() - else: - # Schedule the Tk mainloop to call this function again, - # using a robust method of ensuring that it gets a - # chance to process queued events before doing so. - # See: https://stackoverflow.com/q/18499082#comment65004099_38817470 - root.after(1, root.after_idle, after_callback) - root.after(0, root.after_idle, after_callback) - root.mainloop() - - if exception: - raise exception - - return new_test_method + def decorator(test_method): + @functools.wraps(test_method) + def new_test_method(self): + test_generator = test_method(self) + root = self.root + # Exceptions raised by self.assert...() need to be raised + # outside of the after() callback in order for the test + # harness to capture them. + exception = None + def after_callback(): + nonlocal exception + try: + next(test_generator) + except StopIteration: + root.quit() + except Exception as exc: + exception = exc + root.quit() + else: + # Schedule the Tk mainloop to call this function again, + # using a robust method of ensuring that it gets a + # chance to process queued events before doing so. + # See: https://stackoverflow.com/q/18499082#comment65004099_38817470 + root.after(delay, root.after_idle, after_callback) + root.after(0, root.after_idle, after_callback) + root.mainloop() + + if exception: + raise exception + + return new_test_method + + return decorator |