From 13ad80a3a6a49860f6410741544fb6874cea0d29 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Thu, 31 Jul 2008 07:51:06 +0200 Subject: [PATCH] test case for subclasses and vtables --- tests/run/subclasses.pyx | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/run/subclasses.pyx diff --git a/tests/run/subclasses.pyx b/tests/run/subclasses.pyx new file mode 100644 index 00000000..ece74280 --- /dev/null +++ b/tests/run/subclasses.pyx @@ -0,0 +1,56 @@ +__doc__ = u""" +>>> zoo = Zoo() +>>> for cl in (Zoo, Bam, Bar, Foo, Base, Base0): assert isinstance(zoo, cl) +>>> fooit(zoo) +42 + +>>> bam = Bam() +>>> for cl in (Bam, Bar, Foo, Base, Base0): assert isinstance(bam, cl) +>>> fooit(bam) +42 + +>>> bar = Bar() +>>> for cl in (Bar, Foo, Base, Base0): assert isinstance(bar, cl) +>>> fooit(bar) +42 + +>>> foo = Foo() +>>> for cl in (Foo, Base, Base0): assert isinstance(foo, cl) +>>> fooit(foo) +42 + +>>> base = Base() +>>> for cl in (Base, Base0): assert isinstance(base, cl) +>>> fooit(base) +Traceback (most recent call last): +TypeError: Argument 'foo' has incorrect type (expected subclasses.Foo, got subclasses.Base) + +>>> base0 = Base0() +>>> for cl in (Base0,): assert isinstance(base0, cl) +>>> fooit(base0) +Traceback (most recent call last): +TypeError: Argument 'foo' has incorrect type (expected subclasses.Foo, got subclasses.Base0) +""" + +cdef class Base0: + pass + +cdef class Base(Base0): + pass + +cdef class Foo(Base): + cdef fooit(self): + return 42 + +cdef class Bar(Foo): + pass + +cdef class Bam(Bar): + pass + +cdef class Zoo(Bam): + pass + + +def fooit(Foo foo): + return foo.fooit() -- 2.26.2