Esempio n. 1
0
def test_check_params_described_FnDef():
    fn_def = sp.FnDef(function_node("def add(a,b): return a+b"), False, False)
    fn_def._check_params_described()
    assert len(fn_def.errors) == 2
    fn_def = sp.FnDef(read_function('add_with_docstr.py'), False, False)
    fn_def._check_params_described()
    assert not fn_def.errors
Esempio n. 2
0
def test_check_params_additional_FnDef():
    code = read('add_with_docstr_extra_param.py')
    fn_def = sp.FnDef(function_node(code), False, False)
    fn_def._check_params_additional()
    assert len(fn_def.errors) == 1
    fn_def = sp.FnDef(read_function('add_with_docstr.py'), False, False)
    fn_def._check_params_additional()
    assert not fn_def.errors
Esempio n. 3
0
def test_ignore_first_param_FnDef():
    fn_def = sp.FnDef(function_node("def add(a,b): return a+b"), False)
    assert fn_def._ignore_first_param() == False
    code = read('class_with_staticmethod.py')
    fn_def = sp.FnDef(function_node(code), True)
    assert fn_def._ignore_first_param() == False
    code = read('class_with_method.py')
    fn_def = sp.FnDef(function_node(code), True)
    assert fn_def._ignore_first_param() == True
Esempio n. 4
0
def test_check_params_types_FnDef():
    code = read('add_with_docstr_missing_type.py')
    fn_def = sp.FnDef(function_node(code), False, False)
    fn_def._check_params_types()
    assert len(fn_def.warnings) == 1
    code = read('add_with_docstr_missing_desc.py')
    fn_def = sp.FnDef(function_node(code), False, False)
    fn_def._check_params_types()
    assert len(fn_def.errors) == 1
    fn_def = sp.FnDef(read_function('add_with_docstr.py'), False, False)
    fn_def._check_params_types()
    assert not fn_def.errors
Esempio n. 5
0
def test_constructor_FnDef():
    code = "def add(a,b): return a+b"
    fn_node = function_node(code)
    fn_def = sp.FnDef(fn_node, False)
    assert fn_def.name == 'add'
    assert fn_def.lineno == 1
    assert fn_def.params == ['a', 'b']
    assert fn_def.decorators == set()
    assert fn_def.docstr
    assert fn_def.has_return == True
    assert fn_def.raises_exception == False
Esempio n. 6
0
def test_check_returns_FnDef():
    fn_def = sp.FnDef(read_function('add_with_docstr.py'), False, False)
    fn_def._check_returns()
    assert not fn_def.errors
    code = read('add_with_docstr_missing_return.py')
    fn_def = sp.FnDef(function_node(code), False, False)
    fn_def._check_returns()
    assert len(fn_def.errors) == 1
    code = read('add_with_docstr_missing_return_desc.py')
    fn_def = sp.FnDef(function_node(code), False, False)
    fn_def._check_returns()
    assert len(fn_def.errors) == 1
    code = read('add_with_docstr_missing_rtype.py')
    fn_def = sp.FnDef(function_node(code), False, False)
    fn_def._check_returns()
    assert len(fn_def.warnings) == 1
    code = read('add_with_docstr_no_return.py')
    fn_def = sp.FnDef(function_node(code), False, False)
    fn_def._check_returns()
    assert len(fn_def.errors) == 1
Esempio n. 7
0
def test_check_FnDef():
    fn_def = sp.FnDef(read_function('add_with_docstr.py'), False, False)
    fn_def._check()
    assert not fn_def.errors
    assert not fn_def.warnings
Esempio n. 8
0
def test_check_docstring_FnDef():
    fn_def = sp.FnDef(function_node("def add(a,b): return a+b"), False, False)
    assert fn_def._check_docstring() == False
    fn_def = sp.FnDef(read_function('add_with_docstr.py'), False, False)
    assert fn_def._check_docstring() == True
Esempio n. 9
0
def test_param_names_FnDef():
    code = read('class_with_method.py')
    fn_def = sp.FnDef(function_node(code), True)
    assert fn_def._param_names() == ['a', 'b']