import astroid import nose from nose import SkipTest from hypothesis import given, settings, HealthCheck from typing import List import tests.custom_hypothesis_support as cs from python_ta.typecheck.base import TypeFail, TypeFailFunction from python_ta.transforms.type_inference_visitor import NoType settings.load_profile("pyta") @given( cs.subscript_node(cs.simple_homogeneous_list_node(min_size=1), cs.index_node())) @settings(suppress_health_check=[HealthCheck.too_slow]) def test_inference_list_subscript(node): """Test whether visitor properly set the type constraint of Subscript node representing list-index access.""" module, _ = cs._parse_text(node) for subscript_node in module.nodes_of_class(astroid.Subscript): list_node = subscript_node.value assert subscript_node.inf_type.getValue( ) == list_node.elts[0].inf_type.getValue() @given( cs.subscript_node(cs.simple_homogeneous_list_node(min_size=1), cs.slice_node())) @settings(suppress_health_check=[HealthCheck.too_slow]) def test_subscript_homogeneous_list_slice(node): """Test visitor of Subscript node representing slicing of homogeneous list."""
import astroid import nose from hypothesis import given, settings from typing import List import tests.custom_hypothesis_support as cs settings.load_profile("pyta") @given(cs.subscript_node(cs.simple_homogeneous_list_node(min_size=1), cs.index_node())) def test_inference_list_subscript(node): """Test whether visitor properly set the type constraint of Subscript node representing list-index access.""" 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_node.elts[0].type_constraints.type @given(cs.subscript_node(cs.simple_homogeneous_list_node(min_size=1), cs.slice_node())) 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.
import astroid import nose from hypothesis import assume, given, settings, HealthCheck import tests.custom_hypothesis_support as cs from typing import Any, Dict, List, Set, Tuple settings.load_profile("pyta") @given(cs.subscript_node()) @settings(suppress_health_check=[HealthCheck.too_slow]) def test_index(node): module, _ = cs._parse_text(node) for index_node in module.nodes_of_class(astroid.Index): assert index_node.inf_type.getValue() == index_node.value.inf_type.getValue() @given(cs.expr_node()) @settings(suppress_health_check=[HealthCheck.too_slow]) def test_expr(expr): module, _ = cs._parse_text(expr) for expr_node in module.nodes_of_class(astroid.Expr): assert expr_node.inf_type.getValue() == expr_node.value.inf_type.getValue() if __name__ == '__main__': nose.main()