Skip to content

Commit 9eb6c21

Browse files
committed
more coverage
1 parent cdcc761 commit 9eb6c21

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

dockerfile_parse/util.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,8 @@ def parse(cls, image_name):
388388

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

392394
result = self.get_repo(explicit_namespace)
393395

tests/test_parser.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,26 @@ def test_util_image_name_get_repo(self, image_string, dictionary):
6969

7070
def test_util_image_name_to_str(self, image_string, dictionary):
7171
image = ImageName.parse(image_string)
72-
assert image.to_str() == (image_string.lstrip('/') if image_string else None)
73-
assert image.to_str(explicit_tag=True) == image_string.lstrip('/') + (':latest' if dictionary["tag"] is None else "")
72+
if dictionary["repo"] is None:
73+
with pytest.raises(RuntimeError):
74+
image.to_str()
75+
else:
76+
assert image.to_str() == image_string.lstrip('/')
77+
assert image.to_str() == (image_string.lstrip('/') if image_string else None)
78+
assert image.to_str(explicit_tag=True) == \
79+
image_string.lstrip('/') + (':latest' if dictionary["tag"] is None else "")
80+
81+
def test_image_name_hash(self, image_string, dictionary):
82+
image = ImageName.parse(image_string)
83+
if dictionary["repo"] is None:
84+
with pytest.raises(RuntimeError):
85+
hash(image)
86+
else:
87+
hash(image)
88+
89+
def test_image_name_repr(self, image_string, dictionary):
90+
image = ImageName.parse(image_string)
91+
repr(image)
7492

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

123-
def test_image_name_hash():
124-
hash(ImageName("Hello"))
125-
126-
def test_image_name_repr():
127-
repr(ImageName("World"))
128141

129142
class TestDockerfileParser(object):
130143
def test_all_versions_match(self):

0 commit comments

Comments
 (0)