Skip to content

Commit

Permalink
BUGFIX: Floats reported None Anchors to yaml-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
wwkimball committed Sep 30, 2020
1 parent 2185fa8 commit 74416bd
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGES
@@ -1,3 +1,10 @@
2.4.1:
Bug Fixes:
* The yaml-merge tool (and underlying Merger class) incorrectly assigned "None"
Anchors to all floating-point numbers. This preventing all merging when both
the LHS and RHS documents contained at least one floating-point number, each.
The yaml-merge command now reports version 0.0.2 to reflect this change.

2.4.0:
Enhancements:
* Added new reference command-line tool: yaml-merge. This is a very complex
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="yamlpath",
version="2.4.0",
version="2.4.1",
description="Read and change YAML/Compatible data using powerful, intuitive, command-line friendly syntax",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
48 changes: 48 additions & 0 deletions tests/test_merger_merger.py
Expand Up @@ -318,6 +318,54 @@ def test_merge_deep_hash(
and (open(output_file,'r').read() == open(merged_yaml,'r').read())
)

def test_merge_with_defaults_array_of_floats(
self, quiet_logger, tmp_path, tmp_path_factory
):
lhs_yaml_file = create_temp_yaml_file(tmp_path_factory, """---
- 1.1
- 2.2
""")
rhs_yaml_file = create_temp_yaml_file(tmp_path_factory, """---
- 2.2
- 3.3
""")
merged_yaml = create_temp_yaml_file(tmp_path_factory, """---
- 1.1
- 2.2
- 2.2
- 3.3
""")

output_dir = tmp_path / "test_merge_with_defaults_simple_array"
output_dir.mkdir()
output_file = output_dir / "output.yaml"

lhs_yaml = get_yaml_editor()
rhs_yaml = get_yaml_editor()
lhs_data = get_yaml_data(lhs_yaml, quiet_logger, lhs_yaml_file)
rhs_data = get_yaml_data(rhs_yaml, quiet_logger, rhs_yaml_file)

args = SimpleNamespace()
mc = MergerConfig(quiet_logger, args)
merger = Merger(quiet_logger, lhs_data, mc)
merger.merge_with(rhs_data)

with open(output_file, 'w') as yaml_dump:
lhs_yaml.dump(merger.data, yaml_dump)

# DEBUG:
# with open(output_file, 'r') as output_fnd, open(merged_yaml, 'r') as merged_fnd:
# print("Expected:")
# print(merged_fnd.read())
# print("Got:")
# print(output_fnd.read())

assert (
(os.path.getsize(output_file) == os.path.getsize(merged_yaml))
and (open(output_file,'r').read() == open(merged_yaml,'r').read())
)


def test_merge_with_defaults_simple_array(
self, quiet_logger, tmp_path, tmp_path_factory
):
Expand Down
2 changes: 1 addition & 1 deletion yamlpath/commands/yaml_merge.py
Expand Up @@ -25,7 +25,7 @@
from yamlpath.wrappers import ConsolePrinter

# Implied Constants
MY_VERSION = "0.0.1"
MY_VERSION = "0.0.2"

def processcli():
"""Process command-line arguments."""
Expand Down
2 changes: 1 addition & 1 deletion yamlpath/merger/merger.py
Expand Up @@ -537,7 +537,7 @@ def scan_for_anchors(cls, dom: Any, anchors: Dict[str, Any]):
for ele in dom:
Merger.scan_for_anchors(ele, anchors)

elif hasattr(dom, "anchor"):
elif hasattr(dom, "anchor") and dom.anchor.value is not None:
anchors[dom.anchor.value] = dom

@classmethod
Expand Down

0 comments on commit 74416bd

Please sign in to comment.