From 8c22e42ee442f18a6d84d8f96211a74c2de6938a Mon Sep 17 00:00:00 2001 From: Chris Holdgraf Date: Tue, 24 Apr 2018 16:51:39 -0700 Subject: [PATCH] adding test and more informative error --- repo2docker/app.py | 7 ++++--- tests/argumentvalidation.py | 11 ++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/repo2docker/app.py b/repo2docker/app.py index df712585..7820f0b4 100644 --- a/repo2docker/app.py +++ b/repo2docker/app.py @@ -177,7 +177,8 @@ class Repo2Docker(Application): if ref: if len(ref.split('/')) != 2: - raise ValueError('--ref must be of the form remote/ref') + raise ValueError('Expected --ref to be of the form ' + 'remote/reference, but got %s' % ref) try: for line in execute_cmd(['git', 'reset', '--hard', ref], cwd=checkout_path, @@ -247,8 +248,8 @@ class Repo2Docker(Application): argparser.add_argument( '--ref', - help=('If building a git url, which ref to check out. Must be of' - 'the form `remote/ref`. E.g., `origin/master`.') + help=('If building a git url, which reference to check out. Must ' + 'be of the form `remote/reference`. E.g., `origin/master`.') ) argparser.add_argument( diff --git a/tests/argumentvalidation.py b/tests/argumentvalidation.py index c8a5c4bd..e1a73e9c 100644 --- a/tests/argumentvalidation.py +++ b/tests/argumentvalidation.py @@ -138,7 +138,7 @@ def test_volume_no_run_fail(): def test_env_no_run_fail(): """ - Test to check if repo2docker fails when both --no-run and -e arguments are given + Test to check if repo2docker fails when both --no-run and -e arguments are given """ builddir = os.path.dirname(__file__) args_list = ['--no-run', '-e', 'FOO=bar', '--'] @@ -231,3 +231,12 @@ def test_docker_no_build_success(): assert validate_arguments(builddir, args_list, "", True) + +def test_ref_has_correct_form(): + """ + Test to check if --ref is given with the form `remote/reference` + """ + builddir = os.path.dirname(__file__) + args_list = ['--no-run', '--no-build', '--ref', 'myreference'] + + assert not validate_arguments(builddir, args_list, 'Expected --ref to be of the form remote/reference, but got myreference')