Show More
@@ -63,14 +63,6 b' class EventManager(object):' | |||
|
63 | 63 | """Remove a callback from the given event.""" |
|
64 | 64 | self.callbacks[event].remove(function) |
|
65 | 65 | |
|
66 | def reset(self, event): | |
|
67 | """Clear all callbacks for the given event.""" | |
|
68 | self.callbacks[event] = [] | |
|
69 | ||
|
70 | def reset_all(self): | |
|
71 | """Clear all callbacks for all events.""" | |
|
72 | self.callbacks = {n:[] for n in self.callbacks} | |
|
73 | ||
|
74 | 66 | def trigger(self, event, *args, **kwargs): |
|
75 | 67 | """Call callbacks for ``event``. |
|
76 | 68 |
@@ -873,6 +873,8 b' class InteractiveShell(SingletonConfigurable):' | |||
|
873 | 873 | def init_events(self): |
|
874 | 874 | self.events = EventManager(self, available_events) |
|
875 | 875 | |
|
876 | self.events.register("pre_execute", self._clear_warning_registry) | |
|
877 | ||
|
876 | 878 | def register_post_execute(self, func): |
|
877 | 879 | """DEPRECATED: Use ip.events.register('post_run_cell', func) |
|
878 | 880 | |
@@ -882,6 +884,13 b' class InteractiveShell(SingletonConfigurable):' | |||
|
882 | 884 | "ip.events.register('post_run_cell', func) instead.") |
|
883 | 885 | self.events.register('post_run_cell', func) |
|
884 | 886 | |
|
887 | def _clear_warning_registry(self): | |
|
888 | # clear the warning registry, so that different code blocks with | |
|
889 | # overlapping line number ranges don't cause spurious suppression of | |
|
890 | # warnings (see gh-6611 for details) | |
|
891 | if "__warningregistry__" in self.user_global_ns: | |
|
892 | del self.user_global_ns["__warningregistry__"] | |
|
893 | ||
|
885 | 894 | #------------------------------------------------------------------------- |
|
886 | 895 | # Things related to the "main" module |
|
887 | 896 | #------------------------------------------------------------------------- |
@@ -25,22 +25,8 b' class CallbackTests(unittest.TestCase):' | |||
|
25 | 25 | self.em.trigger('ping_received') |
|
26 | 26 | self.assertEqual(cb.call_count, 1) |
|
27 | 27 | |
|
28 | def test_reset(self): | |
|
29 | cb = Mock() | |
|
30 | self.em.register('ping_received', cb) | |
|
31 | self.em.reset('ping_received') | |
|
32 | self.em.trigger('ping_received') | |
|
33 | assert not cb.called | |
|
34 | ||
|
35 | def test_reset_all(self): | |
|
36 | cb = Mock() | |
|
37 | self.em.register('ping_received', cb) | |
|
38 | self.em.reset_all() | |
|
39 | self.em.trigger('ping_received') | |
|
40 | assert not cb.called | |
|
41 | ||
|
42 | 28 | def test_cb_error(self): |
|
43 | 29 | cb = Mock(side_effect=ValueError) |
|
44 | 30 | self.em.register('ping_received', cb) |
|
45 | 31 | with tt.AssertPrints("Error in callback"): |
|
46 | self.em.trigger('ping_received') No newline at end of file | |
|
32 | self.em.trigger('ping_received') |
@@ -301,7 +301,10 b' class InteractiveShellTestCase(unittest.TestCase):' | |||
|
301 | 301 | assert post_explicit.called |
|
302 | 302 | finally: |
|
303 | 303 | # remove post-exec |
|
304 |
ip.events. |
|
|
304 | ip.events.unregister('pre_run_cell', pre_explicit) | |
|
305 | ip.events.unregister('pre_execute', pre_always) | |
|
306 | ip.events.unregister('post_run_cell', post_explicit) | |
|
307 | ip.events.unregister('post_execute', post_always) | |
|
305 | 308 | |
|
306 | 309 | def test_silent_noadvance(self): |
|
307 | 310 | """run_cell(silent=True) doesn't advance execution_count""" |
@@ -840,3 +843,17 b' class TestSyntaxErrorTransformer(unittest.TestCase):' | |||
|
840 | 843 | |
|
841 | 844 | |
|
842 | 845 | |
|
846 | def test_warning_suppression(): | |
|
847 | ip.run_cell("import warnings") | |
|
848 | try: | |
|
849 | with tt.AssertPrints("UserWarning: asdf", channel="stderr"): | |
|
850 | ip.run_cell("warnings.warn('asdf')") | |
|
851 | # Here's the real test -- if we run that again, we should get the | |
|
852 | # warning again. Traditionally, each warning was only issued once per | |
|
853 | # IPython session (approximately), even if the user typed in new and | |
|
854 | # different code that should have also triggered the warning, leading | |
|
855 | # to much confusion. | |
|
856 | with tt.AssertPrints("UserWarning: asdf", channel="stderr"): | |
|
857 | ip.run_cell("warnings.warn('asdf')") | |
|
858 | finally: | |
|
859 | ip.run_cell("del warnings") |
General Comments 0
You need to be logged in to leave comments.
Login now