예제 #1
0
def test_docopt_parser_with_tabs():
    help_string = """\
Some Tool

Usage: tools [-t] [-i <input>...] <cmd>

Inputs:
	-i, --input <input>...	The input

Options:
	-t	Some boolean
	<cmd>	The command
    """
    opts = Options.from_docopt(help_string)

    assert len(opts) == 3  # the two + help
    assert opts["input"] is not None
    assert opts["input"].nargs == "*"
    assert not opts["input"].required
    assert opts["t"] is not None
    assert opts["t"].nargs == 0
    assert not opts["t"].required
    assert opts["cmd"] is not None
    assert opts["cmd"].nargs == 1
    assert opts["cmd"].required
예제 #2
0
def test_docopt_parser_with_defaults():
    import sys
    help_string = """\
    Some Tool

    Usage: tools [-t <tool>] [-i <input>] [-o <output>]

    Inputs:
        -i, --input <input>    The input
                               [Default: stdin]

    Outputs:
        -o, --output <output>  The output
                               [Default: stdout]

    Options:
        -t, --tool <tool>      Some option
                               [Default: mytool]

    """
    opts = Options.from_docopt(help_string)

    assert opts['input'].option_type == TYPE_INPUT
    assert opts['output'].option_type == TYPE_OUTPUT
    assert opts['input'].get() == ""
    assert str(opts['input']) == ""
    assert opts['input'].raw() == sys.stdin
    assert opts['output'].raw() == sys.stdout
    assert opts['tool'].raw() == "mytool"
예제 #3
0
def test_docopt_parser_with_defaults():
    import sys

    help_string = """\
    Some Tool

    Usage: tools [-t <tool>] [-i <input>] [-o <output>]

    Inputs:
        -i, --input <input>    The input
                               [Default: stdin]

    Outputs:
        -o, --output <output>  The output
                               [Default: stdout]

    Options:
        -t, --tool <tool>      Some option
                               [Default: mytool]

    """
    opts = Options.from_docopt(help_string)

    assert opts["input"].option_type == TYPE_INPUT
    assert opts["output"].option_type == TYPE_OUTPUT
    assert opts["input"].get() == ""
    assert str(opts["input"]) == ""
    assert opts["input"].raw() == sys.stdin
    assert opts["output"].raw() == sys.stdout
    assert opts["tool"].raw() == "mytool"
예제 #4
0
def test_docopt_parser_with_tabs():
    help_string = """\
Some Tool

Usage: tools [-t] [-i <input>...] <cmd>

Inputs:
	-i, --input <input>...	The input

Options:
	-t	Some boolean
	<cmd>	The command
    """
    opts = Options.from_docopt(help_string)

    assert len(opts) == 3  # the two + help
    assert opts['input'] is not None
    assert opts['input'].nargs == "*"
    assert not opts['input'].required
    assert opts['t'] is not None
    assert opts['t'].nargs == 0
    assert not opts['t'].required
    assert opts['cmd'] is not None
    assert opts['cmd'].nargs == 1
    assert opts['cmd'].required
예제 #5
0
def test_options_setting_as_property():
    help_string = """\
Some Tool

Usage: tools --name <input>

Options:
    -n, --name <name>    The input
    """
    opts = Options.from_docopt(help_string)
    assert opts is not None

    opts["name"].set("Test")
    assert opts["name"].get() == "Test"
    assert opts.name.get() == "Test"
    assert opts.name == "Test"

    opts["name"] = "Test2"
    assert opts["name"].get() == "Test2"
    assert opts.name.get() == "Test2"
    assert opts.name == "Test2"

    opts.name = "Test3"
    assert opts["name"].get() == "Test3"
    assert opts.name.get() == "Test3"
    assert opts.name == "Test3"
예제 #6
0
def test_options_setting_as_property():
    help_string = """\
Some Tool

Usage: tools --name <input>

Options:
    -n, --name <name>    The input
    """
    opts = Options.from_docopt(help_string)
    assert opts is not None

    opts['name'].set("Test")
    assert opts['name'].get() == "Test"
    assert opts.name.get() == "Test"
    assert opts.name == "Test"

    opts['name'] = "Test2"
    assert opts['name'].get() == "Test2"
    assert opts.name.get() == "Test2"
    assert opts.name == "Test2"

    opts.name = 'Test3'
    assert opts['name'].get() == "Test3"
    assert opts.name.get() == "Test3"
    assert opts.name == "Test3"
