Skip to content

Commit c86036a

Browse files
authored
fix: to_filetype not defined (#725)
* Update tmuxp/cli.py * add some test: convert * style: tmuxp/cli.py: width too long (96 > 88) * Update tests/test_cli.py
1 parent 4913143 commit c86036a

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

tests/test_cli.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -728,15 +728,18 @@ 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 = cli_args[1]
738+
if filename == '.':
739+
filename = '.tmuxp.yaml'
740+
file_ext = filename.rsplit('.', 1)[-1]
741+
assert file_ext in ['yaml', 'yml'], file_ext
742+
tmpdir.join(filename).write('\nsession_name: hello\n')
740743
tmpdir.join('.oh-my-zsh').ensure(dir=True)
741744
monkeypatch.setenv('HOME', str(tmpdir))
742745

@@ -753,6 +756,31 @@ def test_convert(cli_args, tmpdir, monkeypatch):
753756
)
754757

755758

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

tmuxp/cli.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,10 +1186,15 @@ def command_convert(confirmed, config):
11861186
"""Convert a tmuxp config between JSON and YAML."""
11871187

11881188
_, ext = os.path.splitext(config)
1189-
if 'json' in ext:
1189+
ext = ext.lower()
1190+
if ext == '.json':
11901191
to_filetype = 'yaml'
1191-
elif 'yaml' in ext:
1192+
elif ext in ['.yaml', '.yml']:
11921193
to_filetype = 'json'
1194+
else:
1195+
raise click.BadParameter(
1196+
'Unknown filetype: %s (valid: [.json, .yaml, .yml])' % (ext,)
1197+
)
11931198

11941199
configparser = kaptan.Kaptan()
11951200
configparser.import_config(config)

0 commit comments

Comments
 (0)