def test_fixed_takes_priority(): """if both --fixed and --width are used, fixed should be prefered.""" sys.argv.extend(["--settings", "--fixed", "-nNw", "123", "hi", "fake"]) with pytest.raises(SystemExit) as error: cmdline_entry() assert "'width': 80" in error.exconly()
def test_get_help(): """Ensure we raise SystemExit with a help message.""" sys.argv.append("--help") with pytest.raises(SystemExit): with patch.object(cmdline, "print_help") as helper: cmdline_entry() assert helper.called
def test_get_settings(): """You should get a dump of the settings if you use --settings.""" sys.argv.extend(["--settings", "-Nn", "uptime", "somehost.com"]) with pytest.raises(SystemExit) as error: cmdline_entry() message = error.exconly() should_finds = ["'debug': False", "'password_safety': False", "'password': None"] for should_find in should_finds: assert should_find in message
def test_username_passing(): """Ensure we can use a username that's not our own.""" sys.argv.extend(["-u", "joebob", "-nN", "w", "host"]) cmds, servers, options = cmdline_entry() assert options["username"] == "joebob" assert ["host"] == servers assert ["w"] == cmds
def test_get_settings(): """You should get a dump of the settings if you use --settings.""" sys.argv.extend(["--settings", "-Nn", "uptime", "somehost.com"]) with pytest.raises(SystemExit) as error: cmdline_entry() message = error.exconly() should_finds = [ "'debug': False", "'password_safety': False", "'password': None", ] for should_find in should_finds: assert should_find in message
def test_ssh_key_passing(): """Ensure we can provide a non-standard ssh key path.""" sys.argv.extend(["--ssh-key", "/home/bob/ssh_key", "-nN", "w", "host"]) cmds, servers, options = cmdline_entry() assert options["ssh_key"] == "/home/bob/ssh_key" assert ["host"] == servers assert ["w"] == cmds assert options["username"] is None
def test_csv_becomes_set_from_char(): """If the csv_char is non-standard, enable csv output.""" sys.argv.extend(["--csv-separator", "j", "-nN", "w", "host"]) cmds, servers, options = cmdline_entry() assert ["host"] == servers assert ["w"] == cmds assert options["style"] == -1 assert options["csv_char"] == "j"
def test_debugging(): """Ensure debug with no int sets debug to True.""" sys.argv.extend(["--debug", "-nN", "w", "host"]) cmds, servers, options = cmdline_entry() assert options["debug"] assert ["host"] == servers assert ["w"] == cmds assert options["username"] is None
def test_get_help_contents(option_mismatches, capfd): """Check the contents of --help includes all options.""" sys.argv.append("--help") dummy_runner = Bladerunner() with pytest.raises(SystemExit): cmdline_entry() # help is printed to stdout message, _ = capfd.readouterr() for option in dummy_runner.options: if option in option_mismatches: option_key = option_mismatches[option] else: option_key = option assert option_key.replace("_", "-") in message
def test_fixed_width_with_csv(): """Should raise a usage error.""" sys.argv.extend(["--fixed", "--csv", "uptime", "somehost"]) with pytest.raises(SystemExit): cmdline_entry()
def test_no_servers_raises(): """Should get an error unless both command and server are supplied.""" sys.argv.append("uptime") with pytest.raises(SystemExit): cmdline_entry()