def test_parse_cpp_pep484(): signature = "(example: Example::ExampleOperator," \ + "i: int, j: int, op_name: str='add')" args = parse.parse_signature(signature) assert 'example' in args['args'] signature = "(example: Example::ExampleOperator<int, int>," \ + "i: int, j: int, op_name: str='add')" args = parse.parse_signature(signature) assert 'example' in args['args']
def test_parse_optional_args_pep484(): signature = "(self: python_example.Operations," \ + "i: int, j: int, op_name: str='add')" args = parse.parse_signature(signature) assert 'self' in args['args'] and \ args['args']['self'] == 'python_example.Operations' assert 'i' in args['args'] and args['args']['i'] == 'int' assert 'j' in args['args'] and args['args']['j'] == 'int' assert 'op_name' in args['args'] and args['args']['op_name'] == "str='add'"
def test_override_annotations(): signature = '(arg1: type, arg2:int = True)' in_args = parse.parse_signature(signature) google = setup_google(signature=in_args) docstr = google.parse() args = docstr[1] assert args['args'][0]['field'] == 'arg1' assert args['args'][0]['signature'] == in_args['args']['arg1'] assert args['args'][1]['field'] == 'arg2' assert args['args'][1]['signature'] == in_args['args']['arg2'] # Do not override if signature does not have any annotations signature = '(arg1, arg2)' in_args = parse.parse_signature(signature) google = setup_google(signature=in_args) docstr = google.parse() args = docstr[1] assert args['args'][0]['field'] == 'arg1' assert args['args'][0]['signature'] == '(type)'
def test_check_arguments(): # Missing documentation signature = '(arg1: int, arg2:int = True, arg3: int = True)' in_args = parse.parse_signature(signature) google = setup_google(signature=in_args) with pytest.warns(UserWarning): google.parse() # Annotation mismatch signature = '(arg1: int, arg2:int = True)' in_args = parse.parse_signature(signature) google = setup_google(signature=in_args) with pytest.warns(UserWarning): google.parse() # Unknown argument signature = '(arg1: (type))' in_args = parse.parse_signature(signature) google = setup_google(signature=in_args) with pytest.warns(UserWarning): google.parse() # Do not check annotations if signature does not contain any signature = '(arg1, arg2)' in_args = parse.parse_signature(signature) google = setup_google(signature=in_args) google.parse() # Ok signature = '(arg1: type, arg2:int = True)' in_args = parse.parse_signature(signature) google = setup_google(signature=in_args) google.parse() # Disable checks signature = '(arg1: int, arg2:int = True, arg3: int = True)' in_args = parse.parse_signature(signature) google = setup_google(signature=in_args, config={'check_args': 0}) google.parse() # Do not warn when self is not documented signature = '(self: int, arg1: int, arg2:int = True)' in_args = parse.parse_signature(signature) google = setup_google( signature=in_args, function='ExampleOldClass.__init__', config={'exclude_warn_if_no_arg_doc': ['self', 'arg1']}) google.parse()
def test_parse_args_pep484(): signature = '(arg0: int, arg1: int)' args = parse.parse_signature(signature) assert 'arg0' in args['args'] and args['args']['arg0'] == 'int' assert 'arg1' in args['args'] and args['args']['arg1'] == 'int'
def test_parse_args(): signature = '(arg0, arg1)' args = parse.parse_signature(signature) assert 'arg0' in args['args'] and args['args']['arg0'] == '' assert 'arg1' in args['args'] and args['args']['arg1'] == ''