def test_parser_boolean_arguments(argument, option): """Test that the argument parsing defaults works.""" parser = create_parser() data = parse_arguments(parser.parse_args([ argument, ])) assert data[option] is True
def setUp(self): self.parser = create_parser() self.default_arguments = [ '-c', 'counter', '-l', 'haproxy/tests/files/huge.log', ]
def test_arguments_delta_invalid(delta): """Incorrectly formatted delta argument raises an exception.""" parser = create_parser() with pytest.raises(ValueError) as exception_info: parse_arguments(parser.parse_args([ '-d', delta, ])) assert '--delta argument is not valid' in str(exception_info)
def test_arguments_date_invalid(start): """Incorrectly formatted start argument raises an exception.""" parser = create_parser() with pytest.raises(ValueError) as exception_info: parse_arguments(parser.parse_args([ '-s', start, ])) assert '--start argument is not valid' in str(exception_info)
def test_show_help(capsys): """Check that the help is shown if no arguments are given.""" parser = create_parser() data = parse_arguments(parser.parse_args([])) main(data) output_text = capsys.readouterr().out assert 'optional arguments:' in output_text assert '--list-filters ' in output_text assert '--list-commands ' in output_text
def test_log_argument(filename, is_valid): """Check that the argument parsing validates that the file exists.""" parser = create_parser() if is_valid: data = parse_arguments(parser.parse_args(['-l', filename])) assert data['log'] == filename else: with pytest.raises(ValueError) as exception_info: parse_arguments(parser.parse_args(['-l', filename])) assert f'{filename} does not exist' in str(exception_info)
def test_arguments_dates(start, delta): """Check that properly formatted start and delta arguments are processed fine. Thus they are extracted and stored for later use. """ parser = create_parser() data = parse_arguments(parser.parse_args([ '-s', start, '-d', delta, ])) assert data['start'] == start assert data['delta'] == delta
def test_list_filters_and_commands(capsys, switch, listing): """Test that one can request the filters/commands to be listed.""" parser = create_parser() data = parse_arguments(parser.parse_args([f'--{switch}',])) argument = switch.replace('-', '_') for key in data: expected = None if key == argument: expected = True assert data[key] is expected main(data) output_text = capsys.readouterr().out for name in listing: assert f'{name}: ' in output_text
def test_parser_arguments_defaults(): """Test that the argument parsing defaults works.""" parser = create_parser() data = parse_arguments(parser.parse_args([])) assert data == { 'start': None, 'delta': None, 'commands': None, 'filters': None, 'negate_filter': None, 'log': None, 'list_commands': None, 'list_filters': None, 'json': False, 'invalid_lines': False, }
def test_filters_arguments(filters_list, is_valid): """Test that the filters are parsed, and an exception raised otherwise.""" parser = create_parser() if not is_valid: with pytest.raises(ValueError) as exception_info: parse_arguments(parser.parse_args([ '-f', filters_list, ])) assert 'is not available. Use --list-filters' in str(exception_info) else: data = parse_arguments(parser.parse_args([ '-f', filters_list, ])) assert data['filters'] == [(x, None) for x in filters_list.split(',')]
def test_commands_arguments(cmds, is_valid): """Test that the commands are parsed, and an exception raised otherwise.""" parser = create_parser() if not is_valid: with pytest.raises(ValueError) as exception_info: parse_arguments(parser.parse_args([ '-c', cmds, ])) assert 'is not available. Use --list-commands' in str(exception_info) else: data = parse_arguments(parser.parse_args([ '-c', cmds, ])) assert data['commands'] == cmds.split(',')