Issue 21940: IDLE - Test WidgetRedirector (original) (raw)
Attached is the 3.4 code I plan to commit after a trivial 2.7 backport.
In the existing htest, 'global previous_tcl_fcn' is unnecessary because of Python's late binding of function locals. No forward definitions are needed. Already deleted in the first patch.
Adding this test: def test_unregister_no_attribute(self): del self.text.insert self.assertEqual(self.redir.unregister('insert'), self.func) revealed that this code in .unregister if hasattr(self.widget, operation): delattr(self.widget, operation) is buggy because hasattr looks up the class tree for an attribute whereas delattr does not. Hence the former can be true, and will be after text.insert in deleted to unmask Text.insert, while delattr raises AttributeError. The if check is useless, and replaced by 'try...' in the new patch.
I modified a few tests and added a few more. Coverage is now 100%.