From 4d5dfea12a5533af0716b2f10afb4d481ec6d07b Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Fri, 29 Nov 2013 13:58:40 +0100 Subject: [PATCH] disable autotestdict when testing under Py3.4 and adapt autotestdict tests to make up for its smarter docstring lookup --- runtests.py | 2 ++ tests/run/autotestdict.pyx | 18 +++++++++--------- tests/run/autotestdict_all.pyx | 18 +++++++++--------- tests/run/autotestdict_cdef.pyx | 18 +++++++++--------- tests/run/autotestdict_skip.pyx | 3 ++- 5 files changed, 31 insertions(+), 28 deletions(-) diff --git a/runtests.py b/runtests.py index f131ee4..95a5b5a 100755 --- a/runtests.py +++ b/runtests.py @@ -551,6 +551,8 @@ class CythonCompileTestCase(unittest.TestCase): 'error_on_uninitialized') ] self._saved_default_directives = Options.directive_defaults.items() Options.warning_errors = self.warning_errors + if sys.version_info >= (3, 4): + Options.directive_defaults['autotestdict'] = False if not os.path.exists(self.workdir): os.makedirs(self.workdir) diff --git a/tests/run/autotestdict.pyx b/tests/run/autotestdict.pyx index 0824aff..32921f8 100644 --- a/tests/run/autotestdict.pyx +++ b/tests/run/autotestdict.pyx @@ -1,5 +1,5 @@ -# Directive defaults to True - +# cython: autotestdict=True +# Directive defaults to True, but not when testing in Py3.4 """ Tests autotestdict compiler directive. @@ -15,9 +15,9 @@ MyCdefClass.method (line 74) ; >>> add_log("cdef class method") MyClass.method (line 63) ; >>> add_log("class method") mycpdeffunc (line 50) ; >>> add_log("cpdef") myfunc (line 40) ; >>> add_log("def") - """ +import sys log = [] cdef cdeffunc(): @@ -28,12 +28,12 @@ cdef cdeffunc(): cdeffunc() # make sure it's being used def all_tests_run(): - log.sort() - assert log == [u'cdef class', u'cdef class method', u'class', u'class method', u'cpdef', u'cpdef class method', u'def'], log + assert sorted(log) == sorted([u'cdef class', u'class'] + ( + (1 if sys.version_info < (3, 4) else 2) * [u'cdef class method', u'class method', u'cpdef', u'cpdef class method', u'def'])), sorted(log) def add_log(s): log.append(unicode(s)) - if len(log) == len(__test__) + 2: + if len(log) == len(__test__) + (2 if sys.version_info < (3, 4) else 7): # Final per-function doctest executed all_tests_run() @@ -78,7 +78,7 @@ cdef class MyCdefClass: """>>> add_log("cpdef class method")""" cdef cdef_method(self): - """>>> add_log("cdef class method")""" + """>>> add_log("cdef class cmethod")""" def __cinit__(self): """ @@ -116,7 +116,7 @@ cdef class MyCdefClass: """ Should not be included, as it can't be looked up with getattr in Py 3.1 - >>> True + >>> sys.version_info < (3, 4) False """ @@ -124,7 +124,7 @@ cdef class MyCdefClass: """ Should not be included, as it can't be looked up with getattr in Py 3.1 - >>> True + >>> sys.version_info < (3, 4) False """ diff --git a/tests/run/autotestdict_all.pyx b/tests/run/autotestdict_all.pyx index 624a12b..b93e7db 100644 --- a/tests/run/autotestdict_all.pyx +++ b/tests/run/autotestdict_all.pyx @@ -1,4 +1,4 @@ -# cython: autotestdict.all=True +# cython: autotestdict=True, autotestdict.all=True """ Tests autotestdict compiler directive. @@ -10,7 +10,7 @@ all_tests_run() is executed which does final validation. >>> items.sort() >>> for key, value in items: ... print('%s ; %s' % (key, value)) -MyCdefClass.cdef_method (line 79) ; >>> add_log("cdef class method") +MyCdefClass.cdef_method (line 79) ; >>> add_log("cdef class cmethod") MyCdefClass.cpdef_method (line 76) ; >>> add_log("cpdef class method") MyCdefClass.method (line 73) ; >>> add_log("cdef class method") MyClass.method (line 62) ; >>> add_log("class method") @@ -18,9 +18,9 @@ cdeffunc (line 26) ; >>> add_log("cdef") doc_without_test (line 43) ; Some docs mycpdeffunc (line 49) ; >>> add_log("cpdef") myfunc (line 40) ; >>> add_log("def") - """ +import sys log = [] cdef cdeffunc(): @@ -28,12 +28,12 @@ cdef cdeffunc(): cdeffunc() # make sure it's being used def all_tests_run(): - log.sort() - assert log == [u'cdef', u'cdef class', u'cdef class method', u'class', u'class method', u'cpdef', u'cpdef class method', u'def'], log + assert sorted(log) == sorted([u'cdef', u'cdef class', u'class', u'cdef class cmethod'] + ( + (1 if sys.version_info < (3, 4) else 2) * [u'cdef class method', u'class method', u'cpdef', u'cpdef class method', u'def'])), sorted(log) def add_log(s): log.append(unicode(s)) - if len(log) == len(__test__): + if len(log) == len(__test__) + (1 if sys.version_info < (3, 4) else 6): # Final per-function doctest executed all_tests_run() @@ -77,7 +77,7 @@ cdef class MyCdefClass: """>>> add_log("cpdef class method")""" cdef cdef_method(self): - """>>> add_log("cdef class method")""" + """>>> add_log("cdef class cmethod")""" def __cinit__(self): """ @@ -115,7 +115,7 @@ cdef class MyCdefClass: """ Should not be included, as it can't be looked up with getattr in Py 3.1 - >>> True + >>> sys.version_info < (3, 4) False """ @@ -123,7 +123,7 @@ cdef class MyCdefClass: """ Should not be included, as it can't be looked up with getattr in Py 3.1 - >>> True + >>> sys.version_info < (3, 4) False """ diff --git a/tests/run/autotestdict_cdef.pyx b/tests/run/autotestdict_cdef.pyx index c490987..1102d70 100644 --- a/tests/run/autotestdict_cdef.pyx +++ b/tests/run/autotestdict_cdef.pyx @@ -1,4 +1,4 @@ -# cython: autotestdict.cdef=True +# cython: autotestdict=True, autotestdict.cdef=True """ Tests autotestdict compiler directive. @@ -10,16 +10,16 @@ all_tests_run() is executed which does final validation. >>> items.sort() >>> for key, value in items: ... print('%s ; %s' % (key, value)) -MyCdefClass.cdef_method (line 78) ; >>> add_log("cdef class method") +MyCdefClass.cdef_method (line 78) ; >>> add_log("cdef class cmethod") MyCdefClass.cpdef_method (line 75) ; >>> add_log("cpdef class method") MyCdefClass.method (line 72) ; >>> add_log("cdef class method") MyClass.method (line 61) ; >>> add_log("class method") cdeffunc (line 25) ; >>> add_log("cdef") mycpdeffunc (line 48) ; >>> add_log("cpdef") myfunc (line 39) ; >>> add_log("def") - """ +import sys log = [] cdef cdeffunc(): @@ -27,12 +27,12 @@ cdef cdeffunc(): cdeffunc() # make sure it's being used def all_tests_run(): - log.sort() - assert log == [u'cdef', u'cdef class', u'cdef class method', u'class', u'class method', u'cpdef', u'cpdef class method', u'def'], log + assert sorted(log) == sorted([u'cdef', u'cdef class', u'cdef class cmethod', u'class'] + ( + ((1 if sys.version_info < (3, 4) else 2) * [u'cdef class method', u'class method', u'cpdef', u'cpdef class method', u'def']))), sorted(log) def add_log(s): log.append(unicode(s)) - if len(log) == len(__test__) + 1: + if len(log) == len(__test__) + (2 if sys.version_info < (3, 4) else 7): # Final per-function doctest executed all_tests_run() @@ -76,7 +76,7 @@ cdef class MyCdefClass: """>>> add_log("cpdef class method")""" cdef cdef_method(self): - """>>> add_log("cdef class method")""" + """>>> add_log("cdef class cmethod")""" def __cinit__(self): """ @@ -114,7 +114,7 @@ cdef class MyCdefClass: """ Should not be included, as it can't be looked up with getattr in Py 3.1 - >>> True + >>> sys.version_info < (3, 4) False """ @@ -122,7 +122,7 @@ cdef class MyCdefClass: """ Should not be included, as it can't be looked up with getattr in Py 3.1 - >>> True + >>> sys.version_info < (3, 4) False """ diff --git a/tests/run/autotestdict_skip.pyx b/tests/run/autotestdict_skip.pyx index 3ea6d82..dd1c652 100644 --- a/tests/run/autotestdict_skip.pyx +++ b/tests/run/autotestdict_skip.pyx @@ -10,10 +10,11 @@ If this doesn't work, then the function doctest should fail. True """ +import sys def func(): """ - >>> True + >>> sys.version_info < (3, 4) False """ -- 2.7.4