def test_hostsfile_ioerrors_exit(): """It should SystemExit if we are unable to read the hosts file.""" fake_file = "/not/even/close/to/real/i/hope" class FakeSettings(object): host_file = [fake_file] servers = [] with pytest.raises(SystemExit) as error: get_servers(FakeSettings()) assert fake_file in error.exconly()
def test_reading_hostsfile(): """We should be able to pass in a file with a list of hostnames.""" hosts = ["server-01", "server-02", "server-03", "server-04"] hostsfile = tempfile.mktemp() with open(hostsfile, "w") as openhosts: openhosts.write("\n".join(hosts)) class FakeSettings(object): host_file = [hostsfile] servers = [] settings = FakeSettings() get_servers(settings) assert hosts == settings.servers
def test_reading_hostsfile(): """We should be able to pass in a file with a list of hostnames.""" hosts = [ "server-01", "server-02", "server-03", "server-04", ] hostsfile = tempfile.mktemp() with open(hostsfile, "w") as openhosts: openhosts.write("\n".join(hosts)) class FakeSettings(object): host_file = [hostsfile] servers = [] settings = FakeSettings() get_servers(settings) assert hosts == settings.servers