File: __debug__.srctree

package info (click to toggle)
cython 3.0.11%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 19,092 kB
  • sloc: python: 83,539; ansic: 18,831; cpp: 1,402; xml: 1,031; javascript: 511; makefile: 403; sh: 204; sed: 11
file content (94 lines) | stat: -rw-r--r-- 1,840 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""
PYTHON setup.py build_ext -i
PYTHON debug_test.py
PYTHON -O debug_test.py
PYTHON -OO debug_test.py
"""

######## setup.py ########

from distutils.core import setup
from Cython.Build import cythonize

setup(ext_modules = cythonize('*.pyx'))

######## debug_test.py ########

if __debug__:
    DBG = True
else:
    DBG = False

import sys
try:
    optimised = bool(sys.flags.optimize)
except AttributeError:
    # Py2.[45]
    optimised = eval('not __debug__')

if DBG == optimised:
    raise RuntimeError(
        "PYTHON: unexpected debug value %s, expected %s" % (
        DBG, optimised))

ASSERT_CALLED = False
def sideeffect():
    global ASSERT_CALLED
    ASSERT_CALLED = True
    return True

assert sideeffect()
if ASSERT_CALLED == optimised:
    raise RuntimeError("Assert called in optimised Python run")

import debug_test_cython
if debug_test_cython.DBG == optimised:
    raise RuntimeError(
        "CYTHON: unexpected debug value %s, expected %s" % (
        debug_test_cython.DBG, optimised))

try:
    import plain_debug
except ValueError:
    assert DBG
except IndexError:
    assert not DBG
else:
    assert False


######## plain_debug.pyx ########

if __debug__:
    raise ValueError("DEBUG!")
else:
    raise IndexError("NOT DEBUG!")


######## debug_test_cython.pyx ########

if __debug__:
    DBG = True
else:
    DBG = False

import sys
try:
    optimised = bool(sys.flags.optimize)
except AttributeError:
    # Py2.[45]
    optimised = eval('not __debug__')

ASSERT_CALLED = False
def sideeffect():
    global ASSERT_CALLED
    ASSERT_CALLED = True
    return True

if DBG == optimised:
    raise RuntimeError("Unexpected debug value %s, expected %s" % (
                       DBG, optimised))

assert sideeffect()
if ASSERT_CALLED == optimised:
    raise RuntimeError("Assert called in optimised Python run")