Skip to content

Commit

Permalink
Default values added for ovirt-img add_sub_command method; method cal…
Browse files Browse the repository at this point in the history
…ls also cleaned up across files

Signed-off-by: sri-srikanth <srivatsansrikanth2018@gmail.com>
  • Loading branch information
sri-srikanth committed Jun 3, 2023
1 parent 4e5f7e0 commit 746ecea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
3 changes: 2 additions & 1 deletion ovirt_imageio/client/_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ def __init__(self):
version=f'%(prog)s {version.string}')
self._commands = self._parser.add_subparsers(title="commands")

def add_sub_command(self, name, help, func, transfer_options=True):
def add_sub_command(self, name, help="help", func=lambda x: None,
transfer_options=True):
cmd = self._commands.add_parser(name, help=help)
cmd.set_defaults(command=func)

Expand Down
28 changes: 14 additions & 14 deletions test/client_options_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def config(tmpdir, monkeypatch):

def test_config_all(config):
parser = _options.Parser()
parser.add_sub_command("test", "help", lambda x: None)
parser.add_sub_command("test")
args = parser.parse(["test", "-c", "all"])
assert args.engine_url == "https://engine.com"
assert args.username == "username"
Expand All @@ -179,7 +179,7 @@ def test_config_all_override(config, tmpdir):
password_file.write("password")

parser = _options.Parser()
parser.add_sub_command("test", "help", lambda x: None)
parser.add_sub_command("test")
args = parser.parse([
"test",
"-c", "all",
Expand Down Expand Up @@ -210,7 +210,7 @@ def test_config_required(config, monkeypatch):
monkeypatch.setattr(getpass, "getpass", lambda: "password")

parser = _options.Parser()
parser.add_sub_command("test", "help", lambda x: None)
parser.add_sub_command("test")
args = parser.parse(["test", "-c", "required"])
assert args.engine_url == "https://engine.com"
assert args.username == "username"
Expand All @@ -233,7 +233,7 @@ def test_config_required_override(config, tmpdir):
password_file.write("password")

parser = _options.Parser()
parser.add_sub_command("test", "help", lambda x: None)
parser.add_sub_command("test")
args = parser.parse([
"test",
"-c", "required",
Expand Down Expand Up @@ -266,7 +266,7 @@ def test_config_required_override(config, tmpdir):
])
def test_config_missing(config, capsys, name, missing):
parser = _options.Parser()
parser.add_sub_command("test", "help", lambda x: None)
parser.add_sub_command("test")
with pytest.raises(SystemExit):
parser.parse(["test", "-c", name])
captured = capsys.readouterr()
Expand All @@ -276,7 +276,7 @@ def test_config_missing(config, capsys, name, missing):

def test_config_missing_override(config):
parser = _options.Parser()
parser.add_sub_command("test", "help", lambda x: None)
parser.add_sub_command("test")
args = parser.parse([
"test",
"-c", "missing3",
Expand All @@ -293,7 +293,7 @@ def test_config_missing_override(config):
])
def test_config_invalid(config, capsys, name):
parser = _options.Parser()
parser.add_sub_command("test", "help", lambda x: None)
parser.add_sub_command("test")
with pytest.raises(SystemExit):
parser.parse(["test", "-c", name])
captured = capsys.readouterr()
Expand All @@ -302,7 +302,7 @@ def test_config_invalid(config, capsys, name):

def test_config_no_section(config, capsys):
parser = _options.Parser()
parser.add_sub_command("test", "help", lambda x: None)
parser.add_sub_command("test")

# Required paremeters are available via the command line, but the specified
# configuration does not exist. This is likely a user error so fail loudly.
Expand All @@ -320,7 +320,7 @@ def test_config_no_section(config, capsys):

def test_transfer_options(config):
parser = _options.Parser()
parser.add_sub_command("test", "help", lambda x: None)
parser.add_sub_command("test")

args = parser.parse([
"test",
Expand All @@ -335,7 +335,7 @@ def test_transfer_options(config):
def test_transfer_options_disabled(config):
parser = _options.Parser()
parser.add_sub_command(
"test", "help", lambda x: None, transfer_options=False)
"test", transfer_options=False)
args = parser.parse([
"test",
"-c", "all",
Expand All @@ -350,7 +350,7 @@ def test_transfer_options_disabled(config):
])
def test_output_option(config, output):
parser = _options.Parser()
parser.add_sub_command("test", "help", lambda x: None)
parser.add_sub_command("test")

args = parser.parse([
"test",
Expand All @@ -362,7 +362,7 @@ def test_output_option(config, output):

def test_invalid_output_option(config, capsys):
parser = _options.Parser()
parser.add_sub_command("test", "help", lambda x: None)
parser.add_sub_command("test")

with pytest.raises(SystemExit):
parser.parse([
Expand All @@ -377,7 +377,7 @@ def test_invalid_output_option(config, capsys):
def test_auto_help(capsys):
# Running without arguments is same as running with --help.
parser = _options.Parser()
parser.add_sub_command("test", "help", lambda x: None)
parser.add_sub_command("test")

with pytest.raises(SystemExit):
parser.parse([])
Expand All @@ -392,7 +392,7 @@ def test_auto_help(capsys):

def test_version(capsys):
parser = _options.Parser()
parser.add_sub_command("test", "help", lambda x: None)
parser.add_sub_command("test")
with pytest.raises(SystemExit):
parser.parse(["--version"])
out = capsys.readouterr().out
Expand Down

0 comments on commit 746ecea

Please sign in to comment.