def test_subscript_homogeneous_list_slice(node):
"""Test visitor of Subscript node representing slicing of homogeneous list."""
module, _ = cs._parse_text(node)
for subscript_node in module.nodes_of_class(astroid.Subscript):
list_node = subscript_node.value
assert subscript_node.type_constraints.type == List[list_node.elts[0].type_constraints.type]
# TODO: this test currently fails
# @given(cs.simple_homogeneous_dict_node(min_size=1))
# def test_inference_dict_subscript(node):
# """Note that this test only takes in a dictionary because the subscript index
# must be the same type as the dictionary's keys in order to type check.
# """
# for key, _ in node.items:
# new_node = astroid.Subscript()
# new_node.postinit(node, key)
# module, _ = cs._parse_text(new_node)
# for subscript_node in module.nodes_of_class(astroid.Subscript):
# dict_node = subscript_node.value
# assert subscript_node.type_constraints.type == list(dict_node.items)[0][1].type_constraints.type
# TODO: this test needs to be converted, but will also fail
# @given(cs.random_list(min_size=2), cs.random_slice_indices())
# def test_subscript_heterogeneous_list_slice(input_list, slice):
# """Test visitor of Subscript node representing slicing of heterogeneous list."""
# assume(not isinstance(input_list[0], type(input_list[1])))
# input_slice = ':'.join([str(index) if index else '' for index in slice])
# program = f'{input_list}[{input_slice}]'
# module, _ = cs._parse_text(program)
# subscript_node = list(module.nodes_of_class(astroid.Subscript))[0]
# assert subscript_node.type_constraints.type == List[Any]
评论列表
文章目录