From 0c1cc1e67aed58497b2857212dfb297e6a7d31a3 Mon Sep 17 00:00:00 2001 From: catroll Date: Sat, 8 Jan 2022 19:41:54 +0800 Subject: [PATCH 1/4] Update tmuxp/cli.py --- tmuxp/cli.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tmuxp/cli.py b/tmuxp/cli.py index 811086698d0..eb8955b2683 100644 --- a/tmuxp/cli.py +++ b/tmuxp/cli.py @@ -1186,10 +1186,13 @@ 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) From 844dcca4db7d050d0fdba557322fa7faf40078e9 Mon Sep 17 00:00:00 2001 From: catroll Date: Thu, 13 Jan 2022 13:26:23 +0800 Subject: [PATCH 2/4] add some test: convert --- tests/test_cli.py | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 40dc72fab18..03f7f3d1b30 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -728,15 +728,16 @@ 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 = '.tmuxp.yaml' if cli_args[1] == '.' else cli_args[1] + 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 +754,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() From 16b3fcb941bd448ac2ef5b89cf400ee86ee49609 Mon Sep 17 00:00:00 2001 From: catroll Date: Tue, 18 Jan 2022 22:44:03 +0800 Subject: [PATCH 3/4] style: tmuxp/cli.py: width too long (96 > 88) --- tmuxp/cli.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tmuxp/cli.py b/tmuxp/cli.py index eb8955b2683..201d72282e0 100644 --- a/tmuxp/cli.py +++ b/tmuxp/cli.py @@ -1192,7 +1192,9 @@ def command_convert(confirmed, config): elif ext in ['.yaml', '.yml']: to_filetype = 'json' else: - raise click.BadParameter('Unknown filetype: %s (valid: [.json, .yaml, .yml])' % (ext, )) + raise click.BadParameter( + 'Unknown filetype: %s (valid: [.json, .yaml, .yml])' % (ext,) + ) configparser = kaptan.Kaptan() configparser.import_config(config) From 21ecc1e594c20deb0e099297d42eedf8b2921a28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=98=82?= Date: Tue, 18 Jan 2022 22:45:43 +0800 Subject: [PATCH 4/4] Update tests/test_cli.py Co-authored-by: Tony Narlock --- tests/test_cli.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 03f7f3d1b30..cf0ec046b4c 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -734,7 +734,9 @@ def test_shell_plus( ) def test_convert(cli_args, tmpdir, monkeypatch): # create dummy tmuxp yaml so we don't get yelled at - filename = '.tmuxp.yaml' if cli_args[1] == '.' else cli_args[1] + 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')