def test_ignore_invalid_filenames( self, session_info, config_dir, config_file, capsys ): config_file(**session_info[0]) ignored = {**session_info[1], "filename": "foo.conf"} config_file(**ignored) rofi_tmuxp.main() captured = capsys.readouterr() assert captured.out == "test session 1\n"
def test_prints_sessions(self, monkeypatch, config_dir, capsys): monkeypatch.setenv("EXPAND_ENV", "expanded") rofi_tmuxp.main() captured = capsys.readouterr() assert sorted(captured.out.splitlines()) == sorted( [ "Session 💩", "test session 1", "田中さんにあげて下さい", "expanded session", ] )
def test_safe_yaml(self, config_dir, write_config, caplog, capsys): write_config("danger.yaml", "session_name: !!python/object/apply:object []") rofi_tmuxp.main() captured = capsys.readouterr() assert captured.out == "" match_logs( "rofi_tmuxp", logging.WARNING, r"Error loading config '{}': ConstructorError".format( config_dir / "danger.yaml" ), caplog.record_tuples, )
def test_session_not_found(self, monkeypatch, mocker, mock_popen, caplog): with monkeypatch.context() as monkey: monkey.setattr("sys.argv", ["rofi-tmuxp", "I don't exist"]) rofi_tmuxp.main() assert mock_popen.call_args_list == [ mocker.call( ["rofi", "-e", "No such session: I don't exist"], stdout=subprocess.DEVNULL, ) ] match_logs( "rofi_tmuxp", logging.WARNING, r"No such session: I don't exist", caplog.record_tuples, )
def test_ignore_extra_args(self, monkeypatch, mocker, mock_popen, config_dir): with monkeypatch.context() as monkey: monkey.setattr( "sys.argv", ["rofi-tmuxp", "test session 1", "extra", "argument"] ) rofi_tmuxp.main() assert mock_popen.call_args_list == [ mocker.call( [ "rofi-sensible-terminal", "-e", "tmuxp", "load", str(config_dir / "test1.yml"), ], stdout=subprocess.DEVNULL, ) ]
def test_launches_session( self, monkeypatch, mocker, mock_popen, config_dir, session_name, config_filename ): with monkeypatch.context() as monkey: monkey.setattr("sys.argv", ["rofi-tmuxp", session_name]) rofi_tmuxp.main() assert mock_popen.call_args_list == [ mocker.call( [ "rofi-sensible-terminal", "-e", "tmuxp", "load", str(config_dir / config_filename), ], stdout=subprocess.DEVNULL, ) ]
def test_ignore_invalid_session_configs( self, session_info, config_dir, config_file, write_config, caplog, capsys, bad_filename, ): config_file(**session_info[0]) write_config(bad_filename, "[") rofi_tmuxp.main() captured = capsys.readouterr() assert captured.out == "test session 1\n" match_logs( "rofi_tmuxp", logging.WARNING, r"Error loading config '{}'".format(config_dir / bad_filename), caplog.record_tuples, )
def test_ignore_sessions_without_name( self, session_info, config_dir, config_file, caplog, capsys ): config_file(**session_info[0]) config_file( filename="invalid.yaml", filetype="yaml", data={"windows": [{"panes": [None, None]}]}, ) rofi_tmuxp.main() captured = capsys.readouterr() assert captured.out == "test session 1\n" match_logs( "rofi_tmuxp", logging.WARNING, r"Invalid config \'{}\': No session name configured".format( config_dir / "invalid.yaml" ), caplog.record_tuples, )
def test_no_session_configs(self, config_dir, capsys): rofi_tmuxp.main() captured = capsys.readouterr() assert captured.out == ""