Skip to content

Commit 844dcca

Browse files
committed
add some test: convert
1 parent 0c1cc1e commit 844dcca

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

tests/test_cli.py

+31-5
Original file line numberDiff line numberDiff line change
@@ -728,15 +728,16 @@ def test_shell_plus(
728728
(['convert', '.']),
729729
(['convert', '.tmuxp.yaml']),
730730
(['convert', '.tmuxp.yaml', '-y']),
731+
(['convert', '.tmuxp.yml']),
732+
(['convert', '.tmuxp.yml', '-y']),
731733
],
732734
)
733735
def test_convert(cli_args, tmpdir, monkeypatch):
734736
# create dummy tmuxp yaml so we don't get yelled at
735-
tmpdir.join('.tmuxp.yaml').write(
736-
"""
737-
session_name: hello
738-
"""
739-
)
737+
filename = '.tmuxp.yaml' if cli_args[1] == '.' else cli_args[1]
738+
file_ext = filename.rsplit('.', 1)[-1]
739+
assert file_ext in ['yaml', 'yml'], file_ext
740+
tmpdir.join(filename).write('\nsession_name: hello\n')
740741
tmpdir.join('.oh-my-zsh').ensure(dir=True)
741742
monkeypatch.setenv('HOME', str(tmpdir))
742743

@@ -753,6 +754,31 @@ def test_convert(cli_args, tmpdir, monkeypatch):
753754
)
754755

755756

757+
@pytest.mark.parametrize(
758+
"cli_args",
759+
[
760+
(['convert', '.']),
761+
(['convert', '.tmuxp.json']),
762+
(['convert', '.tmuxp.json', '-y']),
763+
],
764+
)
765+
def test_convert_json(cli_args, tmpdir, monkeypatch):
766+
# create dummy tmuxp yaml so we don't get yelled at
767+
tmpdir.join('.tmuxp.json').write('{"session_name": "hello"}')
768+
tmpdir.join('.oh-my-zsh').ensure(dir=True)
769+
monkeypatch.setenv('HOME', str(tmpdir))
770+
771+
with tmpdir.as_cwd():
772+
runner = CliRunner()
773+
774+
# If autoconfirm (-y) no need to prompt y
775+
input_args = 'y\ny\n' if '-y' not in cli_args else ''
776+
777+
runner.invoke(cli.cli, cli_args, input=input_args)
778+
assert tmpdir.join('.tmuxp.yaml').check()
779+
assert tmpdir.join('.tmuxp.yaml').open().read() == 'session_name: hello\n'
780+
781+
756782
@pytest.mark.parametrize("cli_args", [(['import'])])
757783
def test_import(cli_args, monkeypatch):
758784
runner = CliRunner()

0 commit comments

Comments
 (0)