Skip to content

Commit 0ff97cb

Browse files
refactor: remove unused 'create_new' arg from 'update_yaml_file()'
1 parent 7f89c30 commit 0ff97cb

2 files changed

Lines changed: 3 additions & 47 deletions

File tree

gitopscli/yaml/yaml_util.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,19 @@ def get_string(self):
2020
return stream.get_string()
2121

2222

23-
def update_yaml_file(file_path, key, value, create_new=False):
23+
def update_yaml_file(file_path, key, value):
2424
yaml = YAML()
2525
with open(file_path, "r") as stream:
2626
content = yaml.load(stream)
2727

2828
keys, obj = key.split("."), content
2929
for k in keys[:-1]:
3030
if k not in obj or not isinstance(obj[k], dict):
31-
if not create_new:
32-
raise KeyError(f"Key '{key}' not found in YAML!")
33-
obj[k] = dict()
31+
raise KeyError(f"Key '{key}' not found in YAML!")
3432
obj = obj[k]
3533
if keys[-1] in obj and obj[keys[-1]] == value:
3634
return False # nothing to update
37-
if not create_new and keys[-1] not in obj:
35+
if keys[-1] not in obj:
3836
raise KeyError(f"Key '{key}' not found in YAML!")
3937
obj[keys[-1]] = value
4038

tests/yaml/test_yaml_util.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -72,48 +72,6 @@ def test_update_yaml_file(self):
7272

7373
with pytest.raises(KeyError):
7474
updated = update_yaml_file(test_file, "a.x", "foo")
75-
updated = update_yaml_file(test_file, "a.x", "foo", create_new=True)
76-
self.assertTrue(updated)
77-
78-
expected = """\
79-
a: # comment
80-
# comment
81-
b:
82-
d: 1 # comment
83-
c: '2' # comment
84-
x: foo
85-
"""
86-
actual = self._read_file(test_file)
87-
self.assertEqual(expected, actual)
88-
89-
with pytest.raises(KeyError):
90-
updated = update_yaml_file(test_file, "a.x.z", "foo_z")
91-
updated = update_yaml_file(test_file, "a.x.z", "foo_z", create_new=True)
92-
self.assertTrue(updated)
93-
94-
with pytest.raises(KeyError):
95-
updated = update_yaml_file(test_file, "a.x.y", "foo_y")
96-
updated = update_yaml_file(test_file, "a.x.y", "foo_y", create_new=True)
97-
self.assertTrue(updated)
98-
99-
with pytest.raises(KeyError):
100-
updated = update_yaml_file(test_file, "a.x.y.z", "foo_y_z")
101-
updated = update_yaml_file(test_file, "a.x.y.z", "foo_y_z", create_new=True)
102-
self.assertTrue(updated)
103-
104-
expected = """\
105-
a: # comment
106-
# comment
107-
b:
108-
d: 1 # comment
109-
c: '2' # comment
110-
x:
111-
z: foo_z
112-
y:
113-
z: foo_y_z
114-
"""
115-
actual = self._read_file(test_file)
116-
self.assertEqual(expected, actual)
11775

11876
def test_merge_yaml_element(self):
11977
test_file = self._create_file(

0 commit comments

Comments
 (0)