[Python-Dev] [Python-checkins] cpython: PEP 417: Adding unittest.mock (original) (raw)
Kristján Valur Jónsson kristjan at ccpgames.com
Thu Mar 15 02:38:41 CET 2012
- Previous message: [Python-Dev] [Python-checkins] cpython: PEP 417: Adding unittest.mock
- Next message: [Python-Dev] cpython: Issue #14200: Idle shell crash on printing non-BMP unicode character.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Fyi: http://bugs.python.org/issue14310
-----Original Message----- From: python-dev-bounces+kristjan=ccpgames.com at python.org [mailto:python-dev-bounces+kristjan=ccpgames.com at python.org] On Behalf Of Michael Foord Sent: 14. mars 2012 14:42 To: Terry Reedy Cc: python-dev at python.org Subject: Re: [Python-Dev] [Python-checkins] cpython: PEP 417: Adding unittest.mock
On 14 Mar 2012, at 13:46, Terry Reedy wrote:
On 3/14/2012 4:22 PM, Michael Foord wrote:
On 14 Mar 2012, at 13:08, Terry Reedy wrote:
On 3/14/2012 3:25 PM, michael.foord wrote: +# mock.py +# Test tools for mocking and patching. Should there be a note here about restrictions on editing this file? I notice that there are things like
+class OldStyleClass: + pass +ClassType = type(OldStyleClass) which are only present for running under Py2 and which would normally be removed for Py3. Yeah, I removed as much of the Python 2 compatibility code and thought I'd got it all. Thanks for pointing it out. 2000 lines is a lot to check through. I'm maintaining a "clean" (no Python 2 compatibility code) version in the standard library. Great. Here is something else, which is why I thought otherwise ;-). +def instancecallable(obj): + """Given an object, return True if the object is callable. + For classes, return True if instances would be callable.""" + if not isinstance(obj, type): + # already an instance + return getattr(obj, 'call', None) is not None + + klass = obj + # uses bases instead of mro so that we work with >>> old style classes + if klass.dict.get('call') is not None: + return True + + for base in klass.bases: + if instancecallable(base): + return True + return False If you want to leave the code as is, remove or revise the comment.
Thanks very much for finding these, I'm pretty sure I've fixed all the ones you reported - and one more case where try...except...finally can now be used.
All the best,
Michael Foord
I'll be maintaining mock, so I'd like to be assigned any issues on it and at least talked to before changes are made. I am maintaining a backport still, but the Python standard library version is the canonical version. Add unittest.mock to devguide/experts.rst and yourself with * appended. --- Searching for 'old', I also found +def mustskip(spec, entry, istype): + if not isinstance(spec, type): + if entry in getattr(spec, 'dict', {}): + # instance attribute - shouldn't skip + return False >>>+ # can't use type because of old style classes + spec = spec.class + if not hasattr(spec, 'mro'): >>>+ # old style class: can't have descriptors anyway + return istype In testcallable.py + def testpatchspeccallableclass(self): + class CallableX(X): + def call(self): + pass + + class Sub(CallableX): + pass + + class Multi(SomeClass, Sub): + pass + >>>+ class OldStyle: + def call(self): + pass + >>>+ class OldStyleSub(OldStyle): + pass + + for arg in 'spec', 'specset': >>>+ for Klass in CallableX, Sub, Multi, OldStyle, OldStyleSub: This is the last. -- Terry Jan Reedy
Python-Dev mailing list Python-Dev at python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/fuzzyman%40voidspace.org.uk
-- http://www.voidspace.org.uk/
May you do good and not evil May you find forgiveness for yourself and forgive others May you share freely, never taking more than you give. -- the sqlite blessing http://www.sqlite.org/different.html
Python-Dev mailing list Python-Dev at python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/kristjan%40ccpgames.com
- Previous message: [Python-Dev] [Python-checkins] cpython: PEP 417: Adding unittest.mock
- Next message: [Python-Dev] cpython: Issue #14200: Idle shell crash on printing non-BMP unicode character.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]