Re: [Pyobjc-dev] NSObject, doctest
Brought to you by:
ronaldoussoren
From: Ronald O. <ron...@ma...> - 2013-12-19 12:42:24
|
On 07 Dec 2013, at 21:33, Erik van Blokland <er...@le...> wrote: > Hey, > > I have a small problem writing doctests for a module with a NSObject subclass. > Here's a small test: > > from AppKit import * > """ > An odd interaction between doctest and an NSObject subclass. > """ > class MyClass(NSObject): > def __new__(cls, a, b): > self = cls.alloc().init() > self.a = a > self.b = b > return self > > def doSomething(self): > return a+b > > def _test(): > def testOne(): > """ > Test one >>>> m = MyClass(1,1) >>>> m.doSomething() > 2 > """ > import doctest > doctest.testmod() > > _test() > > Here's the result, using Python 2.7.2 (default, Oct 11 2012, 20:14:37) and objc 2.3.2a0. > >> <class 'NSAppleEventManagerSuspensionID'> >> Traceback (most recent call last): >> File "/Users/erik/Desktop/docTestTest.py", line 53, in <module> >> _test() >> File "/Users/erik/Desktop/docTestTest.py", line 51, in _test >> doctest.testmod() >> File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/doctest.py", line 1850, in testmod >> for test in finder.find(m, name, globs=globs, extraglobs=extraglobs): >> File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/doctest.py", line 865, in find >> self._find(tests, obj, name, module, source_lines, globs, {}) >> File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/doctest.py", line 917, in _find >> self._from_module(module, val)): >> File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/doctest.py", line 880, in _from_module >> elif inspect.getmodule(object) is not None: >> File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/inspect.py", line 486, in getmodule >> file = getabsfile(object, _filename) >> File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/inspect.py", line 469, in getabsfile >> _filename = getsourcefile(object) or getfile(object) >> File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/inspect.py", line 447, in getsourcefile >> filename = getfile(object) >> File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/inspect.py", line 408, in getfile >> object = sys.modules.get(object.__module__) >> AttributeError: __module__ > > Is there something in the nature of pyobjc objects that makes them confuse dockets? Not sure if the class repr at the top of the traceback is relevant, but if it is this might be due to doctest trying to test some PyObjC classes. BTW. I’m moving away from “from AppKit import *” towards just importing what I need. That leads to code that’s slightly easier to check with linting tools, and in recent versions of PyObjC is faster as well because the framework wrappers now try to do as little work as possible (and that doesn’t work when you import everything). Ronald > Thanks! > Erik > ------------------------------------------------------------------------------ > Sponsored by Intel(R) XDK > Develop, test and display web and hybrid apps with a single code base. > Download it for free now! > http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev |