File: relative_import_leak.srctree

package info (click to toggle)
cython 3.0.11%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, 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 (66 lines) | stat: -rw-r--r-- 1,774 bytes parent folder | download
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
PYTHON test_relative_import_leak.py

######## test_relative_import_leak.py ########

import os
import sys
from contextlib import contextmanager
from Cython.Compiler.Errors import CompileError
from Cython.Build.Dependencies import cythonize
if sys.version_info[0] < 3:
    from StringIO import StringIO
else:
    from io import StringIO

@contextmanager
def assert_stderr(expected_error):
    sys.path.append('other')
    sys.stderr = temp_stderr = StringIO()
    try:
        yield
    except CompileError:
        assert expected_error in temp_stderr.getvalue(), '"%s" not found in stderr' % expected_error
    else:
        assert False, 'The module was imported even when it should not be importable'
    finally:
        sys.stderr = sys.__stderr__
        temp_stderr.close()

pxd_file = os.path.join('pkg', 'bb.pxd')

pyx_file = os.path.join('pkg', 'aa.pyx')
with assert_stderr(pyx_file + ":1:0: '" + pxd_file + "' not found"):
    cythonize(pyx_file)

pyx_file = os.path.join('pkg', 'ab.pyx')
with assert_stderr(pyx_file + ":1:0: '" + pxd_file + "' not found"):
    cythonize(pyx_file)

pyx_file = os.path.join('pkg', 'pkg2', 'ac.pyx')
with assert_stderr(pyx_file + ":1:0: '" + pxd_file + "' not found"):
    cythonize(pyx_file)

pyx_file = os.path.join('pkg', 'pkg2', 'ad.pyx')
with assert_stderr(pyx_file + ":1:0: '" + pxd_file + "' not found"):
    cythonize(pyx_file)

######## pkg/__init__.py ########

######## pkg/aa.pyx ########
from . cimport bb

######## pkg/ab.pyx ########
from .bb cimport ULong

######## pkg/pkg2/__init__.py ########

######## pkg/pkg2/ac.pyx ########
from .. cimport bb

######## pkg/pkg2/ad.pyx ########
from ..bb cimport ULong

######## other/pkg/__init__.py ########

######## other/pkg/bb.pxd ########
ctypedef unsigned long ULong