예제 #1
0
def test_singleline_description():
    docstring = """Hello, world!"""

    description, params = argparse_autogen.parse_docstring(docstring)

    assert params == []
    assert description == docstring
예제 #2
0
def test_no_description():
    docstring = """
    :param str foo: this is help
    """

    description, params = argparse_autogen.parse_docstring(docstring)

    assert description == ''
    assert len(params) == 1
예제 #3
0
def test_multiline_description():
    docstring = """
    Hello, world!
    Hello, world!
    """

    description, params = argparse_autogen.parse_docstring(docstring)

    assert params == []
    assert description == 'Hello, world!\nHello, world!'
예제 #4
0
def test_param_without_description():
    docstring = """
    Hello, world!

    :param str foo:
    """

    description, params = argparse_autogen.parse_docstring(docstring)

    assert len(params) == 1
    assert params[0]['description'] is None
예제 #5
0
def test_param_no_type():
    docstring = """
    :param foo: this is help
    """

    description, params = argparse_autogen.parse_docstring(docstring)

    assert len(params) == 1
    assert params[0]['type'] is None
    assert params[0]['name'] == 'foo'
    assert params[0]['description'] == 'this is help'
예제 #6
0
def test_multiline_param_description():
    docstring = """
    Hello, world!

    :param str foo: this is help
        and it is multiline
    :param int bar: no help
    """

    description, params = argparse_autogen.parse_docstring(docstring)

    assert params[0]['description'] == 'this is help\nand it is multiline'
    assert params[1]['description'] == 'no help'
예제 #7
0
def test_simple_params():
    docstring = """
    Hello, world!

    :param str foo: this is help
    """

    description, params = argparse_autogen.parse_docstring(docstring)

    assert description == 'Hello, world!'
    assert len(params) == 1
    assert params[0]['type'] == 'str'
    assert params[0]['name'] == 'foo'
    assert params[0]['description'] == 'this is help'
예제 #8
0
def test_unknown_param():
    docstring = """
    Hello, world!

    :param str foo: this is help
    :raises ValueError:
    """

    description, params = argparse_autogen.parse_docstring(docstring)

    assert len(params) == 1
    assert params[0]['type'] == 'str'
    assert params[0]['name'] == 'foo'
    assert params[0]['description'] == 'this is help'
예제 #9
0
def test_multiple_params():
    docstring = """
    Hello, world!

    :param str foo: this is help
    :param int bar: no help
    """

    description, params = argparse_autogen.parse_docstring(docstring)

    assert description == 'Hello, world!'
    assert len(params) == 2

    assert params[0]['type'] == 'str'
    assert params[0]['name'] == 'foo'
    assert params[0]['description'] == 'this is help'

    assert params[1]['type'] == 'int'
    assert params[1]['name'] == 'bar'
    assert params[1]['description'] == 'no help'