From 481d7becb3376db1ecd850197ebbaea8dcbd7d3f Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Thu, 15 May 2008 00:30:45 +0200 Subject: [PATCH] lots of test fixes for Py3 --- tests/run/r_barbieri1.pyx | 4 ++++ tests/run/r_bowden1.pyx | 4 ++-- tests/run/r_docstrings.pyx | 32 ++++++++++++++++++-------------- tests/run/r_extcomplex2.pyx | 4 ++-- tests/run/r_huss3.pyx | 4 ++++ tests/run/r_mitch_chapman_2.pyx | 12 ++++++++---- tests/run/r_primes.pyx | 2 +- tests/run/r_pythonapi.pyx | 8 ++++++-- tests/run/r_spamtype.pyx | 4 ++-- tests/run/r_vree_1.pyx | 2 +- tests/run/simpcall.pyx | 6 +++++- tests/run/slice3.pyx | 6 +++--- tests/run/starargs.pyx | 2 +- tests/run/strconstinclass.pyx | 2 +- tests/run/strfunction.pyx | 15 ++++++++------- 15 files changed, 66 insertions(+), 41 deletions(-) diff --git a/tests/run/r_barbieri1.pyx b/tests/run/r_barbieri1.pyx index 2f75ba41..614c8270 100644 --- a/tests/run/r_barbieri1.pyx +++ b/tests/run/r_barbieri1.pyx @@ -6,6 +6,10 @@ __doc__ = u""" Exception: crash-me """ +import sys +if sys.version_info[0] >= 3: + __doc__ = __doc__.replace(u"Exception, e'", u"Exception as e") + cdef class A: def __cinit__(self): raise Exception("crash-me") diff --git a/tests/run/r_bowden1.pyx b/tests/run/r_bowden1.pyx index 920c00f2..e205ad10 100644 --- a/tests/run/r_bowden1.pyx +++ b/tests/run/r_bowden1.pyx @@ -1,7 +1,7 @@ __doc__ = u""" ->>> print f(100) +>>> f(100) 101 ->>> print g(3000000000) +>>> g(3000000000) 3000000001 """ diff --git a/tests/run/r_docstrings.pyx b/tests/run/r_docstrings.pyx index 27e83271..1fe98d47 100644 --- a/tests/run/r_docstrings.pyx +++ b/tests/run/r_docstrings.pyx @@ -1,18 +1,18 @@ __doc__ = u""" >>> f.__doc__ - 'This is a function docstring.' + u'This is a function docstring.' >>> C.__doc__ - 'This is a class docstring.' + u'This is a class docstring.' >>> CS.__doc__ - 'This is a subclass docstring.' - >>> print CSS.__doc__ + u'This is a subclass docstring.' + >>> print(CSS.__doc__) None >>> T.__doc__ - 'This is an extension type docstring.' + u'This is an extension type docstring.' >>> TS.__doc__ - 'This is an extension subtype docstring.' + u'This is an extension subtype docstring.' >>> TSS.__doc__ Compare with standard Python: @@ -20,7 +20,7 @@ Compare with standard Python: >>> def f(): ... 'This is a function docstring.' >>> f.__doc__ - 'This is a function docstring.' + u'This is a function docstring.' >>> class C: ... 'This is a class docstring.' @@ -30,29 +30,33 @@ Compare with standard Python: ... pass >>> C.__doc__ - 'This is a class docstring.' + u'This is a class docstring.' >>> CS.__doc__ - 'This is a subclass docstring.' + u'This is a subclass docstring.' >>> CSS.__doc__ """ +import sys +if sys.version_info[0] >= 3: + __doc__ = __doc__.replace(u" u'", u" '") + def f(): - "This is a function docstring." + u"This is a function docstring." class C: - "This is a class docstring." + u"This is a class docstring." class CS(C): - "This is a subclass docstring." + u"This is a subclass docstring." class CSS(CS): pass cdef class T: - "This is an extension type docstring." + u"This is an extension type docstring." cdef class TS(T): - "This is an extension subtype docstring." + u"This is an extension subtype docstring." cdef class TSS(TS): pass diff --git a/tests/run/r_extcomplex2.pyx b/tests/run/r_extcomplex2.pyx index 458c3fa8..53292ff5 100644 --- a/tests/run/r_extcomplex2.pyx +++ b/tests/run/r_extcomplex2.pyx @@ -1,7 +1,7 @@ __doc__ = u""" >>> c = eggs() - >>> print "eggs returned:", c - eggs returned: (17+42j) + >>> c + (17+42j) >>> spam(c) Real: 17.0 Imag: 42.0 diff --git a/tests/run/r_huss3.pyx b/tests/run/r_huss3.pyx index 5e724342..9aff6821 100644 --- a/tests/run/r_huss3.pyx +++ b/tests/run/r_huss3.pyx @@ -10,6 +10,10 @@ ValueError: ... print "%s: %s" % (e.__class__.__name__, e) """ +import sys +if sys.version_info[0] >= 3: + __doc__ = __doc__.replace(u"Exception, e'", u"Exception as e") + def bar(): try: raise TypeError diff --git a/tests/run/r_mitch_chapman_2.pyx b/tests/run/r_mitch_chapman_2.pyx index 82057a1c..4e3d19c6 100644 --- a/tests/run/r_mitch_chapman_2.pyx +++ b/tests/run/r_mitch_chapman_2.pyx @@ -1,11 +1,15 @@ __doc__ = u""" >>> boolExpressionsFail() - 'Not 2b' + u'Not 2b' """ +import sys +if sys.version_info[0] >= 3: + __doc__ = __doc__.replace(u" u'", u" '") + def boolExpressionsFail(): dict = {1: 1} - if not dict.has_key("2b"): - return "Not 2b" + if not "2b" in dict: + return u"Not 2b" else: - return "2b?" + return u"2b?" diff --git a/tests/run/r_primes.pyx b/tests/run/r_primes.pyx index ce74fdf0..16a93b06 100644 --- a/tests/run/r_primes.pyx +++ b/tests/run/r_primes.pyx @@ -1,5 +1,5 @@ __doc__ = u""" - >>> print primes(20) + >>> primes(20) [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71] """ diff --git a/tests/run/r_pythonapi.pyx b/tests/run/r_pythonapi.pyx index 89adc474..edf3ddaa 100644 --- a/tests/run/r_pythonapi.pyx +++ b/tests/run/r_pythonapi.pyx @@ -1,9 +1,13 @@ __doc__ = u""" >>> x = spam() - >>> print repr(x) - 'Ftang\\x00Ftang!' + >>> print(repr(x)) + b'Ftang\\x00Ftang!' """ +import sys +if sys.version_info[0] < 3: + __doc__ = __doc__.replace(u" b'", u" '") + cdef extern from "string.h": void memcpy(char *d, char *s, int n) diff --git a/tests/run/r_spamtype.pyx b/tests/run/r_spamtype.pyx index 6a087c8a..70d85ea0 100644 --- a/tests/run/r_spamtype.pyx +++ b/tests/run/r_spamtype.pyx @@ -1,9 +1,9 @@ __doc__ = u""" >>> s = Spam() - >>> print s.get_tons() + >>> s.get_tons() 17 >>> s.set_tons(42) - >>> print s.get_tons() + >>> s.get_tons() 42 >>> s = None 42 tons of spam is history. diff --git a/tests/run/r_vree_1.pyx b/tests/run/r_vree_1.pyx index 085b2c8b..fc4a5bc2 100644 --- a/tests/run/r_vree_1.pyx +++ b/tests/run/r_vree_1.pyx @@ -1,4 +1,4 @@ -__doc__ = u""" +__doc__ = """# disabled in Py3 >>> test(0) 0L >>> test(1) diff --git a/tests/run/simpcall.pyx b/tests/run/simpcall.pyx index 8c66c90c..0ce249ef 100644 --- a/tests/run/simpcall.pyx +++ b/tests/run/simpcall.pyx @@ -1,5 +1,5 @@ __doc__ = u""" - >>> z(1,9.2,'test') + >>> z(1,9.2, b'test') >>> failtype() Traceback (most recent call last): TypeError: an integer is required @@ -13,6 +13,10 @@ __doc__ = u""" TypeError: function takes exactly 2 arguments (1 given) """ +import sys +if sys.version_info[0] < 3: + __doc__ = __doc__.replace(u" b'", u" '") + def f(x, y): x = y diff --git a/tests/run/slice3.pyx b/tests/run/slice3.pyx index f3336507..928be777 100644 --- a/tests/run/slice3.pyx +++ b/tests/run/slice3.pyx @@ -1,9 +1,9 @@ __doc__ = u""" >>> class Test(object): ... def __setitem__(self, key, value): - ... print key, value + ... print((key, value)) ... def __getitem__(self, key): - ... print key + ... print(key) ... return self >>> ellipsis(Test()) @@ -23,7 +23,7 @@ __doc__ = u""" slice(1, 2, 3) >>> set(Test(), -11) - slice(1, 2, 3) -11 + (slice(1, 2, 3), -11) """ def ellipsis(o): diff --git a/tests/run/starargs.pyx b/tests/run/starargs.pyx index 803eaa54..d5fde52a 100644 --- a/tests/run/starargs.pyx +++ b/tests/run/starargs.pyx @@ -85,7 +85,7 @@ __doc__ = u""" """ cdef sorteditems(d): - l = d.items() + l = list(d.items()) l.sort() return tuple(l) diff --git a/tests/run/strconstinclass.pyx b/tests/run/strconstinclass.pyx index 72fc7277..bfde9de0 100644 --- a/tests/run/strconstinclass.pyx +++ b/tests/run/strconstinclass.pyx @@ -1,6 +1,6 @@ __doc__ = u""" >>> c = C() - >>> print c.x + >>> print(c.x) foo """ diff --git a/tests/run/strfunction.pyx b/tests/run/strfunction.pyx index 51af8360..b0bc01d0 100644 --- a/tests/run/strfunction.pyx +++ b/tests/run/strfunction.pyx @@ -1,14 +1,14 @@ __doc__ = u""" - >>> s('test') - 'test' + >>> s('test', **encoding) + b'test' >>> z - 'test' + b'test' >>> c('testing') - 'testing' + b'testing' >>> sub('testing a subtype') - 'testing a subtype' - >>> subs('testing a subtype') - 'testing a subtype' + b'testing a subtype' + >>> subs('testing a subtype', **encoding) + b'testing a subtype' # >>> csub('testing a subtype') # 'testing a subtype' @@ -21,6 +21,7 @@ if sys.version_info[0] >= 3: encoding = {'encoding' : 'ASCII'} else: encoding = {} + __doc__ = __doc__.replace(u" b'", u" '") s = str z = str('test', **encoding) -- 2.26.2