kopia lustrzana https://github.com/jupyterhub/repo2docker
Changed to google style docstrings. Added image_name validation test.
rodzic
5372b09333
commit
f04aa4da97
|
@ -124,10 +124,18 @@ class Repo2Docker(Application):
|
|||
|
||||
def validate_image_name(self, image_name):
|
||||
"""
|
||||
Validate that the image_name read by argparse contains only lowercase characters
|
||||
:param image_name: string argument read by argparse
|
||||
:return: test and return image_name if it only contains lowercase characters else raise error
|
||||
Validate image_name read by argparse contains only lowercase characters
|
||||
|
||||
Args:
|
||||
image_name: string argument read by the argument parser
|
||||
|
||||
Returns:
|
||||
unmodified image_name
|
||||
|
||||
Raises:
|
||||
ArgumentTypeError: if image_name contains characters that are not lowercase
|
||||
"""
|
||||
|
||||
if not image_name.islower():
|
||||
msg = "%r is not a valid docker image name. Image name can contain only lowercase characters." % image_name
|
||||
raise argparse.ArgumentTypeError(msg)
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
"""
|
||||
Tests that runs validity checks on arguments passed in from shell
|
||||
"""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
def does_validate_image_name(builddir, image_name):
|
||||
try:
|
||||
output = subprocess.check_output(
|
||||
[
|
||||
'repo2docker',
|
||||
'--no-run',
|
||||
'--image-name',
|
||||
str(image_name),
|
||||
builddir
|
||||
],
|
||||
stderr=subprocess.STDOUT,
|
||||
).decode()
|
||||
print(output)
|
||||
return True
|
||||
except subprocess.CalledProcessError as e:
|
||||
output = e.output.decode()
|
||||
print(output)
|
||||
if "error: argument --image-name: %r is not a valid docker image name. " \
|
||||
"Image name can contain only lowercase characters." % image_name in output:
|
||||
return False
|
||||
else:
|
||||
raise
|
||||
|
||||
def test_image_name_fail():
|
||||
builddir = os.path.dirname(__file__)
|
||||
|
||||
assert not does_validate_image_name(builddir, 'Test/Invalid_name:1.0.0')
|
||||
|
Ładowanie…
Reference in New Issue