From e69a1fa5c1009d6350a6d1af67898eb346ed150a Mon Sep 17 00:00:00 2001 From: Stefan Behnel <stefan_ml@behnel.de> Date: Sat, 23 Nov 2013 21:22:15 +0100 Subject: [PATCH] make an old test from 'broken' directory usable --- tests/run/extcmethod.pyx | 43 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/tests/run/extcmethod.pyx b/tests/run/extcmethod.pyx index 18e1ed8a2..8b9f459ad 100644 --- a/tests/run/extcmethod.pyx +++ b/tests/run/extcmethod.pyx @@ -1,5 +1,6 @@ # mode: run + cdef class Spam: cdef int tons @@ -13,14 +14,16 @@ cdef class Spam: def lift(self): print self.tons + cdef class SubSpam(Spam): cdef void add_tons(self, int x): self.tons += 2 * x -def test(): + +def test_spam(): """ - >>> test() + >>> test_spam() 5 0 20 @@ -41,3 +44,39 @@ def test(): ss.lift() s.lift() + + +cdef class SpamDish: + cdef int spam + + cdef void describe(self): + print "This dish contains", self.spam, "tons of spam." + + +cdef class FancySpamDish(SpamDish): + cdef int lettuce + + cdef void describe(self): + print "This dish contains", self.spam, "tons of spam", + print "and", self.lettuce, "milligrams of lettuce." + + +cdef void describe_dish(SpamDish d): + d.describe() + + +def test_spam_dish(): + """ + >>> test_spam_dish() + This dish contains 42 tons of spam. + This dish contains 88 tons of spam and 5 milligrams of lettuce. + """ + cdef SpamDish s + cdef FancySpamDish ss + s = SpamDish() + s.spam = 42 + ss = FancySpamDish() + ss.spam = 88 + ss.lettuce = 5 + describe_dish(s) + describe_dish(ss) -- 2.30.9