[ctypes-commit] ctypes/comtypes/unittests test_basic.py,1.1,1.2
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2005-01-13 09:38:05
|
Update of /cvsroot/ctypes/ctypes/comtypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17275 Modified Files: test_basic.py Log Message: Removed the _nummethods_ property, replaced by a mechanism to calculate it. Changed the requirements for COM method implementations. - The method body is optional now. - If a method body is given, it must call the actual COM method like this: 'self.<methodname>._api_(self, *args)' Index: test_basic.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/unittests/test_basic.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_basic.py 12 Jan 2005 20:54:05 -0000 1.1 --- test_basic.py 13 Jan 2005 09:37:49 -0000 1.2 *************** *** 1,10 **** import unittest ! from ctypes import windll, POINTER, byref ! from comtypes import IUnknown class BasicTest(unittest.TestCase): def test_IUnknown(self): from comtypes import IUnknown ! self.failUnlessEqual(IUnknown._nummethods_, 3) def test_release(self): --- 1,14 ---- import unittest ! from ctypes import windll, POINTER, byref, HRESULT ! from comtypes import IUnknown, STDMETHOD ! ! def method_count(interface): ! return sum([len(base.__dict__.get("_methods_", ())) ! for base in interface.__mro__]) class BasicTest(unittest.TestCase): def test_IUnknown(self): from comtypes import IUnknown ! self.failUnlessEqual(method_count(IUnknown), 3) def test_release(self): *************** *** 39,49 **** def test_derived(self): class IMyInterface(IUnknown): pass ! self.failUnlessEqual(IMyInterface._nummethods_, 3) IMyInterface._methods_ = [] ! self.failUnlessEqual(IMyInterface._nummethods_, 3) def test_mro(self): --- 43,59 ---- def test_derived(self): + self.failUnlessEqual(method_count(IUnknown), 3) + class IMyInterface(IUnknown): pass ! self.failUnlessEqual(method_count(IMyInterface), 3) IMyInterface._methods_ = [] ! self.failUnlessEqual(method_count(IMyInterface), 3) ! ! IMyInterface._methods_ = [ ! STDMETHOD(HRESULT, "Blah", [])] ! self.failUnlessEqual(method_count(IMyInterface), 4) def test_mro(self): *************** *** 56,59 **** --- 66,101 ---- self.failUnless(IUnknown.__dict__.get("QueryInterface")) + ## def test_identity(self): + ## p = POINTER(IUnknown)() + #### p[0] + ## windll.oleaut32.CreateTypeLib(1, u"blabla", byref(p)) + + ## p = p.QueryInterface(IUnknown) + ## other = p.QueryInterface(IUnknown) + + ## print other == p + ## print other is p + ## print "A" + ## print "?", p[0] + ## print "B" + #### p[0] = 42 + ## print "C" + ## print dir(p) + ## from ctypes import cast, c_int + ## print cast(other, c_int).value + ## print cast(p, c_int).value + + ## x = POINTER(IUnknown)() + ## windll.oleaut32.CreateTypeLib(1, u"blabla_2", byref(x)) + ## x = x.QueryInterface(IUnknown) + + ## print cast(x, c_int).value + + ## print "D" + ## del p + ## print "E" + ## del other + ## print "F" + if __name__ == "__main__": unittest.main() |