def test_extract_pep484(): match = extract.extract(example, 'function_with_docstring_pep484') assert match['function'] == 'function_with_docstring_pep484' assert match['signature'] == '(arg0: int, arg1: bool = True) -> bool' args = match['parsed_signature']['args'] return_annotation = match['parsed_signature']['return_annotation'] assert args['arg0'] == 'int' assert args['arg1'] == 'bool = True' assert return_annotation == 'bool' assert 'Example of a function with a doc string.' in match['docstring'] assert 'Some more' in match['docstring'] # Allow for nested.types in return type annotation match = extract.extract(example, 'function_with_docstring_objects_pep484') assert match['signature'] == '(arg0: int, arg1: bool = True) -> obj.bool'
def test_new_class(): match = extract.extract(example, 'ExampleNewClass') assert match['class'] == 'ExampleNewClass' assert match['signature'] == '(object)' assert match['type'] == 'class' assert match['docstring'] assert 'Some more' in match['docstring']
def setup_google(filename='fixtures/example.py', function='function_with_docstring', signature=None, config=None): match = extract(filename, function) google = parse.GoogleDocString(match['docstring'], signature=signature, config=config) return google
def test_overloaded_function(): match = extract.extract(example, 'overloaded_add') assert isinstance(match, list) assert len(match) == 2 assert match[0]['docstring'] assert 'Some more' in match[0]['docstring'] assert not 'arg3' in match[0]['docstring'] assert match[1]['docstring'] assert 'Some more' in match[1]['docstring'] assert 'arg3' in match[1]['docstring']
def test_methods(): classes = ['ExampleOldClass', 'ExampleOldClass'] methods = ['method_with_docstring', 'method_with_new_line_before_self'] signatures = ['(self, arg1, arg2)', '( self)'] text = ['Some more', 'with a new line'] for cl, mt, sig, txt in zip(classes, methods, signatures, text): match = extract.extract(example, '%s.%s' % (cl, mt)) assert match['function'] == mt assert match['signature'] == sig assert match['type'] == 'method' assert txt in match['docstring']
def test_undefined_headers(): example = 'fixtures/example.py' match = extract(example, 'function_with_undefined_header') with pytest.warns(UserWarning): \ docstring = parse.GoogleDocString(match['docstring']).parse() assert docstring[0]['args'] == [] config = {'ignore_args_for_undefined_headers': False} with pytest.warns(UserWarning): \ docstring = parse.GoogleDocString(match['docstring'], config=config).parse() assert not docstring[0]['args'] == []
def test_function(): match = extract.extract(example, 'function_with_docstring') args = match['parsed_signature']['args'] assert match['function'] == 'function_with_docstring' assert match['signature'] == '(arg1, arg2=True)' assert match['type'] == 'function' assert match['source'] == \ 'def function_with_docstring(arg1, arg2=True):\n pass\n\n' assert match['docstring'] assert args['arg1'] == '' assert args['arg2'] == '=True' assert 'Some more' in match['docstring']
def test_multiline_signature_new_line_before_args(): example = 'fixtures/example.py' match = extract.extract(example, 'multiline_new_line_before_args') assert match['function'] == 'multiline_new_line_before_args' args = match['parsed_signature']['args'] assert args['arg1'] == ''
def test_multiline_signature(): example = 'fixtures/example.py' match = extract.extract(example, 'multiline') assert match['function'] == 'multiline'
def test_function_not_found(): with pytest.raises(NameError): extract.extract(example, 'something') with pytest.raises(ValueError): extract.extract(example, 'something.a.a')
def test_init(): match = extract.extract(example, 'ExampleOldClass.__init__') assert match['class'] == 'ExampleOldClass' assert match['signature'] == '(self, arg1, arg2)' assert match['docstring'] assert 'Some more' in match['docstring']
def test_old_class(): match = extract.extract(example, 'ExampleOldClass') assert match['class'] == 'ExampleOldClass' assert match['type'] == 'class' assert match['docstring'] assert 'Some more' in match['docstring']