def test_valid_zuliprc_but_no_connection(capsys, mocker, minimal_zuliprc, server_connection_error="some_error"): mocker.patch('zulipterminal.core.Controller.__init__', side_effect=ServerConnectionFailure(server_connection_error)) with pytest.raises(SystemExit) as e: main(["-c", minimal_zuliprc]) assert str(e.value) == '1' captured = capsys.readouterr() lines = captured.out.strip().split("\n") expected_lines = [ "Loading with:", " theme 'default' specified with no config.", " autohide setting 'no_autohide' specified with no config.", "\x1b[91m", ("Error connecting to Zulip server: {}.\x1b[0m".format( server_connection_error)), ] assert lines == expected_lines assert captured.err == ""
def test_warning_regarding_incomplete_theme(capsys, mocker, monkeypatch, minimal_zuliprc, bad_theme, server_connection_error="sce"): mocker.patch('zulipterminal.core.Controller.__init__', side_effect=ServerConnectionFailure(server_connection_error)) monkeypatch.setitem(THEMES, bad_theme, []) mocker.patch('zulipterminal.cli.run.all_themes', return_value=('a', 'b', 'c', 'd')) mocker.patch('zulipterminal.cli.run.complete_and_incomplete_themes', return_value=(['a', 'b'], ['c', 'd'])) with pytest.raises(SystemExit) as e: main(["-c", minimal_zuliprc, "-t", bad_theme]) assert str(e.value) == '1' captured = capsys.readouterr() lines = captured.out.strip().split("\n") expected_lines = [ "Loading with:", " theme '{}' specified on command line.".format(bad_theme), "\x1b[93m" " WARNING: Incomplete theme; results may vary!", " (you could try: {}, {})" "\x1b[0m".format('a', 'b'), " autohide setting 'no_autohide' specified with no config.", "\x1b[91m", ("Error connecting to Zulip server: {}.\x1b[0m". format(server_connection_error)), ] assert lines == expected_lines assert captured.err == ""
def test_valid_zuliprc_but_no_connection(capsys, mocker, minimal_zuliprc, server_connection_error="some_error"): mocker.patch( "zulipterminal.core.Controller.__init__", side_effect=ServerConnectionFailure(server_connection_error), ) with pytest.raises(SystemExit) as e: main(["-c", minimal_zuliprc]) assert str(e.value) == "1" captured = capsys.readouterr() lines = captured.out.strip().split("\n") expected_lines = [ "Loading with:", " theme 'zt_dark' specified with no config.", " autohide setting 'no_autohide' specified with no config.", " maximum footlinks value '3' specified with no config.", " color depth setting '256' specified with no config.", " notify setting 'disabled' specified with no config.", "\x1b[91m", f"Error connecting to Zulip server: {server_connection_error}.\x1b[0m", ] assert lines == expected_lines assert captured.err == ""
def test_valid_zuliprc_but_no_connection(capsys, mocker, tmpdir, server_connection_error="some_error"): mocker.patch('zulipterminal.core.Controller.__init__', side_effect=ServerConnectionFailure(server_connection_error)) zuliprc_path = str(tmpdir) + "/zuliprc" with open(zuliprc_path, "w") as f: f.write("[api]") # minimal to avoid Exception with pytest.raises(SystemExit) as e: main(["-c", zuliprc_path]) assert str(e.value) == '1' captured = capsys.readouterr() lines = captured.out.strip().split("\n") expected_lines = [ "Loading with:", " theme 'default' specified with no config.", " autohide setting 'autohide' specified with no config.", "", ("\x1b[91mError connecting to Zulip server: {}.".format( server_connection_error)), ] assert lines == expected_lines assert captured.err == ""
def test_warning_regarding_incomplete_theme( capsys, mocker, monkeypatch, minimal_zuliprc, bad_theme, server_connection_error="sce", ): mocker.patch( "zulipterminal.core.Controller.__init__", side_effect=ServerConnectionFailure(server_connection_error), ) monkeypatch.setitem(THEMES, bad_theme, []) mocker.patch("zulipterminal.cli.run.all_themes", return_value=("a", "b", "c", "d")) mocker.patch( "zulipterminal.cli.run.complete_and_incomplete_themes", return_value=(["a", "b"], ["c", "d"]), ) with pytest.raises(SystemExit) as e: main(["-c", minimal_zuliprc, "-t", bad_theme]) assert str(e.value) == "1" captured = capsys.readouterr() lines = captured.out.strip().split("\n") expected_lines = [ "Loading with:", f" theme '{bad_theme}' specified on command line.", "\x1b[93m WARNING: Incomplete theme; results may vary!", f" (you could try: {'a'}, {'b'})\x1b[0m", " autohide setting 'no_autohide' specified with no config.", " maximum footlinks value '3' specified with no config.", " color depth setting '256' specified with no config.", " notify setting 'disabled' specified with no config.", "\x1b[91m", f"Error connecting to Zulip server: {server_connection_error}.\x1b[0m", ] assert lines == expected_lines assert captured.err == ""
def test_warning_regarding_incomplete_theme( capsys: CaptureFixture[str], mocker: MockerFixture, minimal_zuliprc: str, bad_theme: str, expected_complete_incomplete_themes: Tuple[List[str], List[str]], expected_warning: str, server_connection_error: str = "sce", ) -> None: mocker.patch( CONTROLLER + ".__init__", side_effect=ServerConnectionFailure(server_connection_error), ) mocker.patch(MODULE + ".all_themes", return_value=("a", "b", "c", "d")) mocker.patch( MODULE + ".complete_and_incomplete_themes", return_value=expected_complete_incomplete_themes, ) mocker.patch(MODULE + ".generate_theme") with pytest.raises(SystemExit) as e: main(["-c", minimal_zuliprc, "-t", bad_theme]) assert str(e.value) == "1" captured = capsys.readouterr() lines = captured.out.strip().split("\n") expected_lines = [ "Loading with:", f" theme '{bad_theme}' specified on command line.", "\x1b[93m WARNING: Incomplete theme; results may vary!", f" {expected_warning}\x1b[0m", " autohide setting 'no_autohide' specified with no config.", " maximum footlinks value '3' specified with no config.", " color depth setting '256' specified with no config.", " notify setting 'disabled' specified with no config.", "\x1b[91m", f"Error connecting to Zulip server: {server_connection_error}.\x1b[0m", ] assert lines == expected_lines assert captured.err == ""