Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
change parameter raise_if_absent to raise_if_present
Browse files Browse the repository at this point in the history
  • Loading branch information
jschicktanz authored and ccwienk committed May 10, 2021
1 parent d1ee895 commit a337a60
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
8 changes: 3 additions & 5 deletions bindings-python/gci/componentmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,10 @@ def find_label(
def set_label(
self,
label: Label,
raise_if_absent: bool = False,
raise_if_present: bool = False,
) -> typing.List[Label]:
self.find_label(
name=label.name,
raise_if_absent=raise_if_absent,
)
if self.find_label(name=label.name) and raise_if_present:
raise ValueError(f'label {label.name} is already present')

patched_labels = [l for l in self.labels if l.name != label.name]
patched_labels.append(label)
Expand Down
48 changes: 24 additions & 24 deletions bindings-python/tests/gci/componentmodel_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ class TestCase(unittest.TestCase):
name: str
input_labels: typing.List[cm.Label]
label_to_set: cm.Label
raise_if_absent: bool
raise_if_present: bool
expected_labels: typing.List[cm.Label]
expected_err_msg: str

testcases = [
TestCase(
name='appends label to empty input_labels list',
name='appends label to empty input_labels list with raise_if_present == True',
input_labels=[],
label_to_set=cm.Label(
name=lssd_label_name,
Expand All @@ -91,7 +91,7 @@ class TestCase(unittest.TestCase):
],
},
),
raise_if_absent=False,
raise_if_present=True,
expected_labels=[
cm.Label(
name=lssd_label_name,
Expand All @@ -105,7 +105,7 @@ class TestCase(unittest.TestCase):
expected_err_msg=''
),
TestCase(
name='throws exception if len(input_labels) == 0 and raise_if_absent == True',
name='appends label to empty input_labels list with raise_if_present == False',
input_labels=[],
label_to_set=cm.Label(
name=lssd_label_name,
Expand All @@ -115,12 +115,21 @@ class TestCase(unittest.TestCase):
],
},
),
expected_labels=None,
raise_if_absent=True,
expected_err_msg=f'no such label: name=\'{lssd_label_name}\'',
raise_if_present=False,
expected_labels=[
cm.Label(
name=lssd_label_name,
value={
'processingRules': [
processing_rule_name,
],
},
),
],
expected_err_msg=''
),
TestCase(
name='throws no exception if label exists and raise_if_absent == True',
name='throws exception if label exists and raise_if_present == True',
input_labels=[
cm.Label(
name=lssd_label_name,
Expand All @@ -139,21 +148,12 @@ class TestCase(unittest.TestCase):
],
},
),
raise_if_absent=True,
expected_labels=[
cm.Label(
name=lssd_label_name,
value={
'processingRules': [
processing_rule_name,
],
},
),
],
expected_err_msg=''
raise_if_present=True,
expected_labels=None,
expected_err_msg=f'label {lssd_label_name} is already present'
),
TestCase(
name='overwrites preexisting label',
name='throws no exception if label exists and raise_if_present == False',
input_labels=[
cm.Label(
name='test-label',
Expand All @@ -177,7 +177,7 @@ class TestCase(unittest.TestCase):
],
},
),
raise_if_absent=False,
raise_if_present=False,
expected_labels=[
cm.Label(
name='test-label',
Expand Down Expand Up @@ -212,13 +212,13 @@ class TestCase(unittest.TestCase):
with testcase.assertRaises(ValueError) as ctx:
patched_resource = test_resource.set_label(
label=testcase.label_to_set,
raise_if_absent=testcase.raise_if_absent,
raise_if_present=testcase.raise_if_present,
)
assert str(ctx.exception) == testcase.expected_err_msg
else:
patched_resource = test_resource.set_label(
label=testcase.label_to_set,
raise_if_absent=testcase.raise_if_absent,
raise_if_present=testcase.raise_if_present,
)
testcase.assertListEqual(
list1=patched_resource.labels,
Expand Down

0 comments on commit a337a60

Please sign in to comment.