예제 #1
0
def test_set_single_assign(variables_dict):
    """Test single-target assignment statements; verify unification of type variables."""
    program = cs._parse_dictionary_to_program(variables_dict)
    module, inferer = cs._parse_text(program)
    for node in module.nodes_of_class(astroid.AssignName):
        target_value = node.parent.value
        target_type = inferer.lookup_type(node, node.name)
        # compare it to the type of the assigned value
        assert target_value.type_constraints.type == target_type
예제 #2
0
def test_set_name_assigned(variables_dict):
    """Test visitor for name nodes representing a variables with assigned values in module."""
    program = cs._parse_dictionary_to_program(variables_dict)
    for variable_name in variables_dict:
        program += variable_name + "\n"
    module, _ = cs._parse_text(program)
    for name_node in module.nodes_of_class(astroid.Name):
        name_type_var = name_node.frame().type_environment.lookup_in_env(name_node.name)
        assert name_node.type_constraints.type == name_type_var
예제 #3
0
def test_set_name_assigned(variables_dict):
    """Test visitor for name nodes representing a variables with assigned values in module."""
    program = cs._parse_dictionary_to_program(variables_dict)
    for variable_name in variables_dict:
        program += variable_name + "\n"
    module, inferer = cs._parse_text(program)
    for name_node in module.nodes_of_class(astroid.Name):
        name_type = inferer.lookup_type(name_node, name_node.name)
        assert name_node.type_constraints.type == name_type
예제 #4
0
def test_set_single_assign(variables_dict):
    """Test single-target assignment statements; verify unification of type variables."""
    program = cs._parse_dictionary_to_program(variables_dict)
    module, inferer = cs._parse_text(program)
    for node in module.nodes_of_class(astroid.AssignName):
        target_value = node.parent.value
        target_type = inferer.lookup_type(node, node.name)
        # compare it to the type of the assigned value
        assert target_value.inf_type.getValue() == target_type
예제 #5
0
def test_set_name_assigned(variables_dict):
    """Test visitor for name nodes representing a variables with assigned values in module."""
    program = cs._parse_dictionary_to_program(variables_dict)
    for variable_name in variables_dict:
        program += variable_name + "\n"
    module, inferer = cs._parse_text(program)
    for name_node in module.nodes_of_class(astroid.Name):
        name_type = inferer.lookup_type(name_node, name_node.name)
        assert name_node.inf_type.getValue() == name_type
예제 #6
0
def test_set_env(variables_dict):
    """Test environment setting visitors"""
    program = cs._parse_dictionary_to_program(variables_dict)
    module, _ = cs._parse_text(program)
    # get list of variable names in locals
    local_values = [module.type_environment.locals[name] for name in module.type_environment.locals]
    global_values = [module.type_environment.globals[name] for name in module.type_environment.globals]
    # verify the type of the value of each variable in the environment
    for value in local_values:
        assert isinstance(value, TypeVar)
    for value in global_values:
        assert isinstance(value, TypeVar)
예제 #7
0
def test_set_env(variables_dict):
    """Test environment setting visitors"""
    program = cs._parse_dictionary_to_program(variables_dict)
    module, _ = cs._parse_text(program)
    # get list of variable names in locals
    local_values = [module.type_environment.locals[name] for name in module.type_environment.locals]
    global_values = [module.type_environment.globals[name] for name in module.type_environment.globals]
    # verify the type of the value of each variable in the environment
    for value in local_values:
        assert isinstance(value, TypeVar)
    for value in global_values:
        assert isinstance(value, TypeVar)
예제 #8
0
def test_set_single_assign(variables_dict):
    """Test single-target assignment statements; verify unification of type variables."""
    program = cs._parse_dictionary_to_program(variables_dict)
    module, inferer = cs._parse_text(program)
    for node in module.nodes_of_class(astroid.AssignName):
        target_name = node.name
        target_value = node.parent.value
        # lookup name in the frame's environment
        target_type_var = node.frame().type_environment.lookup_in_env(target_name)
        # do a concrete look up of the corresponding TypeVar
        target_type = inferer.type_constraints.lookup_concrete(target_type_var)
        # compare it to the type of the assigned value
        assert target_value.type_constraints.type == target_type