Skip to content

Commit c13e0ad

Browse files
committed
Add tests for cli
1 parent 916523b commit c13e0ad

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

tests/test_cli.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,64 @@ def test_load_zsh_autotitle_warning(cli_args, tmpdir, monkeypatch):
406406
assert 'Please set' not in result.output
407407

408408

409+
@pytest.mark.parametrize(
410+
"cli_args,inputs,expected_output",
411+
[
412+
(
413+
['cli', '-L{SOCKET_NAME}', '-c', 'print(str(server.socket_name))'],
414+
[],
415+
'{SERVER_SOCKET_NAME}',
416+
),
417+
(
418+
[
419+
'cli',
420+
'-L{SOCKET_NAME}',
421+
'{SESSION_NAME}',
422+
'-c',
423+
'print(session.name)',
424+
],
425+
[],
426+
'{SESSION_NAME}',
427+
),
428+
(
429+
[
430+
'cli',
431+
'-L{SOCKET_NAME}',
432+
'{SESSION_NAME}',
433+
'{WINDOW_NAME}',
434+
'-c',
435+
'print(server.has_session(session.name))',
436+
],
437+
[],
438+
'True',
439+
),
440+
],
441+
)
442+
def test_cli(cli_args, inputs, expected_output, tmpdir, monkeypatch, server, session):
443+
monkeypatch.setenv('HOME', str(tmpdir))
444+
window_name = 'my_window'
445+
window = session.new_window(window_name=window_name)
446+
window.split_window()
447+
448+
template_ctx = dict(
449+
SOCKET_NAME=server.socket_name,
450+
SOCKET_PATH=server.socket_path,
451+
SESSION_NAME=session.name,
452+
WINDOW_NAME=window_name,
453+
SERVER_SOCKET_NAME=server.socket_name,
454+
)
455+
456+
cli_args[:] = [cli_arg.format(**template_ctx) for cli_arg in cli_args]
457+
458+
with tmpdir.as_cwd():
459+
runner = CliRunner()
460+
461+
result = runner.invoke(
462+
cli.cli, cli_args, input=''.join(inputs), catch_exceptions=False
463+
)
464+
assert expected_output.format(**template_ctx) in result.output
465+
466+
409467
@pytest.mark.parametrize(
410468
"cli_args",
411469
[

0 commit comments

Comments
 (0)