[issue21940] IDLE - Test WidgetRedirector

Terry J. Reedy report at bugs.python.org
Thu Jul 10 09:58:41 CEST 2014


Terry J. Reedy added the comment:

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%.

----------
assignee:  -> terry.reedy
stage:  -> commit review
type:  -> enhancement
Added file: http://bugs.python.org/file35919/test-redir-21940-34.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21940>
_______________________________________


More information about the Python-bugs-list mailing list