예제 #7
0
def test_get_usage_from_docopt():
    help_string = """\
    Some Tool

    Usage: tools [-i <input>] [-o <output>]

    Options:
        -i, --input <input>    The input
                               [Default: stdin]
        -o, --output <output>  The output
                               [Default: stdout]
    """
    opts = Options.from_docopt(help_string)
    assert opts.usage() == "Usage: tools [-i <input>] [-o <output>]"
예제 #8
0
def test_streamable_from_default_no_list():
    help_string = """\
    Some Tool

    Usage: tools [-i <input>] -o <output>

    Options:
        -i, --input <input>    The input
                               [Default: stdin]
        -o, --output <output>  The output
    """
    opts = Options.from_docopt(help_string)
    assert not opts['output'].streamable
    assert opts['input'].streamable
예제 #9
0
def test_get_usage_from_docopt():
    help_string = """\
    Some Tool

    Usage: tools [-i <input>] [-o <output>]

    Options:
        -i, --input <input>    The input
                               [Default: stdin]
        -o, --output <output>  The output
                               [Default: stdout]
    """
    opts = Options.from_docopt(help_string)
    assert opts.usage() == "Usage: tools [-i <input>] [-o <output>]"
예제 #10
0
def test_streamable_from_default_no_list():
    help_string = """\
    Some Tool

    Usage: tools [-i <input>] -o <output>

    Options:
        -i, --input <input>    The input
                               [Default: stdin]
        -o, --output <output>  The output
    """
    opts = Options.from_docopt(help_string)
    assert not opts["output"].streamable
    assert opts["input"].streamable
예제 #11
0
def test_call_to_help():
    help_string = """\
    Some Tool

    Usage: tools [-i <input>] [-o <output>]

    Options:
        -i, --input <input>    The input
                               [Default: stdin]
        -o, --output <output>  The output
                               [Default: stdout]
    """
    opts = Options.from_docopt(help_string)
    with pytest.raises(ParserException):
        opts.parse(["-h"])
예제 #12
0
def test_parsing_args():
    help_string = """\
    Some Tool

    Usage: tools [-i <input>] [-o <output>]

    Options:
        -i, --input <input>    The input
                               [Default: stdin]
        -o, --output <output>  The output
                               [Default: stdout]
    """
    opts = Options.from_docopt(help_string)
    opts.parse(["-i", "testme"])
    assert opts["input"].raw() == "testme"
예제 #13
0
파일: test_options.py 프로젝트: Poshi/pyjip
def test_unkonw_argument():
    help_string = """\
    Some Tool

    Usage: tools [-i <input>] [-o <output>]

    Options:
        -i, --input <input>    The input
                               [Default: stdin]
        -o, --output <output>  The output
                               [Default: stdout]
    """
    opts = Options.from_docopt(help_string)
    with pytest.raises(ParserException):
        opts.parse(['-x', 'testme'])
예제 #14
0
def test_call_to_help():
    help_string = """\
    Some Tool

    Usage: tools [-i <input>] [-o <output>]

    Options:
        -i, --input <input>    The input
                               [Default: stdin]
        -o, --output <output>  The output
                               [Default: stdout]
    """
    opts = Options.from_docopt(help_string)
    with pytest.raises(ParserException):
        opts.parse(['-h'])
예제 #15
0
def test_parsing_args():
    help_string = """\
    Some Tool

    Usage: tools [-i <input>] [-o <output>]

    Options:
        -i, --input <input>    The input
                               [Default: stdin]
        -o, --output <output>  The output
                               [Default: stdout]
    """
    opts = Options.from_docopt(help_string)
    opts.parse(['-i', 'testme'])
    assert opts['input'].raw() == 'testme'
예제 #16
0
def test_list_arguments_for_fan_out():
    help_string = """\
    Some Tool

    Usage: tools [-i <input>] [-o <output>]

    Options:
        -i, --input <input>    The input
                               [Default: stdin]
        -o, --output <output>  The output
                               [Default: stdout]
    """
    opts = Options.from_docopt(help_string)
    opts.parse(["-i", "testme", "testme2"])
    assert opts["input"].raw() == ["testme", "testme2"]
    with pytest.raises(ValueError):
        opts["input"].get()
예제 #17
0
def test_list_arguments_for_fan_out():
    help_string = """\
    Some Tool

    Usage: tools [-i <input>] [-o <output>]

    Options:
        -i, --input <input>    The input
                               [Default: stdin]
        -o, --output <output>  The output
                               [Default: stdout]
    """
    opts = Options.from_docopt(help_string)
    opts.parse(['-i', 'testme', 'testme2'])
    assert opts['input'].raw() == ['testme', 'testme2']
    with pytest.raises(ValueError):
        opts['input'].get()
