From 9a8c817dcc709a7fc9630865610626dcc787e9f1 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Tue, 1 Jan 2008 20:16:28 +0100 Subject: [PATCH] loads of doctests --- tests/compile/getattr3ref.pyx | 7 +++- tests/compile/nogil.pyx | 2 +- tests/run/addressof.pyx | 12 +++++- tests/run/ass2global.pyx | 18 +++++++-- tests/run/assert.pyx | 21 +++++++++- tests/run/attr.pyx | 65 +++++++++++++++++++++++++++++- tests/run/baas3.pyx | 6 +++ tests/run/behnel1.pyx | 15 ++++--- tests/run/bishop2.pyx | 8 ++++ tests/run/cfuncdef.pyx | 9 +++++ tests/run/cintop.pyx | 12 +++++- tests/run/cstruct.pyx | 42 ++++++++++++++++++- tests/run/cunion.pyx | 31 +++++++++++++- tests/run/dict.pyx | 46 +++++++++++++++++---- tests/run/dietachmayer1.pyx | 7 +++- tests/run/extinherit.pyx | 23 ++++++++++- tests/run/extlen.pyx | 5 +++ tests/run/extstarargs.pyx | 42 +++++++++++++++++++ tests/run/ishimoto2.pyx | 13 +++++- tests/run/kwonlyargs.pyx | 65 ++++++++++++++++++++++++++++++ tests/run/modbody.pyx | 12 ++++++ tests/run/modop.pyx | 33 +++++++++++---- tests/run/naanou_1.pyx | 2 - tests/run/new_style_exceptions.pyx | 6 +++ tests/run/pinard5.pyx | 18 +++++++-- tests/run/pinard7.pyx | 13 ++++++ tests/run/pyextattrref.pyx | 4 ++ tests/run/r_mang1.pyx | 10 +++++ tests/run/ref2local.pyx | 6 +++ tests/run/return.pyx | 15 ++++++- tests/run/slice3.pyx | 48 +++++++++++++++++++--- tests/run/starargs.pyx | 41 ++++++++++++++++++- tests/run/subop.pyx | 25 ++++++++++-- tests/run/varargcall.pyx | 6 ++- tests/run/wundram1.pyx | 6 +++ 35 files changed, 639 insertions(+), 55 deletions(-) delete mode 100644 tests/run/naanou_1.pyx diff --git a/tests/compile/getattr3ref.pyx b/tests/compile/getattr3ref.pyx index 5fb4fdb9..492fb28e 100644 --- a/tests/compile/getattr3ref.pyx +++ b/tests/compile/getattr3ref.pyx @@ -1,2 +1,7 @@ -cdef int f() except -1: +__doc__ = """ + >>> print f() +""" + +def f(): g = getattr3 + return g.__name__ diff --git a/tests/compile/nogil.pyx b/tests/compile/nogil.pyx index cc9d4c87..149f0448 100644 --- a/tests/compile/nogil.pyx +++ b/tests/compile/nogil.pyx @@ -1,4 +1,4 @@ -cdef extern object g(object x) nogil +cdef extern object g(int x) nogil cdef void f(int x) nogil: cdef int y diff --git a/tests/run/addressof.pyx b/tests/run/addressof.pyx index a7dd1656..809adb61 100644 --- a/tests/run/addressof.pyx +++ b/tests/run/addressof.pyx @@ -1,4 +1,12 @@ -def f(): - cdef int i +__doc__ = """ + >>> f(5) + 5 +""" + +def f(int a): + cdef int i,j cdef int *p + i = a p = &i + j = p[0] + return j diff --git a/tests/run/ass2global.pyx b/tests/run/ass2global.pyx index cc4fa3a4..7ae23536 100644 --- a/tests/run/ass2global.pyx +++ b/tests/run/ass2global.pyx @@ -1,4 +1,16 @@ +__doc__ = """ + >>> getg() + 5 + >>> f(42) + >>> getg() + 42 +""" + +g = 5 + def f(a): - global f - f = a - f = 42 + global g + g = a + +def getg(): + return g diff --git a/tests/run/assert.pyx b/tests/run/assert.pyx index b9e435c4..aafcfd9c 100644 --- a/tests/run/assert.pyx +++ b/tests/run/assert.pyx @@ -1,5 +1,22 @@ -def f(a, b): - cdef int i +__doc__ = """ + >>> f(1, 2, 1) + >>> f(0, 2, 1) + Traceback (most recent call last): + AssertionError + >>> f(1, -1, 1) + Traceback (most recent call last): + AssertionError + >>> f(1, 2, 0) + Traceback (most recent call last): + AssertionError + + >>> g(1, "works") + >>> g(0, "fails") + Traceback (most recent call last): + AssertionError: fails +""" + +def f(a, b, int i): assert a assert a+b assert i diff --git a/tests/run/attr.pyx b/tests/run/attr.pyx index 2927acb6..70bf7e69 100644 --- a/tests/run/attr.pyx +++ b/tests/run/attr.pyx @@ -1,6 +1,67 @@ -def f(a, b): +__doc__ = """ + >>> class Test: + ... def __init__(self, i): + ... self.i = i + >>> b = Test(1) + >>> b.spam = Test(2) + >>> b.spam.eggs = Test(3) + >>> b.spam.eggs.spam = Test(4) + >>> b.spam.eggs.spam.eggs = Test(5) + + >>> a = f(b) + >>> print a.i + 2 + >>> print b.i + 1 + >>> print a.spam.i + 1 + >>> print b.spam.i + 2 + >>> print a.spam.eggs.i + Traceback (most recent call last): + AttributeError: Test instance has no attribute 'eggs' + >>> print b.spam.eggs.i + 3 + >>> print a.spam.spam.i + 2 + >>> print b.spam.spam.i + 1 + >>> print a.spam.eggs.spam.i + Traceback (most recent call last): + AttributeError: Test instance has no attribute 'eggs' + >>> print b.spam.eggs.spam.i + 4 + + >>> a = g(b) + >>> print a.i + 3 + >>> print b.i + 1 + >>> print a.spam.i + 4 + >>> print b.spam.i + 2 + >>> print a.spam.eggs.i + 1 + >>> print b.spam.eggs.i + 3 + >>> print a.spam.spam.i + Traceback (most recent call last): + AttributeError: Test instance has no attribute 'spam' + >>> print b.spam.spam.i + 1 + >>> print a.spam.eggs.spam.i + 2 + >>> print b.spam.eggs.spam.i + 4 +""" + +def f(b): a = b.spam a.spam = b + return a + +def g(b): a = b.spam.eggs a.spam.eggs = b - \ No newline at end of file + return a diff --git a/tests/run/baas3.pyx b/tests/run/baas3.pyx index a292ef73..66098fc2 100644 --- a/tests/run/baas3.pyx +++ b/tests/run/baas3.pyx @@ -1,3 +1,9 @@ +__doc__ = """ + >>> m = MyClass() + >>> m is foo(m) + True +""" + cdef class MyClass: pass diff --git a/tests/run/behnel1.pyx b/tests/run/behnel1.pyx index 43823505..10e264b6 100644 --- a/tests/run/behnel1.pyx +++ b/tests/run/behnel1.pyx @@ -1,9 +1,14 @@ +__doc__ = """ + >>> viking(5) + 5 +""" + cdef class Spam: - cdef eggs(self): - pass + cdef eggs(self, a): + return a cdef Spam spam(): - pass + return Spam() -def viking(): - return spam().eggs() +def viking(a): + return spam().eggs(a) diff --git a/tests/run/bishop2.pyx b/tests/run/bishop2.pyx index 0853117e..24d9c06e 100644 --- a/tests/run/bishop2.pyx +++ b/tests/run/bishop2.pyx @@ -1,3 +1,11 @@ +__doc__ = """ + >>> f = foo() + >>> 'a' in f + True + >>> 1 in f + True +""" + cdef class foo: def __contains__(self, key): diff --git a/tests/run/cfuncdef.pyx b/tests/run/cfuncdef.pyx index f2779743..3351885a 100644 --- a/tests/run/cfuncdef.pyx +++ b/tests/run/cfuncdef.pyx @@ -1,3 +1,7 @@ +__doc__ = """ + >>> test() +""" + cdef void ftang(): cdef int x x = 0 @@ -10,3 +14,8 @@ cdef int foo(int i, char c): cdef spam(int i, obj, object object): cdef char c c = 0 + +def test(): + ftang() + foo(0, c'f') + spam(25, None, None) diff --git a/tests/run/cintop.pyx b/tests/run/cintop.pyx index 6a600578..49d36ee6 100644 --- a/tests/run/cintop.pyx +++ b/tests/run/cintop.pyx @@ -1,7 +1,16 @@ +__doc__ = """ + >>> f() + (5376, 67) +""" + def f(): cdef int int1, int2, int3 cdef char char1 cdef long long1, long2 + int2 = 42 + int3 = 7 + char1 = c'C' + int1 = int2 | int3 int1 = int2 ^ int3 int1 = int2 & int3 @@ -9,5 +18,4 @@ def f(): int1 = int2 >> int3 int1 = int2 << int3 | int2 >> int3 long1 = char1 | long2 - - \ No newline at end of file + return int1, long1 diff --git a/tests/run/cstruct.pyx b/tests/run/cstruct.pyx index 1529e1cf..07a243d6 100644 --- a/tests/run/cstruct.pyx +++ b/tests/run/cstruct.pyx @@ -1,3 +1,10 @@ +__doc__ = """ + >>> test_i() + >>> test_c() + >>> test_p() + >>> test_g() +""" + cdef struct Grail cdef struct Spam: @@ -11,9 +18,42 @@ cdef struct Grail: cdef Spam spam, ham -cdef void eggs(Spam s): +cdef void eggs_i(Spam s): cdef int j j = s.i s.i = j +cdef void eggs_c(Spam s): + cdef char c + c = s.c + s.c = c + +cdef void eggs_p(Spam s): + cdef float *p + p = s.p[0] + s.p[0] = p + +cdef void eggs_g(Spam s): + cdef float *p + p = s.p[0] + s.p[0] = p + spam = ham + +def test_i(): + spam.i = 1 + eggs_i(spam) + +def test_c(): + spam.c = c'a' + eggs_c(spam) + +def test_p(): + cdef float f + spam.p[0] = &f + eggs_p(spam) + +def test_g(): + cdef Grail l + spam.g = &l + eggs_g(spam) diff --git a/tests/run/cunion.pyx b/tests/run/cunion.pyx index 72ad7668..352464a3 100644 --- a/tests/run/cunion.pyx +++ b/tests/run/cunion.pyx @@ -1,3 +1,9 @@ +__doc__ = """ + >>> test_i() + >>> test_c() + >>> test_p() +""" + cdef union Spam: int i char c @@ -5,9 +11,32 @@ cdef union Spam: cdef Spam spam, ham -cdef void eggs(Spam s): +cdef void eggs_i(Spam s): cdef int j j = s.i s.i = j +cdef void eggs_c(Spam s): + cdef char c + c = s.c + s.c = c + +cdef void eggs_p(Spam s): + cdef float *p + p = s.p[0] + s.p[0] = p + spam = ham + +def test_i(): + spam.i = 1 + eggs_i(spam) + +def test_c(): + spam.c = c'a' + eggs_c(spam) + +def test_p(): + cdef float f + spam.p[0] = &f + eggs_p(spam) diff --git a/tests/run/dict.pyx b/tests/run/dict.pyx index 2ae22a3c..3c51fb07 100644 --- a/tests/run/dict.pyx +++ b/tests/run/dict.pyx @@ -1,7 +1,39 @@ -def f(adict, key1, value1, key2, value2): - adict = {} - adict = {key1:value1} - adict = {key1:value1, key2:value2} - adict = {key1:value1, key2:value2,} - adict = {"parrot":"resting", "answer":42} - \ No newline at end of file +__doc__ = """ + >>> empty() + {} + >>> keyvalue(1, 2) + {1: 2} + + >>> keyvalues(1, 2, 3, 4) + {1: 2, 3: 4} + >>> keyvalues2(1, 2, 3, 4) + {1: 2, 3: 4} + + >>> len(constant()) + 2 + >>> constant()['parrot'] + 'resting' + >>> constant()['answer'] + 42 +""" + +def empty(): + d = {} + return d + +def keyvalue(key, value): + d = {key:value} + return d + +def keyvalues(key1, value1, key2, value2): + d = {key1:value1, key2:value2} + return d + +def keyvalues2(key1, value1, key2, value2): + d = {key1:value1, key2:value2,} + return d + +def constant(): + d = {"parrot":"resting", "answer":42} + return d + diff --git a/tests/run/dietachmayer1.pyx b/tests/run/dietachmayer1.pyx index d86f8738..09e5558e 100644 --- a/tests/run/dietachmayer1.pyx +++ b/tests/run/dietachmayer1.pyx @@ -1,4 +1,9 @@ +__doc__ = """ + >>> test() + 1.0 +""" + def test(): cdef float v[10][10] v[1][2] = 1.0 - print v[1][2] + return v[1][2] diff --git a/tests/run/extinherit.pyx b/tests/run/extinherit.pyx index ffd12451..633d8c3a 100644 --- a/tests/run/extinherit.pyx +++ b/tests/run/extinherit.pyx @@ -1,3 +1,9 @@ +__doc__ = """ + >>> p = create() + >>> rest(p) + 0 +""" + cdef class Parrot: cdef object name cdef int alive @@ -5,11 +11,24 @@ cdef class Parrot: cdef class Norwegian(Parrot): cdef object plumage_colour -cdef void rest(Norwegian polly): +def create(): + cdef Parrot p + p = Norwegian() + p.alive = 1 + return p + +def rest(Norwegian polly): cdef Parrot fred cdef object spam + spam = None + fred = polly polly = fred polly = spam + assert polly is None + assert fred.alive + spam = polly - polly.alive = 0 + fred.alive = 0 + + return fred.alive diff --git a/tests/run/extlen.pyx b/tests/run/extlen.pyx index e03a56d0..2577a02d 100644 --- a/tests/run/extlen.pyx +++ b/tests/run/extlen.pyx @@ -1,3 +1,8 @@ +__doc__ = """ + >>> len(Spam()) + 0 +""" + cdef class Spam: def __len__(self): diff --git a/tests/run/extstarargs.pyx b/tests/run/extstarargs.pyx index 5757b23f..dc00d2e9 100644 --- a/tests/run/extstarargs.pyx +++ b/tests/run/extstarargs.pyx @@ -1,3 +1,45 @@ +__doc__ = """ + >>> s = Silly(1,2,3, 'test') + + >>> s.spam(1,2,3) + >>> s.spam(1,2) + Traceback (most recent call last): + TypeError: function takes exactly 3 arguments (2 given) + >>> s.spam(1,2,3,4) + Traceback (most recent call last): + TypeError: function takes exactly 3 arguments (4 given) + >>> s.spam(1,2,3, a=1) + Traceback (most recent call last): + TypeError: 'a' is an invalid keyword argument for this function + + >>> s.grail(1,2,3) + >>> s.grail(1,2,3,4) + >>> s.grail(1,2,3,4,5,6,7,8,9) + >>> s.grail(1,2) + Traceback (most recent call last): + TypeError: function takes exactly 3 arguments (2 given) + >>> s.grail(1,2,3, a=1) + Traceback (most recent call last): + TypeError: 'a' is an invalid keyword argument for this function + + >>> s.swallow(1,2,3) + >>> s.swallow(1,2,3,4) + Traceback (most recent call last): + TypeError: function takes at most 3 positional arguments (4 given) + >>> s.swallow(1,2,3, a=1, b=2) + >>> s.swallow(1,2,3, x=1) + Traceback (most recent call last): + TypeError: keyword parameter 'x' was given by position and by name + + >>> s.creosote(1,2,3) + >>> s.creosote(1,2,3,4) + >>> s.creosote(1,2,3, a=1) + >>> s.creosote(1,2,3,4, a=1, b=2) + >>> s.creosote(1,2,3,4, x=1) + Traceback (most recent call last): + TypeError: keyword parameter 'x' was given by position and by name +""" + cdef class Silly: def __init__(self, *a): diff --git a/tests/run/ishimoto2.pyx b/tests/run/ishimoto2.pyx index 3ab94028..24541f0c 100644 --- a/tests/run/ishimoto2.pyx +++ b/tests/run/ishimoto2.pyx @@ -1,3 +1,14 @@ +__doc__ = """ + >>> C().xxx(5) + 5 + >>> C().xxx() + 'a b' + >>> C().xxx(42) + 42 + >>> C().xxx() + 'a b' +""" + class C: def xxx(self, p="a b"): - pass + return p diff --git a/tests/run/kwonlyargs.pyx b/tests/run/kwonlyargs.pyx index a1be9cd7..78c523fd 100644 --- a/tests/run/kwonlyargs.pyx +++ b/tests/run/kwonlyargs.pyx @@ -1,3 +1,68 @@ +__doc__ = """ + >>> c(1,2,3) + >>> c(1,2,3,4) + Traceback (most recent call last): + TypeError: function takes exactly 3 arguments (4 given) + + >>> d(1,2) + >>> d(1,2, c=1) + + >>> d(1,2,3) + Traceback (most recent call last): + TypeError: function takes at most 2 positional arguments (3 given) + >>> d(1,2, d=1) + Traceback (most recent call last): + TypeError: 'd' is an invalid keyword argument for this function + + >>> e(1,2) + >>> e(1,2, c=1) + >>> e(1,2, d=1) + >>> e(1,2, c=1, d=2, e=3) + >>> e(1,2,3) + >>> e(1,2,3,4) + Traceback (most recent call last): + TypeError: function takes at most 3 positional arguments (4 given) + + >>> f(1,2, c=1) + >>> f(1,2, c=1, d=2) + + >>> f(1,2,3) + Traceback (most recent call last): + TypeError: function takes at most 2 positional arguments (3 given) + >>> f(1,2) + Traceback (most recent call last): + TypeError: required keyword argument 'c' is missing + >>> f(1,2, c=1, e=2) + Traceback (most recent call last): + TypeError: 'e' is an invalid keyword argument for this function + + >>> g(1,2, c=1, f=2) + >>> g(1,2, c=1, e=0, f=2, d=11) + >>> g(1,2, c=1, f=2, e=0, x=25) + + >>> g(1,2,3) + Traceback (most recent call last): + TypeError: function takes at most 2 positional arguments (3 given) + >>> g(1,2) + Traceback (most recent call last): + TypeError: required keyword argument 'c' is missing + >>> g(1,2, c=1) + Traceback (most recent call last): + TypeError: required keyword argument 'f' is missing + + >>> h(1,2, c=1, f=2) + >>> h(1,2, c=1, f=2, e=3) + >>> h(1,2,3,4,5,6, c=1, f=2) + >>> h(1,2,3,4,5,6, c=1, f=2, e=3, x=25, y=11) + + >>> h(1,2,3) + Traceback (most recent call last): + TypeError: required keyword argument 'c' is missing + >>> h(1,2, d=1) + Traceback (most recent call last): + TypeError: required keyword argument 'c' is missing +""" + def c(a, b, c): z = 33 diff --git a/tests/run/modbody.pyx b/tests/run/modbody.pyx index 0cf3e14c..8315b1fc 100644 --- a/tests/run/modbody.pyx +++ b/tests/run/modbody.pyx @@ -1,3 +1,15 @@ +__doc__ = """ + >>> f() + >>> g + 42 + >>> x + 'spam' + >>> y + 'eggs' + >>> z + 'spameggs' +""" + def f(): pass diff --git a/tests/run/modop.pyx b/tests/run/modop.pyx index 9298d31e..539ccacc 100644 --- a/tests/run/modop.pyx +++ b/tests/run/modop.pyx @@ -1,10 +1,27 @@ -def f(): - cdef int int1, int2, int3 - cdef char *str2, *str3 - obj1 = 1 - obj2 = 2 - obj3 = 3 +__doc__ = """ + >>> modobj(9,2) + 1 + >>> modobj('%d', 5) + '5' + + >>> modint(9,2) + 1 +""" + +def modobj(obj2, obj3): + obj1 = obj2 % obj3 + return obj1 + +def modint(int int2, int int3): + cdef int int1 int1 = int2 % int3 + return int1 + +cdef modptr(): + # FIXME!!! + cdef char *str2, *str3 + str2 = "spam" + str3 = "eggs" + obj1 = str2 % str3 - obj1 = obj2 % obj3 - \ No newline at end of file + return obj1 diff --git a/tests/run/naanou_1.pyx b/tests/run/naanou_1.pyx deleted file mode 100644 index d79ad652..00000000 --- a/tests/run/naanou_1.pyx +++ /dev/null @@ -1,2 +0,0 @@ -def f(a, *p, **n): - pass diff --git a/tests/run/new_style_exceptions.pyx b/tests/run/new_style_exceptions.pyx index 8ae72409..34c8bd66 100644 --- a/tests/run/new_style_exceptions.pyx +++ b/tests/run/new_style_exceptions.pyx @@ -1,3 +1,9 @@ +__doc__ = """ + >>> test(Exception('hi')) + Raising: Exception('hi',) + Caught: Exception('hi',) +""" + import sys def test(obj): diff --git a/tests/run/pinard5.pyx b/tests/run/pinard5.pyx index 32c6527d..8a2e3510 100644 --- a/tests/run/pinard5.pyx +++ b/tests/run/pinard5.pyx @@ -1,10 +1,22 @@ +__doc__ = """ + >>> test() + 1 +""" + cdef class Tri: - pass + def test(self): + return 1 cdef class Curseur: cdef Tri tri def detail(self): - produire_fiches(self.tri) + return produire_fiches(self.tri) cdef produire_fiches(Tri tri): - pass + return tri.test() + +def test(): + cdef Curseur c + c = Curseur() + c.tri = Tri() + return c.detail() diff --git a/tests/run/pinard7.pyx b/tests/run/pinard7.pyx index 4a611967..a464f2cd 100644 --- a/tests/run/pinard7.pyx +++ b/tests/run/pinard7.pyx @@ -1,3 +1,10 @@ +__doc__ = """ + >>> c = build() + >>> c.method() + Traceback (most recent call last): + AssertionError: 1 +""" + cdef enum Mode: a = 1 b = 2 @@ -7,3 +14,9 @@ cdef class Curseur: def method(self): assert False, self.mode + +def build(): + cdef Curseur c + c = Curseur() + c.mode = a + return c diff --git a/tests/run/pyextattrref.pyx b/tests/run/pyextattrref.pyx index cee11189..3f9261a9 100644 --- a/tests/run/pyextattrref.pyx +++ b/tests/run/pyextattrref.pyx @@ -1,3 +1,7 @@ +__doc__ = """ + >>> +""" + cdef class Eggs: cdef object ham diff --git a/tests/run/r_mang1.pyx b/tests/run/r_mang1.pyx index fcf140af..64ef5613 100644 --- a/tests/run/r_mang1.pyx +++ b/tests/run/r_mang1.pyx @@ -1,2 +1,12 @@ +__doc__ = """ + >>> import re + >>> t + ('2',) + >>> t == re.search('(\\d+)', '-2.80 98\\n').groups() + True +""" + +# this is a string constant test, not a test for 're' + import re t = re.search('(\d+)', '-2.80 98\n').groups() diff --git a/tests/run/ref2local.pyx b/tests/run/ref2local.pyx index cfcc66be..bfe1b8ef 100644 --- a/tests/run/ref2local.pyx +++ b/tests/run/ref2local.pyx @@ -1,3 +1,9 @@ +__doc__ = """ + >>> f() + 42 +""" + def f(): a = 42 b = a + return b diff --git a/tests/run/return.pyx b/tests/run/return.pyx index b07ad14c..81a2ddb9 100644 --- a/tests/run/return.pyx +++ b/tests/run/return.pyx @@ -1,3 +1,10 @@ +__doc__ = """ + >>> f('test') + >>> test_g() + >>> test_h(5) + 5 +""" + def f(a): return return a @@ -8,5 +15,11 @@ cdef void g(): cdef int h(a): cdef int i + i = a return i - \ No newline at end of file + +def test_g(): + g() + +def test_h(i): + return h(i) diff --git a/tests/run/slice3.pyx b/tests/run/slice3.pyx index 07321b85..36f618c7 100644 --- a/tests/run/slice3.pyx +++ b/tests/run/slice3.pyx @@ -1,7 +1,46 @@ -def f(obj1, obj2, obj3, obj4, obj5): +__doc__ = """ + >>> class Test(object): + ... def __setitem__(self, key, value): + ... print key, value + ... def __getitem__(self, key): + ... print key + ... return self + + >>> ellipsis(Test()) + Ellipsis + + >>> full(Test()) + slice(None, None, None) + + >>> select(0, Test(), 10, 20, 30) + slice(10, None, None) + slice(None, 20, None) + slice(None, None, 30) + slice(10, 20, None) + slice(10, None, 30) + slice(None, 20, 30) + slice(10, 20, 30) + slice(1, 2, 3) + + >>> set(Test(), -11) + slice(1, 2, 3) -11 +""" + +def ellipsis(o): + obj1 = o[...] + +def full(o): + obj1 = o[::] + +def set(o, v): cdef int int3, int4, int5 - obj1 = obj2[...] - obj1 = obj2[::] + int3, int4, int5 = 1,2,3 + o[int3:int4:int5] = v + +def select(obj1, obj2, obj3, obj4, obj5): + cdef int int3, int4, int5 + int3, int4, int5 = 1,2,3 + obj1 = obj2[obj3::] obj1 = obj2[:obj4:] obj1 = obj2[::obj5] @@ -10,5 +49,4 @@ def f(obj1, obj2, obj3, obj4, obj5): obj1 = obj2[:obj4:obj5] obj1 = obj2[obj3:obj4:obj5] obj1 = obj2[int3:int4:int5] - obj1[int3:int4:int5] = obj2 - \ No newline at end of file + diff --git a/tests/run/starargs.pyx b/tests/run/starargs.pyx index 67cd01c9..5ca223b3 100644 --- a/tests/run/starargs.pyx +++ b/tests/run/starargs.pyx @@ -1,3 +1,43 @@ +__doc__ = """ + >>> spam(1,2,3) + >>> spam(1,2) + Traceback (most recent call last): + TypeError: function takes exactly 3 arguments (2 given) + >>> spam(1,2,3,4) + Traceback (most recent call last): + TypeError: function takes exactly 3 arguments (4 given) + >>> spam(1,2,3, a=1) + Traceback (most recent call last): + TypeError: 'a' is an invalid keyword argument for this function + + >>> grail(1,2,3) + >>> grail(1,2,3,4) + >>> grail(1,2,3,4,5,6,7,8,9) + >>> grail(1,2) + Traceback (most recent call last): + TypeError: function takes exactly 3 arguments (2 given) + >>> grail(1,2,3, a=1) + Traceback (most recent call last): + TypeError: 'a' is an invalid keyword argument for this function + + >>> swallow(1,2,3) + >>> swallow(1,2,3,4) + Traceback (most recent call last): + TypeError: function takes at most 3 positional arguments (4 given) + >>> swallow(1,2,3, a=1, b=2) + >>> swallow(1,2,3, x=1) + Traceback (most recent call last): + TypeError: keyword parameter 'x' was given by position and by name + + >>> creosote(1,2,3) + >>> creosote(1,2,3,4) + >>> creosote(1,2,3, a=1) + >>> creosote(1,2,3,4, a=1, b=2) + >>> creosote(1,2,3,4, x=1) + Traceback (most recent call last): + TypeError: keyword parameter 'x' was given by position and by name +""" + def spam(x, y, z): pass @@ -9,4 +49,3 @@ def swallow(x, y, z, **k): def creosote(x, y, z, *a, **k): pass - diff --git a/tests/run/subop.pyx b/tests/run/subop.pyx index 717edbbc..d71b29ed 100644 --- a/tests/run/subop.pyx +++ b/tests/run/subop.pyx @@ -1,11 +1,30 @@ +__doc__ = """ + >>> f() + (-1, -1) + >>> p() + 0 +""" + def f(): cdef int int1, int2, int3 - cdef char *ptr1, *ptr2, *ptr3 obj1 = 1 obj2 = 2 obj3 = 3 + int2 = 2 + int3 = 3 + int1 = int2 - int3 + obj1 = obj2 - int3 + return int1, obj1 + +def p(): + cdef int int1, int2, int3 + cdef char *ptr1, *ptr2, *ptr3 + int2 = 2 + int3 = 3 + ptr2 = "test" + ptr3 = ptr2 + ptr1 = ptr2 - int3 int1 = ptr2 - ptr3 - obj1 = obj2 - int3 - \ No newline at end of file + return int1 diff --git a/tests/run/varargcall.pyx b/tests/run/varargcall.pyx index 13d7201f..02626952 100644 --- a/tests/run/varargcall.pyx +++ b/tests/run/varargcall.pyx @@ -1,6 +1,10 @@ +__doc__ = """ + >>> swallow() +""" + cdef grail(char *blarg, ...): pass -cdef swallow(): +def swallow(): grail("spam") grail("spam", 42) diff --git a/tests/run/wundram1.pyx b/tests/run/wundram1.pyx index 7360cb69..c8933dae 100644 --- a/tests/run/wundram1.pyx +++ b/tests/run/wundram1.pyx @@ -1,2 +1,8 @@ +__doc__ = """ + >>> x + 5L +""" + cdef unsigned int ui +ui = 5 x = ui -- 2.26.2