| 1 |
""" |
| 2 |
All character set and unicode related tests. |
| 3 |
""" |
| 4 |
from jedi import Project |
| 5 |
|
| 6 |
|
| 7 |
def test_unicode_script(Script): |
| 8 |
s = "import datetime; datetime.timedelta" |
| 9 |
completions = Script(s).complete() |
| 10 |
assert len(completions) |
| 11 |
assert type(completions[0].description) is str |
| 12 |
|
| 13 |
s = "author='öä'; author" |
| 14 |
completions = Script(s).complete() |
| 15 |
x = completions[0].description |
| 16 |
assert type(x) is str |
| 17 |
|
| 18 |
s = "#-*- coding: iso-8859-1 -*-\nauthor='öä'; author" |
| 19 |
s = s.encode('latin-1') |
| 20 |
completions = Script(s).complete() |
| 21 |
assert type(completions[0].description) is str |
| 22 |
|
| 23 |
|
| 24 |
def test_unicode_attribute(Script): |
| 25 |
""" github jedi-vim issue #94 """ |
| 26 |
s1 = ('#-*- coding: utf-8 -*-\nclass Person():\n' |
| 27 |
' name = "e"\n\nPerson().name.') |
| 28 |
completions1 = Script(s1).complete() |
| 29 |
assert 'strip' in [c.name for c in completions1] |
| 30 |
s2 = ('#-*- coding: utf-8 -*-\nclass Person():\n' |
| 31 |
' name = "é"\n\nPerson().name.') |
| 32 |
completions2 = Script(s2).complete() |
| 33 |
assert 'strip' in [c.name for c in completions2] |
| 34 |
|
| 35 |
|
| 36 |
def test_multibyte_script(Script): |
| 37 |
""" `jedi.Script` must accept multi-byte string source. """ |
| 38 |
code = "import datetime; datetime.d" |
| 39 |
comment = "# multi-byte comment あいうえおä" |
| 40 |
s = ('%s\n%s') % (code, comment) |
| 41 |
assert len(Script(s).complete(1, len(code))) |
| 42 |
|
| 43 |
|
| 44 |
def test_goto_definition_at_zero(Script): |
| 45 |
"""Infer at zero sometimes raises issues.""" |
| 46 |
assert Script("a").infer(1, 1) == [] |
| 47 |
s = Script("str").infer(1, 1) |
| 48 |
assert len(s) == 1 |
| 49 |
assert list(s)[0].description == 'class str' |
| 50 |
assert Script("").infer(1, 0) == [] |
| 51 |
|
| 52 |
|
| 53 |
def test_complete_at_zero(Script): |
| 54 |
s = Script("str").complete(1, 3) |
| 55 |
assert len(s) == 1 |
| 56 |
assert list(s)[0].name == 'str' |
| 57 |
|
| 58 |
s = Script("").complete(1, 0) |
| 59 |
assert len(s) > 0 |
| 60 |
|
| 61 |
|
| 62 |
def test_wrong_encoding(Script, tmpdir): |
| 63 |
x = tmpdir.join('x.py') |
| 64 |
|
| 65 |
x.write_binary('foobar = 1\nä'.encode('latin-1') + 'ä'.encode('utf-8')) |
| 66 |
|
| 67 |
project = Project(tmpdir.strpath) |
| 68 |
c, = Script('import x; x.foo', project=project).complete() |
| 69 |
assert c.name == 'foobar' |