Skip to content

Commit

Permalink
more coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-vk committed Dec 4, 2022
1 parent cdcc761 commit 9eb6c21
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
2 changes: 2 additions & 0 deletions dockerfile_parse/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ def parse(cls, image_name):

def to_str(self, registry=True, tag=True, explicit_tag=False,
explicit_namespace=False):
if self.repo is None:
raise RuntimeError('No image repository specified')

result = self.get_repo(explicit_namespace)

Expand Down
27 changes: 20 additions & 7 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,26 @@ def test_util_image_name_get_repo(self, image_string, dictionary):

def test_util_image_name_to_str(self, image_string, dictionary):
image = ImageName.parse(image_string)
assert image.to_str() == (image_string.lstrip('/') if image_string else None)
assert image.to_str(explicit_tag=True) == image_string.lstrip('/') + (':latest' if dictionary["tag"] is None else "")
if dictionary["repo"] is None:
with pytest.raises(RuntimeError):
image.to_str()
else:
assert image.to_str() == image_string.lstrip('/')
assert image.to_str() == (image_string.lstrip('/') if image_string else None)
assert image.to_str(explicit_tag=True) == \
image_string.lstrip('/') + (':latest' if dictionary["tag"] is None else "")

def test_image_name_hash(self, image_string, dictionary):
image = ImageName.parse(image_string)
if dictionary["repo"] is None:
with pytest.raises(RuntimeError):
hash(image)
else:
hash(image)

def test_image_name_repr(self, image_string, dictionary):
image = ImageName.parse(image_string)
repr(image)

def test_image_name_comparison(self, image_string, dictionary):
# make sure that "==" is implemented correctly on both Python major releases
Expand Down Expand Up @@ -120,11 +138,6 @@ def test_image_name_enclose(repo, organization, enclosed_repo, registry, tag):
assert image_name.registry == registry
assert image_name.tag == tag

def test_image_name_hash():
hash(ImageName("Hello"))

def test_image_name_repr():
repr(ImageName("World"))

class TestDockerfileParser(object):
def test_all_versions_match(self):
Expand Down

0 comments on commit 9eb6c21

Please sign in to comment.