| 1 |
""" |
| 2 |
Test compiled module |
| 3 |
""" |
| 4 |
import os |
| 5 |
|
| 6 |
import jedi |
| 7 |
from ..helpers import get_example_dir |
| 8 |
import pytest |
| 9 |
|
| 10 |
|
| 11 |
def test_completions(Script): |
| 12 |
s = Script('import _ctypes; _ctypes.') |
| 13 |
assert len(s.complete()) >= 15 |
| 14 |
|
| 15 |
|
| 16 |
def test_get_signatures_extension(Script, environment): |
| 17 |
if os.name == 'nt': |
| 18 |
func = 'LoadLibrary' |
| 19 |
else: |
| 20 |
func = 'dlopen' |
| 21 |
s = Script('import _ctypes; _ctypes.%s(' % (func,)) |
| 22 |
sigs = s.get_signatures() |
| 23 |
assert len(sigs) == 1 |
| 24 |
assert len(sigs[0].params) in (1, 2) |
| 25 |
|
| 26 |
|
| 27 |
def test_get_signatures_stdlib(Script): |
| 28 |
s = Script('import math; math.cos(') |
| 29 |
sigs = s.get_signatures() |
| 30 |
assert len(sigs) == 1 |
| 31 |
assert len(sigs[0].params) == 1 |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
@pytest.mark.parametrize('load_unsafe_extensions', [False, True]) |
| 38 |
@pytest.mark.skipif( |
| 39 |
'sys.platform != "linux" or sys.maxsize <= 2**32 or sys.version_info[:2] != (3, 8)', |
| 40 |
) |
| 41 |
def test_init_extension_module(Script, load_unsafe_extensions): |
| 42 |
""" |
| 43 |
``__init__`` extension modules are also packages and Jedi should understand |
| 44 |
that. |
| 45 |
|
| 46 |
Originally coming from #472. |
| 47 |
|
| 48 |
This test was built by the module.c and setup.py combination you can find |
| 49 |
in the init_extension_module folder. You can easily build the |
| 50 |
`__init__.cpython-38m.so` by compiling it (create a virtualenv and run |
| 51 |
`setup.py install`. |
| 52 |
|
| 53 |
This is also why this test only runs on certain systems and a specific |
| 54 |
Python version. |
| 55 |
""" |
| 56 |
|
| 57 |
project = jedi.Project(get_example_dir(), load_unsafe_extensions=load_unsafe_extensions) |
| 58 |
s = jedi.Script( |
| 59 |
'import init_extension_module as i\ni.', |
| 60 |
path='not_existing.py', |
| 61 |
project=project, |
| 62 |
) |
| 63 |
if load_unsafe_extensions: |
| 64 |
assert 'foo' in [c.name for c in s.complete()] |
| 65 |
else: |
| 66 |
assert 'foo' not in [c.name for c in s.complete()] |
| 67 |
|
| 68 |
s = jedi.Script( |
| 69 |
'from init_extension_module import foo\nfoo', |
| 70 |
path='not_existing.py', |
| 71 |
project=project, |
| 72 |
) |
| 73 |
c, = s.complete() |
| 74 |
assert c.name == 'foo' |
| 75 |
if load_unsafe_extensions: |
| 76 |
assert c.infer() |
| 77 |
else: |
| 78 |
assert not c.infer() |