Skip to content

Commit

Permalink
Test processor::delete_nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
wwkimball committed Jan 23, 2021
1 parent cce2891 commit 288ea1f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 12 deletions.
65 changes: 53 additions & 12 deletions tests/test_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,21 +311,23 @@ def test_set_value_in_none_data(self, capsys, quiet_logger):
("/top_hash/negative_float", -0.009, 1, True, YAMLValueFormats.FLOAT, PathSeperators.FSLASH),
("/top_hash/positive_float", -2.71828, 1, True, YAMLValueFormats.FLOAT, PathSeperators.FSLASH),
("/top_hash/negative_float", 5283.4, 1, True, YAMLValueFormats.FLOAT, PathSeperators.FSLASH),
("/null_value", "No longer null", 1, True, YAMLValueFormats.DEFAULT, PathSeperators.FSLASH),
])
def test_set_value(self, quiet_logger, yamlpath, value, tally, mustexist, vformat, pathsep):
yamldata = """---
aliases:
- &testAnchor Initial Value
top_array:
# Comment 1
- 1
# Comment 2
- 2
# Comment N
top_scalar: Top-level plain scalar string
top_hash:
positive_float: 3.14159265358
negative_float: -11.034
aliases:
- &testAnchor Initial Value
top_array:
# Comment 1
- 1
# Comment 2
- 2
# Comment N
top_scalar: Top-level plain scalar string
top_hash:
positive_float: 3.14159265358
negative_float: -11.034
null_value:
"""
yaml = YAML()
data = yaml.load(yamldata)
Expand Down Expand Up @@ -767,3 +769,42 @@ def test_get_every_data_type(self, quiet_logger):
for node in processor.get_nodes(yamlpath):
assert unwrap_node_coords(node) == results[match_index]
match_index += 1

@pytest.mark.parametrize("delete_yamlpath,new_flat_data", [
("/**[&alias_number]", [1,1,True,1,1,True,1,1,True,1,"ABC",123,"BCD",987,"CDE","8B8"]),
("/records[1]", [1,1,1,True,1,1,1,True,1,1,1,True,1,1,"CDE","8B8"]),
])
def test_delete_nodes(self, quiet_logger, delete_yamlpath, new_flat_data):
yamldata = """---
aliases:
- &alias_number 1
- &alias_bool true
number: 1
bool: true
alias_number: *alias_number
alias_bool: *alias_bool
hash:
number: 1
bool: true
alias_number: *alias_number
alias_bool: *alias_bool
complex:
hash:
number: 1
bool: true
alias_number: *alias_number
alias_bool: *alias_bool
records:
- id: ABC
data: 123
- id: BCD
data: 987
- id: CDE
data: 8B8
"""
yaml = YAML()
data = yaml.load(yamldata)
processor = Processor(quiet_logger, data)
processor.delete_nodes(delete_yamlpath)
for (test_value, verify_node_coord) in zip(new_flat_data, processor.get_nodes("**")):
assert test_value, unwrap_node_coords(verify_node_coord)
1 change: 1 addition & 0 deletions yamlpath/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ def delete_nodes(self, yaml_path: Union[YAMLPath, str],

if len(gathered_nodes) > 0:
self._delete_nodes(gathered_nodes)
raise NotImplementedError

def delete_gathered_nodes(self, gathered_nodes: List[NodeCoords]) -> None:
"""
Expand Down

0 comments on commit 288ea1f

Please sign in to comment.