From 08e50f96e8314563f9c875ff29119ea409ff9566 Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Sun, 20 Oct 2019 09:48:25 +0200 Subject: [PATCH] Improve error message when only --test is passed #339 --- jupytext/cli.py | 7 +++++-- tests/test_cli.py | 10 +++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/jupytext/cli.py b/jupytext/cli.py index baa080ee9..9726ebd67 100644 --- a/jupytext/cli.py +++ b/jupytext/cli.py @@ -225,12 +225,15 @@ def log(text): print_paired_paths(args.notebooks[0], args.input_format) return 1 + if (args.test or args.test_strict) and not args.to and not args.output and not args.sync: + raise ValueError('Please provide one of --to, --output or --sync') + if not args.to and not args.output and not args.sync \ and not args.pipe and not args.check \ - and not args.test and not args.test_strict \ and not args.update_metadata and not args.set_kernel \ and not args.execute: - raise ValueError('Please select an action') + raise ValueError('Please provide one of --to, --output, --sync, --pipe, ' + '--check, --update_metadata, --set-kernel or --execute') if args.output and len(args.notebooks) != 1: raise ValueError('Please input a single notebook when using --output') diff --git a/tests/test_cli.py b/tests/test_cli.py index 6ec83d5da..06c36c1c7 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -180,7 +180,7 @@ def test_error_not_same_ext(tmp_ipynb, tmpdir): def test_error_no_action(tmp_ipynb): - with pytest.raises(ValueError, match="Please select an action"): + with pytest.raises(ValueError, match="Please provide one of"): jupytext([tmp_ipynb]) @@ -982,3 +982,11 @@ def erroneous_is_magic(line, language, comment_magics): with mock.patch('jupytext.magics.is_magic', erroneous_is_magic): assert jupytext([tmp_py, '--to', 'ipynb', '--test-strict']) != 0 + + +def test_339_require_to(tmpdir): + """Test that the to argument is asked for when a `--test` command is provided""" + tmp_py = str(tmpdir.join('test.py')) + + with pytest.raises(ValueError, match='--to'): + jupytext([tmp_py, '--test-strict'])