本文整理汇总了Python中tests.custom_hypothesis_support._parse_text函数的典型用法代码示例。如果您正苦于以下问题:Python _parse_text函数的具体用法?Python _parse_text怎么用?Python _parse_text使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_parse_text函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_subscript_del_ctx
def test_subscript_del_ctx(node):
"""Test visitor of Subscript node within a del statement."""
del_node = astroid.Delete()
del_node.postinit([node])
module, _ = cs._parse_text(del_node)
for subscript_node in module.nodes_of_class(astroid.Subscript):
assert subscript_node.inf_type.getValue() == type(None)
开发者ID:pyta-uoft,项目名称:pyta,代码行数:7,代码来源:test_subscript.py
示例2: test_annotation_forward_ref_space
def test_annotation_forward_ref_space():
src = """
x: 'Some Class'
"""
module, inferer = cs._parse_text(src, reset=True)
for ann_node in module.nodes_of_class(astroid.AnnAssign):
assert isinstance(ann_node.inf_type, TypeFailAnnotationInvalid)
开发者ID:pyta-uoft,项目名称:pyta,代码行数:7,代码来源:test_annassign.py
示例3: test_set_comprehension_reproduce_homogeneous
def test_set_comprehension_reproduce_homogeneous(iterable):
"""Test SetComp node visitor representing a comprehension expression reproducing a set of elements of
a homogeneous iterable."""
program = '{elt for elt in ' + repr(iterable) + '}'
module, _ = cs._parse_text(program)
setcomp_node = list(module.nodes_of_class(astroid.SetComp))[0]
assert setcomp_node.type_constraints.type == Set[setcomp_node.generators[0].iter.type_constraints.type.__args__[0]]
开发者ID:nigef,项目名称:pyta,代码行数:7,代码来源:test_setcomp.py
示例4: test_functiondef_annotated_simple_return
def test_functiondef_annotated_simple_return(functiondef_node):
"""Test whether type annotations are set properly for a FunctionDef node representing a function definition
with type annotations."""
arg_names = [arg.name for arg in functiondef_node.args.args]
assume(functiondef_node.name not in arg_names)
for arg in functiondef_node.args.args:
assume(arg_names.count(arg.name) == 1)
module, inferer = cs._parse_text(functiondef_node)
functiondef_node = next(module.nodes_of_class(astroid.FunctionDef))
# arguments and annotations are not changing, so test this once.
for i in range(len(functiondef_node.args.annotations)):
arg_name = functiondef_node.args.args[i].name
expected_type = inferer.type_constraints.resolve(functiondef_node.type_environment.lookup_in_env(arg_name)).getValue()
# need to do by name because annotations must be name nodes.
if isinstance(expected_type, _GenericAlias):
assert _gorg(expected_type).__name__ == functiondef_node.args.annotations[i].name
else:
assert expected_type.__name__ == functiondef_node.args.annotations[i].name
# test return type
return_node = functiondef_node.body[0].value
expected_rtype = inferer.type_constraints.resolve(functiondef_node.type_environment.lookup_in_env(return_node.name)).getValue()
if isinstance(expected_rtype, _GenericAlias):
assert _gorg(expected_rtype).__name__ == functiondef_node.returns.name
else:
assert expected_rtype.__name__ == functiondef_node.returns.name
开发者ID:pyta-uoft,项目名称:pyta,代码行数:25,代码来源:test_function_def_inference.py
示例5: test_subscript_slice
def test_subscript_slice():
program = '''
x = List[:]
'''
module, _ = cs._parse_text(program)
assign_node = next(module.nodes_of_class(astroid.Assign))
assert isinstance(assign_node.inf_type, TypeFail)
开发者ID:pyta-uoft,项目名称:pyta,代码行数:7,代码来源:test_subscript.py
示例6: test_multi_starred
def test_multi_starred():
src = """
*a, b, *c = [1, 2, 3, 4, 5]
"""
ast_mod, ti = cs._parse_text(src, reset=True)
assign_node = next(ast_mod.nodes_of_class(astroid.Assign))
assert isinstance(assign_node.inf_type, TypeFailStarred)
开发者ID:pyta-uoft,项目名称:pyta,代码行数:7,代码来源:test_starred.py
示例7: test_userdefn_mro_diamond
def test_userdefn_mro_diamond(draw=False):
src = """
class A:
pass
class B(A):
def foo(self):
return 'a'
class C(A):
def foo(self):
return 0
class D(B,C):
pass
d = D()
x = d.foo() # this is a call to B.foo()
"""
ast_mod, ti = cs._parse_text(src, reset=True)
_, _, d, x = [ti.lookup_typevar(node, node.name) for node
in ast_mod.nodes_of_class(astroid.AssignName)]
assert ti.type_constraints.resolve(x).getValue() == str
if draw:
gen_graph_from_nodes(ti.type_constraints._nodes)
开发者ID:pyta-uoft,项目名称:pyta,代码行数:25,代码来源:test_tnode_structure.py
示例8: test_invalid_annassign_and_assign
def test_invalid_annassign_and_assign():
src = """
x: List[str] = [1, 2, 3]
"""
module, inferer = cs._parse_text(src, reset=True)
for ann_node in module.nodes_of_class(astroid.AnnAssign):
assert isinstance(ann_node.inf_type, TypeFailUnify)
开发者ID:pyta-uoft,项目名称:pyta,代码行数:7,代码来源:test_annassign.py
示例9: test_set_name_unassigned
def test_set_name_unassigned(variable_name):
"""Test visitor for name nodes representing a single unassigned variable in module."""
program = variable_name
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
开发者ID:nigef,项目名称:pyta,代码行数:7,代码来源:test_assignments.py
示例10: test_userdefn_inheritance_multilevel
def test_userdefn_inheritance_multilevel(draw=False):
src = """
class A:
pass
class B(A):
pass
class C(B):
pass
a = A()
b = B()
c = C()
"""
ast_mod, ti = cs._parse_text(src, reset=True)
tc = ti.type_constraints
a, b, c = [ti.lookup_typevar(node, node.name) for node
in ast_mod.nodes_of_class(astroid.AssignName)]
assert tc.unify(b, a).getValue() == ForwardRef('B')
assert tc.unify(c, b).getValue() == ForwardRef('C')
assert tc.unify(c, a).getValue() == ForwardRef('C')
assert isinstance(ti.type_constraints.unify(b, c), TypeFail)
if draw:
gen_graph_from_nodes(tc._nodes)
开发者ID:pyta-uoft,项目名称:pyta,代码行数:27,代码来源:test_tnode_structure.py
示例11: test_binop_reverse
def test_binop_reverse():
src = """
x = 3 * [1,2,3]
"""
ast_mod, ti = cs._parse_text(src, reset=True)
x = [ti.lookup_typevar(node, node.name) for node
in ast_mod.nodes_of_class(astroid.AssignName)][0]
assert ti.type_constraints.resolve(x).getValue() == List[int]
开发者ID:pyta-uoft,项目名称:pyta,代码行数:8,代码来源:test_binops.py
示例12: test_dict_comprehension_reproduce_heterogeneous
def test_dict_comprehension_reproduce_heterogeneous(node):
"""Test DictComp node visitor representing a comprehension expression reproducing the the key, value pairs
of a heterogeneous Dictionary."""
dictionary = node.as_string()
program = f"{{key: {dictionary}[key] for key in {dictionary}}}"
module, _ = cs._parse_text(program)
dictcomp_node = list(module.nodes_of_class(astroid.DictComp))[0]
assert dictcomp_node.inf_type.getValue() == dictcomp_node.generators[0].iter.inf_type.getValue()
开发者ID:pyta-uoft,项目名称:pyta,代码行数:8,代码来源:test_dictcomp.py
示例13: test_multi_variable
def test_multi_variable():
src = """
lst = [1, 2, 3, 4, 5]
*a, b, *c = lst
"""
ast_mod, ti = cs._parse_text(src, reset=True)
assign_node = list(ast_mod.nodes_of_class(astroid.Assign))[1]
assert isinstance(assign_node.inf_type, TypeFailStarred)
开发者ID:pyta-uoft,项目名称:pyta,代码行数:8,代码来源:test_starred.py
示例14: test_homogeneous_lists
def test_homogeneous_lists(lst):
"""Test List nodes representing a list of values of the same primitive type."""
module, _ = cs._parse_text(lst)
list_node = list(module.nodes_of_class(astroid.List))[0]
if len(list_node.elts) == 0:
assert list_node.type_constraints.type == List[Any]
else:
cs._verify_type_setting(module, astroid.List, List[type(lst.elts[0].value)])
开发者ID:nigef,项目名称:pyta,代码行数:8,代码来源:test_literals.py
示例15: test_tuple_int_str
def test_tuple_int_str():
src = """
l = (1, "Hello")
"""
ast_mod, ti = cs._parse_text(src)
actual_set = tc_to_disjoint(ti.type_constraints)
expected_set = [{'~_TV0', 'typing.Tuple[int, str]'}]
compare_list_sets(actual_set, expected_set)
开发者ID:pyta-uoft,项目名称:pyta,代码行数:8,代码来源:test_tnode_structure.py
示例16: test_annassign_subscript_tuple_int
def test_annassign_subscript_tuple_int():
program = """
t: Tuple[int, int]
"""
module, inferer = cs._parse_text(program)
ann_node = next(module.nodes_of_class(astroid.AnnAssign))
variable_type = lookup_type(inferer, ann_node, ann_node.target.name)
eq_(variable_type, Tuple[int, int])
开发者ID:pyta-uoft,项目名称:pyta,代码行数:8,代码来源:test_annassign.py
示例17: test_annassign_subscript_dict_int_str
def test_annassign_subscript_dict_int_str():
program = """
d: Dict[int, str]
"""
module, inferer = cs._parse_text(program)
ann_node = next(module.nodes_of_class(astroid.AnnAssign))
variable_type = lookup_type(inferer, ann_node, ann_node.target.name)
eq_(variable_type, Dict[int, str])
开发者ID:pyta-uoft,项目名称:pyta,代码行数:8,代码来源:test_annassign.py
示例18: test_heterogeneous_binary_boolop
def test_heterogeneous_binary_boolop(node):
"""Test type setting of binary BoolOp node(s) representing expression with heterogeneous operands."""
raise SkipTest('Currently fails due to typechecking for inheritance. '
'Need to figure out if this is expected behavior.')
assume(type(node.values[0].value) != type(node.values[1].value))
module, _ = cs._parse_text(node)
boolop_node = list(module.nodes_of_class(astroid.BoolOp))[0]
assert boolop_node.inf_type.getValue() == Any
开发者ID:pyta-uoft,项目名称:pyta,代码行数:8,代码来源:test_boolops.py
示例19: test_tuple_subscript
def test_tuple_subscript():
program = """
lst = ['Hello', 'Goodbye']
lst[0], lst[1] = 'Bonjour', 'Au revoir'
"""
module, _ = cs._parse_text(program)
for assign_node in module.nodes_of_class(astroid.Assign):
assert not isinstance(assign_node.inf_type, TypeFail)
开发者ID:pyta-uoft,项目名称:pyta,代码行数:8,代码来源:test_assign_tuple.py
示例20: test_list_int
def test_list_int():
src = """
l = [1,2,3]
"""
ast_mod, ti = cs._parse_text(src)
actual_set = tc_to_disjoint(ti.type_constraints)
expected_set = [{'~_TV0', 'typing.List[int]'}, {int}]
compare_list_sets(actual_set, expected_set)
开发者ID:pyta-uoft,项目名称:pyta,代码行数:8,代码来源:test_tnode_structure.py
注:本文中的tests.custom_hypothesis_support._parse_text函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论