mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
Implemented support for namedtuples (fixes #107)
Note that namedtuples are only supported for Python >2.6.
This commit is contained in:
37
test/test_integration_stdlib.py
Normal file
37
test/test_integration_stdlib.py
Normal file
@@ -0,0 +1,37 @@
|
||||
"""
|
||||
Tests of various stdlib related things that could not be tested
|
||||
with "Black Box Tests".
|
||||
"""
|
||||
import pytest
|
||||
from jedi import Script
|
||||
from jedi._compatibility import is_py26
|
||||
|
||||
|
||||
@pytest.mark.parametrize(['letter', 'expected'], [
|
||||
('n', ['name']),
|
||||
('s', ['smart']),
|
||||
])
|
||||
def test_namedtuple_str(letter, expected):
|
||||
source = "import collections\n" + \
|
||||
"Person = collections.namedtuple('Person', 'name smart')\n" + \
|
||||
"dave = Person('Dave', False)\n" + \
|
||||
"dave.%s" % letter
|
||||
result = Script(source).completions()
|
||||
completions = set(r.name for r in result)
|
||||
if is_py26:
|
||||
assert completions == set()
|
||||
else:
|
||||
assert completions == set(expected)
|
||||
|
||||
|
||||
def test_namedtuple_list():
|
||||
source = "import collections\n" + \
|
||||
"Cat = collections.namedtuple('Person', ['legs', u'length', 'large'])\n" + \
|
||||
"garfield = Cat(4, '85cm', True)\n" + \
|
||||
"garfield.l"
|
||||
result = Script(source).completions()
|
||||
completions = set(r.name for r in result)
|
||||
if is_py26:
|
||||
assert completions == set()
|
||||
else:
|
||||
assert completions == set(['legs', 'length', 'large'])
|
||||
Reference in New Issue
Block a user