diff --git a/tests/test_cli.py b/tests/test_cli.py index 40dc72fab1..cf0ec046b4 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -728,15 +728,18 @@ def test_shell_plus( (['convert', '.']), (['convert', '.tmuxp.yaml']), (['convert', '.tmuxp.yaml', '-y']), + (['convert', '.tmuxp.yml']), + (['convert', '.tmuxp.yml', '-y']), ], ) def test_convert(cli_args, tmpdir, monkeypatch): # create dummy tmuxp yaml so we don't get yelled at - tmpdir.join('.tmuxp.yaml').write( - """ -session_name: hello - """ - ) + filename = cli_args[1] + if filename == '.': + filename = '.tmuxp.yaml' + file_ext = filename.rsplit('.', 1)[-1] + assert file_ext in ['yaml', 'yml'], file_ext + tmpdir.join(filename).write('\nsession_name: hello\n') tmpdir.join('.oh-my-zsh').ensure(dir=True) monkeypatch.setenv('HOME', str(tmpdir)) @@ -753,6 +756,31 @@ def test_convert(cli_args, tmpdir, monkeypatch): ) +@pytest.mark.parametrize( + "cli_args", + [ + (['convert', '.']), + (['convert', '.tmuxp.json']), + (['convert', '.tmuxp.json', '-y']), + ], +) +def test_convert_json(cli_args, tmpdir, monkeypatch): + # create dummy tmuxp yaml so we don't get yelled at + tmpdir.join('.tmuxp.json').write('{"session_name": "hello"}') + tmpdir.join('.oh-my-zsh').ensure(dir=True) + monkeypatch.setenv('HOME', str(tmpdir)) + + with tmpdir.as_cwd(): + runner = CliRunner() + + # If autoconfirm (-y) no need to prompt y + input_args = 'y\ny\n' if '-y' not in cli_args else '' + + runner.invoke(cli.cli, cli_args, input=input_args) + assert tmpdir.join('.tmuxp.yaml').check() + assert tmpdir.join('.tmuxp.yaml').open().read() == 'session_name: hello\n' + + @pytest.mark.parametrize("cli_args", [(['import'])]) def test_import(cli_args, monkeypatch): runner = CliRunner() diff --git a/tmuxp/cli.py b/tmuxp/cli.py index 811086698d..201d72282e 100644 --- a/tmuxp/cli.py +++ b/tmuxp/cli.py @@ -1186,10 +1186,15 @@ def command_convert(confirmed, config): """Convert a tmuxp config between JSON and YAML.""" _, ext = os.path.splitext(config) - if 'json' in ext: + ext = ext.lower() + if ext == '.json': to_filetype = 'yaml' - elif 'yaml' in ext: + elif ext in ['.yaml', '.yml']: to_filetype = 'json' + else: + raise click.BadParameter( + 'Unknown filetype: %s (valid: [.json, .yaml, .yml])' % (ext,) + ) configparser = kaptan.Kaptan() configparser.import_config(config)