def test_tool_empty_list_options(): help_string = """\ Some Tool Usage: tools -i <input>... [-o <output>...] Options: -i, --input <input>... The input -o, --output <output>... The output """ tool = Tool(help_string) assert tool.options is not None assert len(tool.options) == 2 tool.parse_args(['-i', 'A', 'B']) assert tool.options['input'].raw() == ['A', 'B'] assert tool.options['output'].raw() == []
def test_tool_validate_input_file_not_found(): 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] """ tool = Tool(help_string) tool.parse_args(["-i", "unknown"]) with pytest.raises(ValidationError) as execinfo: tool.validate() assert "Input file not found: unknown" in str(execinfo.value)
def test_tool_validation_unknown(): 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] """ tool = Tool(help_string) assert tool.options is not None assert len(tool.options) == 2 with pytest.raises(ParserException) as execinfo: tool.parse_args(["-x"]) assert str(execinfo.value) == "tools :: unrecognized arguments: -x"