| 1 |
PYTHON setup.py build_ext --inplace |
| 2 |
PYTHON -c "import bar" |
| 3 |
PYTHON -c "import run" |
| 4 |
PYTHON -c "import crun" |
| 5 |
|
| 6 |
######## setup.py ######## |
| 7 |
|
| 8 |
from Cython.Build.Dependencies import cythonize |
| 9 |
from distutils.core import setup |
| 10 |
|
| 11 |
setup( |
| 12 |
ext_modules = cythonize(["*.pyx", "aa.py"], compiler_directives={'legacy_implicit_noexcept': True}), |
| 13 |
) |
| 14 |
|
| 15 |
######## run.py ######## |
| 16 |
|
| 17 |
import aa |
| 18 |
|
| 19 |
def check_exception_propagated(c, ret_expected): |
| 20 |
assert c(False) == ret_expected |
| 21 |
try: |
| 22 |
c(True) |
| 23 |
except ValueError: |
| 24 |
pass |
| 25 |
else: |
| 26 |
assert False, "ValueError not raised" |
| 27 |
|
| 28 |
def check_exception_not_propagated(c, ret_expected): |
| 29 |
assert c(False) == ret_expected |
| 30 |
try: |
| 31 |
c(True) |
| 32 |
except ValueError: |
| 33 |
assert False, "ValueError raised" |
| 34 |
else: |
| 35 |
pass |
| 36 |
|
| 37 |
klass = aa.Klass() |
| 38 |
|
| 39 |
check_exception_propagated(klass.m1, 1) |
| 40 |
check_exception_not_propagated(klass.m2, 2) |
| 41 |
check_exception_not_propagated(klass.m3, 3) |
| 42 |
check_exception_propagated(klass.m4, 4) |
| 43 |
check_exception_propagated(klass.m5, 5) |
| 44 |
|
| 45 |
check_exception_propagated(klass.n1, "n1") |
| 46 |
check_exception_propagated(klass.n2, "n2") |
| 47 |
check_exception_propagated(klass.n3, "n3") |
| 48 |
|
| 49 |
check_exception_not_propagated(klass.o3, None) |
| 50 |
check_exception_propagated(klass.o2, None) |
| 51 |
check_exception_not_propagated(klass.o3, None) |
| 52 |
|
| 53 |
check_exception_propagated(aa.m1, 1) |
| 54 |
check_exception_not_propagated(aa.m2, 2) |
| 55 |
check_exception_not_propagated(aa.m3, 3) |
| 56 |
check_exception_propagated(aa.m4, 4) |
| 57 |
check_exception_propagated(aa.m5, 5) |
| 58 |
|
| 59 |
check_exception_propagated(aa.n1, "n1") |
| 60 |
check_exception_propagated(aa.n2, "n2") |
| 61 |
check_exception_propagated(aa.n3, "n3") |
| 62 |
|
| 63 |
check_exception_not_propagated(aa.o3, None) |
| 64 |
check_exception_propagated(aa.o2, None) |
| 65 |
check_exception_not_propagated(aa.o3, None) |
| 66 |
|
| 67 |
######## crun.pyx ######## |
| 68 |
|
| 69 |
cimport aa |
| 70 |
cdef aa.Klass klass = aa.Klass() |
| 71 |
|
| 72 |
assert klass.p1(False) == 1 |
| 73 |
try: klass.p1(True) |
| 74 |
except ValueError: pass |
| 75 |
else: assert False, "ValueError not raised" |
| 76 |
|
| 77 |
assert klass.p2(False) == 2 |
| 78 |
try: klass.p2(True) |
| 79 |
except ValueError: assert False, "ValueError not raised" |
| 80 |
else: pass |
| 81 |
|
| 82 |
assert klass.p3(False) == 3 |
| 83 |
try: klass.p3(True) |
| 84 |
except ValueError: assert False, "ValueError not raised" |
| 85 |
else: pass |
| 86 |
|
| 87 |
assert klass.p4(False) == 4 |
| 88 |
try: klass.p4(True) |
| 89 |
except ValueError: pass |
| 90 |
else: assert False, "ValueError not raised" |
| 91 |
|
| 92 |
assert klass.p5(False) == 5 |
| 93 |
try: klass.p5(True) |
| 94 |
except ValueError: pass |
| 95 |
else: assert False, "ValueError not raised" |
| 96 |
|
| 97 |
assert klass.q1(False) == 'q1' |
| 98 |
try: klass.q1(True) |
| 99 |
except ValueError: pass |
| 100 |
else: assert False, "ValueError not raised" |
| 101 |
|
| 102 |
assert klass.q2(False) == 'q2' |
| 103 |
try: klass.q2(True) |
| 104 |
except ValueError: pass |
| 105 |
else: assert False, "ValueError not raised" |
| 106 |
|
| 107 |
assert klass.q3(False) == 'q3' |
| 108 |
try: klass.q3(True) |
| 109 |
except ValueError: pass |
| 110 |
else: assert False, "ValueError not raised" |
| 111 |
|
| 112 |
klass.r1(False) |
| 113 |
try: klass.r1(True) |
| 114 |
except ValueError: assert False, "ValueError not raised" |
| 115 |
else: pass |
| 116 |
|
| 117 |
klass.r2(False) |
| 118 |
try: klass.r2(True) |
| 119 |
except ValueError: pass |
| 120 |
else: assert False, "ValueError not raised" |
| 121 |
|
| 122 |
klass.r3(False) |
| 123 |
try: klass.r3(True) |
| 124 |
except ValueError: assert False, "ValueError not raised" |
| 125 |
else: pass |
| 126 |
|
| 127 |
assert aa.p1(False) == 1 |
| 128 |
try: aa.p1(True) |
| 129 |
except ValueError: pass |
| 130 |
else: assert False, "ValueError not raised" |
| 131 |
|
| 132 |
assert aa.p2(False) == 2 |
| 133 |
try: aa.p2(True) |
| 134 |
except ValueError: assert False, "ValueError not raised" |
| 135 |
else: pass |
| 136 |
|
| 137 |
assert aa.p3(False) == 3 |
| 138 |
try: aa.p3(True) |
| 139 |
except ValueError: assert False, "ValueError not raised" |
| 140 |
else: pass |
| 141 |
|
| 142 |
assert aa.p4(False) == 4 |
| 143 |
try: aa.p4(True) |
| 144 |
except ValueError: pass |
| 145 |
else: assert False, "ValueError not raised" |
| 146 |
|
| 147 |
assert aa.p5(False) == 5 |
| 148 |
try: aa.p5(True) |
| 149 |
except ValueError: pass |
| 150 |
else: assert False, "ValueError not raised" |
| 151 |
|
| 152 |
assert aa.q1(False) == 'q1' |
| 153 |
try: aa.q1(True) |
| 154 |
except ValueError: pass |
| 155 |
else: assert False, "ValueError not raised" |
| 156 |
|
| 157 |
assert aa.q2(False) == 'q2' |
| 158 |
try: aa.q2(True) |
| 159 |
except ValueError: pass |
| 160 |
else: assert False, "ValueError not raised" |
| 161 |
|
| 162 |
assert aa.q3(False) == 'q3' |
| 163 |
try: aa.q3(True) |
| 164 |
except ValueError: pass |
| 165 |
else: assert False, "ValueError not raised" |
| 166 |
|
| 167 |
aa.r1(False) |
| 168 |
try: aa.r1(True) |
| 169 |
except ValueError: assert False, "ValueError not raised" |
| 170 |
else: pass |
| 171 |
|
| 172 |
aa.r2(False) |
| 173 |
try: aa.r2(True) |
| 174 |
except ValueError: pass |
| 175 |
else: assert False, "ValueError not raised" |
| 176 |
|
| 177 |
aa.r3(False) |
| 178 |
try: aa.r3(True) |
| 179 |
except ValueError: assert False, "ValueError not raised" |
| 180 |
else: pass |
| 181 |
|
| 182 |
######## bar.pxd ######## |
| 183 |
cdef int func_noexcept_declared_in_pxd() noexcept |
| 184 |
cdef int func_implicit_declared_in_pxd() |
| 185 |
|
| 186 |
######## bar.pyx ######## |
| 187 |
|
| 188 |
cdef int func_noexcept() noexcept: |
| 189 |
raise RuntimeError() |
| 190 |
|
| 191 |
cdef int func_implicit(): |
| 192 |
raise RuntimeError() |
| 193 |
|
| 194 |
cdef int func_noexcept_declared_in_pxd(): |
| 195 |
raise RuntimeError() |
| 196 |
|
| 197 |
cdef int func_implicit_declared_in_pxd(): |
| 198 |
raise RuntimeError() |
| 199 |
|
| 200 |
cdef int func_return_value() except -1: |
| 201 |
raise RuntimeError() |
| 202 |
|
| 203 |
func_noexcept() |
| 204 |
func_implicit() |
| 205 |
|
| 206 |
func_noexcept_declared_in_pxd() |
| 207 |
func_implicit_declared_in_pxd() |
| 208 |
|
| 209 |
try: |
| 210 |
func_return_value() |
| 211 |
except RuntimeError: |
| 212 |
pass |
| 213 |
else: |
| 214 |
assert False, 'Exception not raised' |
| 215 |
|
| 216 |
|
| 217 |
######## aa.pxd ######## |
| 218 |
cdef class Klass: |
| 219 |
cpdef int m1(self, bint exc) except? -1 |
| 220 |
cpdef int m2(self, bint exc) |
| 221 |
cpdef int m3(self, bint exc) noexcept |
| 222 |
cpdef int m4(self, bint exc) except * |
| 223 |
cpdef int m5(self, bint exc) except -1 |
| 224 |
cpdef object n1(self, bint exc) |
| 225 |
cpdef object n2(self, bint exc) except * |
| 226 |
cpdef object n3(self, bint exc) noexcept # will warn, but should work |
| 227 |
cpdef void o1(self, bint exc) |
| 228 |
cpdef void o2(self, bint exc) except* |
| 229 |
cpdef void o3(self, bint exc) noexcept |
| 230 |
cdef int p1(self, bint exc) except? -1 |
| 231 |
cdef int p2(self, bint exc) |
| 232 |
cdef int p3(self, bint exc) noexcept |
| 233 |
cdef int p4(self, bint exc) except * |
| 234 |
cdef int p5(self, bint exc) except -1 |
| 235 |
cdef object q1(self, bint exc) |
| 236 |
cdef object q2(self, bint exc) except * |
| 237 |
cdef object q3(self, bint exc) noexcept # will warn, but should work |
| 238 |
cdef void r1(self, bint exc) |
| 239 |
cdef void r2(self, bint exc) except* |
| 240 |
cdef void r3(self, bint exc) noexcept |
| 241 |
|
| 242 |
cpdef int m1(bint exc) except? -1 |
| 243 |
cpdef int m2(bint exc) |
| 244 |
cpdef int m3(bint exc) noexcept |
| 245 |
cpdef int m4(bint exc) except * |
| 246 |
cpdef int m5(bint exc) except -1 |
| 247 |
cpdef object n1(bint exc) |
| 248 |
cpdef object n2(bint exc) except * |
| 249 |
cpdef object n3(bint exc) noexcept # will warn, but should work |
| 250 |
cpdef void o1(bint exc) |
| 251 |
cpdef void o2(bint exc) except* |
| 252 |
cpdef void o3(bint exc) noexcept |
| 253 |
cdef int p1(bint exc) except? -1 |
| 254 |
cdef int p2(bint exc) |
| 255 |
cdef int p3(bint exc) noexcept |
| 256 |
cdef int p4(bint exc) except * |
| 257 |
cdef int p5(bint exc) except -1 |
| 258 |
cdef object q1(bint exc) |
| 259 |
cdef object q2(bint exc) except * |
| 260 |
cdef object q3(bint exc) noexcept # will warn, but should work |
| 261 |
cdef void r1(bint exc) |
| 262 |
cdef void r2(bint exc) except* |
| 263 |
cdef void r3(bint exc) noexcept |
| 264 |
|
| 265 |
######## aa.py ######## |
| 266 |
|
| 267 |
class Klass: |
| 268 |
|
| 269 |
def m1(self, exc): |
| 270 |
if exc: raise ValueError() |
| 271 |
return 1 |
| 272 |
def m2(self, exc): |
| 273 |
if exc: raise ValueError() |
| 274 |
return 2 |
| 275 |
def m3(self, exc): |
| 276 |
if exc: raise ValueError() |
| 277 |
return 3 |
| 278 |
def m4(self, exc): |
| 279 |
if exc: raise ValueError() |
| 280 |
return 4 |
| 281 |
def m5(self, exc): |
| 282 |
if exc: raise ValueError() |
| 283 |
return 5 |
| 284 |
|
| 285 |
def n1(self, exc): |
| 286 |
if exc: raise ValueError() |
| 287 |
return 'n1' |
| 288 |
def n2(self, exc): |
| 289 |
if exc: raise ValueError() |
| 290 |
return 'n2' |
| 291 |
def n3(self, exc): |
| 292 |
if exc: raise ValueError() |
| 293 |
return 'n3' |
| 294 |
|
| 295 |
def o1(self, exc): |
| 296 |
if exc: raise ValueError() |
| 297 |
return |
| 298 |
def o2(self, exc): |
| 299 |
if exc: raise ValueError() |
| 300 |
return |
| 301 |
def o3(self, exc): |
| 302 |
if exc: raise ValueError() |
| 303 |
return |
| 304 |
|
| 305 |
def p1(self, exc): |
| 306 |
if exc: raise ValueError() |
| 307 |
return 1 |
| 308 |
def p2(self, exc): |
| 309 |
if exc: raise ValueError() |
| 310 |
return 2 |
| 311 |
def p3(self, exc): |
| 312 |
if exc: raise ValueError() |
| 313 |
return 3 |
| 314 |
def p4(self, exc): |
| 315 |
if exc: raise ValueError() |
| 316 |
return 4 |
| 317 |
def p5(self, exc): |
| 318 |
if exc: raise ValueError() |
| 319 |
return 5 |
| 320 |
|
| 321 |
def q1(self, exc): |
| 322 |
if exc: raise ValueError() |
| 323 |
return 'q1' |
| 324 |
def q2(self, exc): |
| 325 |
if exc: raise ValueError() |
| 326 |
return 'q2' |
| 327 |
def q3(self, exc): |
| 328 |
if exc: raise ValueError() |
| 329 |
return 'q3' |
| 330 |
|
| 331 |
def r1(self, exc): |
| 332 |
if exc: raise ValueError() |
| 333 |
return |
| 334 |
def r2(self, exc): |
| 335 |
if exc: raise ValueError() |
| 336 |
return |
| 337 |
def r3(self, exc): |
| 338 |
if exc: raise ValueError() |
| 339 |
return |
| 340 |
|
| 341 |
def m1(exc): |
| 342 |
if exc: raise ValueError() |
| 343 |
return 1 |
| 344 |
def m2(exc): |
| 345 |
if exc: raise ValueError() |
| 346 |
return 2 |
| 347 |
def m3(exc): |
| 348 |
if exc: raise ValueError() |
| 349 |
return 3 |
| 350 |
def m4(exc): |
| 351 |
if exc: raise ValueError() |
| 352 |
return 4 |
| 353 |
def m5(exc): |
| 354 |
if exc: raise ValueError() |
| 355 |
return 5 |
| 356 |
|
| 357 |
def n1(exc): |
| 358 |
if exc: raise ValueError() |
| 359 |
return 'n1' |
| 360 |
def n2(exc): |
| 361 |
if exc: raise ValueError() |
| 362 |
return 'n2' |
| 363 |
def n3(exc): |
| 364 |
if exc: raise ValueError() |
| 365 |
return 'n3' |
| 366 |
|
| 367 |
def o1(exc): |
| 368 |
if exc: raise ValueError() |
| 369 |
return |
| 370 |
def o2(exc): |
| 371 |
if exc: raise ValueError() |
| 372 |
return |
| 373 |
def o3(exc): |
| 374 |
if exc: raise ValueError() |
| 375 |
return |
| 376 |
|
| 377 |
def p1(exc): |
| 378 |
if exc: raise ValueError() |
| 379 |
return 1 |
| 380 |
def p2(exc): |
| 381 |
if exc: raise ValueError() |
| 382 |
return 2 |
| 383 |
def p3(exc): |
| 384 |
if exc: raise ValueError() |
| 385 |
return 3 |
| 386 |
def p4(exc): |
| 387 |
if exc: raise ValueError() |
| 388 |
return 4 |
| 389 |
def p5(exc): |
| 390 |
if exc: raise ValueError() |
| 391 |
return 5 |
| 392 |
|
| 393 |
def q1(exc): |
| 394 |
if exc: raise ValueError() |
| 395 |
return 'q1' |
| 396 |
def q2(exc): |
| 397 |
if exc: raise ValueError() |
| 398 |
return 'q2' |
| 399 |
def q3(exc): |
| 400 |
if exc: raise ValueError() |
| 401 |
return 'q3' |
| 402 |
|
| 403 |
def r1(exc): |
| 404 |
if exc: raise ValueError() |
| 405 |
return |
| 406 |
def r2(exc): |
| 407 |
if exc: raise ValueError() |
| 408 |
return |
| 409 |
def r3(exc): |
| 410 |
if exc: raise ValueError() |
| 411 |
return |