예제 #18
0
def test_docopt_parser_shorts():
    help_string = """\
    Some Tool

    Usage: tools [-t] [--input <input>...] <cmd>
    """
    opts = Options.from_docopt(help_string)

    assert len(opts) == 3  # the two + help
    assert opts['input'] is not None
    assert opts['input'].nargs == "*"
    assert not opts['input'].required
    assert opts['t'] is not None
    assert opts['t'].nargs == 0
    assert not opts['t'].required
    assert opts['cmd'] is not None
    assert opts['cmd'].nargs == 1
    assert opts['cmd'].required
예제 #19
0
def test_docopt_parser_shorts():
    help_string = """\
    Some Tool

    Usage: tools [-t] [--input <input>...] <cmd>
    """
    opts = Options.from_docopt(help_string)

    assert len(opts) == 3  # the two + help
    assert opts["input"] is not None
    assert opts["input"].nargs == "*"
    assert not opts["input"].required
    assert opts["t"] is not None
    assert opts["t"].nargs == 0
    assert not opts["t"].required
    assert opts["cmd"] is not None
    assert opts["cmd"].nargs == 1
    assert opts["cmd"].required
예제 #20
0
def test_docopt_type_from_defaults():
    import sys
    help_string = """\
    Some Tool

    Usage: tools [-i <input>] [-o <output>]

    Options:
        -i, --input <input>    The input
                               [Default: stdin]
        -o, --output <output>  The output
                               [Default: stdout]
    """
    opts = Options.from_docopt(help_string)

    assert opts['input'].option_type == TYPE_INPUT
    assert opts['output'].option_type == TYPE_OUTPUT
    assert opts['input'].raw() == sys.stdin
    assert opts['output'].raw() == sys.stdout
예제 #21
0
파일: test_options.py 프로젝트: Poshi/pyjip
def test_docopt_type_from_defaults():
    import sys
    help_string = """\
    Some Tool

    Usage: tools [-i <input>] [-o <output>]

    Options:
        -i, --input <input>    The input
                               [Default: stdin]
        -o, --output <output>  The output
                               [Default: stdout]
    """
    opts = Options.from_docopt(help_string)

    assert opts['input'].option_type == TYPE_INPUT
    assert opts['output'].option_type == TYPE_OUTPUT
    assert opts['input'].raw() == sys.stdin
    assert opts['output'].raw() == sys.stdout
예제 #22
0
def test_docopt_parser_with_opts():
    help_string = """\
    Some Tool

    Usage: tools [-t] [-i <input>...] [-o <output>] <cmd>

    Inputs:
        -i, --input <input>    The input

    Outputs:
        -o, --output <output>  The output

    Options:
        -t, --test             Some option
        -h, --help             Show help

    """
    opts = Options.from_docopt(help_string)

    assert len(opts) == 4  # the two + help
    assert opts["input"] is not None
    assert opts["input"].nargs == "*"
    assert opts["input"].option_type == TYPE_INPUT
    assert not opts["input"].required
    assert opts["output"] is not None
    assert opts["output"].nargs == 1
    assert opts["output"].option_type == TYPE_OUTPUT
    assert not opts["output"].required
    assert opts["test"] is not None
    assert opts["test"].nargs == 0
    assert not opts["test"].required
    assert opts["test"].option_type == TYPE_OPTION
    assert opts["cmd"] is not None
    assert opts["cmd"].nargs == 1
    assert opts["cmd"].required
    assert opts["cmd"].option_type == TYPE_OPTION
예제 #23
0
def test_docopt_parser_with_opts():
    help_string = """\
    Some Tool

    Usage: tools [-t] [-i <input>...] [-o <output>] <cmd>

    Inputs:
        -i, --input <input>    The input

    Outputs:
        -o, --output <output>  The output

    Options:
        -t, --test             Some option
        -h, --help             Show help

    """
    opts = Options.from_docopt(help_string)

    assert len(opts) == 4  # the two + help
    assert opts['input'] is not None
    assert opts['input'].nargs == "*"
    assert opts['input'].option_type == TYPE_INPUT
    assert not opts['input'].required
    assert opts['output'] is not None
    assert opts['output'].nargs == 1
    assert opts['output'].option_type == TYPE_OUTPUT
    assert not opts['output'].required
    assert opts['test'] is not None
    assert opts['test'].nargs == 0
    assert not opts['test'].required
    assert opts['test'].option_type == TYPE_OPTION
    assert opts['cmd'] is not None
    assert opts['cmd'].nargs == 1
    assert opts['cmd'].required
    assert opts['cmd'].option_type == TYPE_OPTION