From 72fbd6564993a415043a0566d19cb57e5f53fed0 Mon Sep 17 00:00:00 2001 From: Simon Li Date: Mon, 27 Jul 2020 20:32:34 +0100 Subject: [PATCH] validate_image_name: mention lowercase, fix formatting --- repo2docker/__main__.py | 6 ++--- tests/unit/test_argumentvalidation.py | 32 +++++++++------------------ 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/repo2docker/__main__.py b/repo2docker/__main__.py index c73d10d8..f4a8f000 100644 --- a/repo2docker/__main__.py +++ b/repo2docker/__main__.py @@ -31,9 +31,9 @@ def validate_image_name(image_name): """ if not is_valid_docker_image_name(image_name): msg = ( - "%r is not a valid docker image name. Image name" - "must start with an alphanumeric character and" - "can then use _ . or - in addition to alphanumeric." % image_name + "%r is not a valid docker image name. Image name " + "must start with a lowercase or numeric character and " + "can then use _ . or - in addition to lowercase and numeric." % image_name ) raise argparse.ArgumentTypeError(msg) return image_name diff --git a/tests/unit/test_argumentvalidation.py b/tests/unit/test_argumentvalidation.py index 11647e37..d2475b89 100644 --- a/tests/unit/test_argumentvalidation.py +++ b/tests/unit/test_argumentvalidation.py @@ -21,6 +21,13 @@ def temp_cwd(tmpdir): tmpdir.chdir() +invalid_image_name_template = ( + "%r is not a valid docker image name. Image name " + "must start with a lowercase or numeric character and " + "can then use _ . or - in addition to lowercase and numeric." +) + + def validate_arguments(builddir, args_list=".", expected=None, disable_dockerd=False): try: cmd = ["repo2docker"] @@ -50,11 +57,7 @@ def test_image_name_fail(temp_cwd): image_name = "Test/Invalid_name:1.0.0" args_list = ["--no-run", "--no-build", "--image-name", image_name] - expected = ( - "%r is not a valid docker image name. Image name" - "must start with an alphanumeric character and" - "can then use _ . or - in addition to alphanumeric." % image_name - ) + expected = invalid_image_name_template % image_name assert not validate_arguments(builddir, args_list, expected) @@ -65,11 +68,7 @@ def test_image_name_underscore_fail(temp_cwd): image_name = "_test/invalid_name:1.0.0" args_list = ["--no-run", "--no-build", "--image-name", image_name] - expected = ( - "%r is not a valid docker image name. Image name" - "must start with an alphanumeric character and" - "can then use _ . or - in addition to alphanumeric." % image_name - ) + expected = invalid_image_name_template % image_name assert not validate_arguments(builddir, args_list, expected) @@ -80,11 +79,7 @@ def test_image_name_double_dot_fail(temp_cwd): image_name = "test..com/invalid_name:1.0.0" args_list = ["--no-run", "--no-build", "--image-name", image_name] - expected = ( - "%r is not a valid docker image name. Image name" - "must start with an alphanumeric character and" - "can then use _ . or - in addition to alphanumeric." % image_name - ) + expected = invalid_image_name_template % image_name assert not validate_arguments(builddir, args_list, expected) @@ -96,12 +91,7 @@ def test_image_name_valid_restircted_registry_domain_name_fail(temp_cwd): image_name = "Test.com/valid_name:1.0.0" args_list = ["--no-run", "--no-build", "--image-name", image_name] - expected = ( - "%r is not a valid docker image name. Image name" - "must start with an alphanumeric character and" - "can then use _ . or - in addition to alphanumeric." % image_name - ) - + expected = invalid_image_name_template % image_name assert not validate_arguments(builddir, args_list, expected)