Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/python/test/polymorphism.py @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

File size: 1.9 KB
Line 
1# Copyright David Abrahams 2004. Distributed under the Boost
2# Software License, Version 1.0. (See accompanying
3# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4import unittest
5from polymorphism_ext import *
6
7class PolymorphTest(unittest.TestCase):
8
9   def testReturnCpp(self):
10
11      # Python Created Object With Same Id As
12      # Cpp Created B Object
13      # b = B(872) 
14
15      #  Get Reference To Cpp Created B Object
16      a = getBCppObj()
17
18      # Python Created B Object and Cpp B Object
19      # Should have same result by calling f()
20      self.failUnlessEqual ('B::f()', a.f())
21      self.failUnlessEqual ('B::f()', call_f(a))
22      self.failUnlessEqual ('A::f()', call_f(A()))
23
24   def test_references(self):
25      # B is not exposed to Python
26      a = getBCppObj()
27      self.failUnlessEqual(type(a), A)
28
29      # C is exposed to Python
30      c = getCCppObj()
31      self.failUnlessEqual(type(c), C)
32     
33   def test_factory(self):
34      self.failUnlessEqual(type(factory(0)), A)
35      self.failUnlessEqual(type(factory(1)), A)
36      self.failUnlessEqual(type(factory(2)), C)
37
38   def test_return_py(self):
39
40      class X(A):
41         def f(self):
42            return 'X.f'
43
44      x = X()
45     
46      self.failUnlessEqual ('X.f', x.f())
47      self.failUnlessEqual ('X.f', call_f(x))
48
49   def test_wrapper_downcast(self):
50      a = pass_a(D())
51      self.failUnlessEqual('D::g()', a.g())
52
53   def test_pure_virtual(self):
54      p = P()
55      self.assertRaises(RuntimeError, p.f)
56     
57      q = Q()
58      self.failUnlessEqual ('Q::f()', q.f())
59     
60      class R(P):
61         def f(self):
62            return 'R.f'
63
64      r = R()
65      self.failUnlessEqual ('R.f', r.f())
66     
67                       
68if __name__ == "__main__":
69   
70   # remove the option which upsets unittest
71   import sys
72   sys.argv = [ x for x in sys.argv if x != '--broken-auto-ptr' ]
73   
74   unittest.main()
Note: See TracBrowser for help on using the repository browser.