def test_cmdfile_ioerrors_exit(): """If we are unable to read the cmd file, it should SystemExit.""" fake_file = "/not/even/close/to/real/i/hope" class FakeSettings(object): command = "somehost" command_file = [fake_file] servers = [] with pytest.raises(SystemExit) as error: get_commands(FakeSettings()) assert fake_file in error.exconly()
def test_reading_command_file(): """Make a tempfile, ensure it's read into the commands list.""" commands = ["echo 'hello world'", "uptime", "", "who"] # empty lines should be skipped cmd_file = tempfile.mktemp() with open(cmd_file, "w") as opencmds: opencmds.write("\n".join(commands)) class FakeSettings(object): command = "somehost" command_file = [cmd_file] servers = [] commands_post, settings = get_commands(FakeSettings()) commands.pop(2) # remove the empty line assert commands == commands_post
def test_reading_command_file(): """Make a tempfile, ensure it's read into the commands list.""" commands = [ "echo 'hello world'", "uptime", "", # empty lines should be skipped "who", ] cmd_file = tempfile.mktemp() with open(cmd_file, "w") as opencmds: opencmds.write("\n".join(commands)) class FakeSettings(object): command = "somehost" command_file = [cmd_file] servers = [] commands_post, settings = get_commands(FakeSettings()) commands.pop(2) # remove the empty line assert commands == commands_post