From 6ec2b112d5fc304ef62e1fd60dde6067b90f88bd Mon Sep 17 00:00:00 2001 From: William Kimball <30981667+wwkimball@users.noreply.github.com> Date: Sat, 10 Apr 2021 16:28:52 -0500 Subject: [PATCH] Code quality updates for new folded string handler --- tests/test_wrappers_consoleprinter.py | 12 +++++++++++- yamlpath/common/nodes.py | 2 +- yamlpath/wrappers/consoleprinter.py | 3 +-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/test_wrappers_consoleprinter.py b/tests/test_wrappers_consoleprinter.py index 0fea10d0..e6590ffc 100644 --- a/tests/test_wrappers_consoleprinter.py +++ b/tests/test_wrappers_consoleprinter.py @@ -3,7 +3,7 @@ from types import SimpleNamespace from ruamel.yaml.comments import CommentedMap, CommentedSeq, TaggedScalar -from ruamel.yaml.scalarstring import PlainScalarString +from ruamel.yaml.scalarstring import PlainScalarString, FoldedScalarString from yamlpath.wrappers import NodeCoords from yamlpath.wrappers import ConsolePrinter @@ -57,6 +57,10 @@ def test_debug_noisy(self, capsys): logger = ConsolePrinter(args) anchoredkey = PlainScalarString("TestKey", anchor="KeyAnchor") anchoredval = PlainScalarString("TestVal", anchor="Anchor") + foldedstr = "123456789 123456789 123456789" + foldedstrfolds = [10, 20] + foldedval = FoldedScalarString(foldedstr) + foldedval.fold_pos = foldedstrfolds logger.debug(anchoredval) console = capsys.readouterr() @@ -170,6 +174,12 @@ def test_debug_noisy(self, capsys): "DEBUG: test_debug_noisy: (parentref)key", ]) + "\n" == console.out + logger.debug(foldedval) + console = capsys.readouterr() + assert "\n".join([ + "DEBUG: {},folded@{}".format(foldedstr, foldedstrfolds) + ]) + def test_debug_quiet(self, capsys): args = SimpleNamespace(verbose=False, quiet=True, debug=True) logger = ConsolePrinter(args) diff --git a/yamlpath/common/nodes.py b/yamlpath/common/nodes.py index b569637c..637283ef 100644 --- a/yamlpath/common/nodes.py +++ b/yamlpath/common/nodes.py @@ -106,7 +106,7 @@ def make_new_node( new_node = new_type(new_value) if preserve_folds: - new_node.fold_pos = preserve_folds + new_node.fold_pos = preserve_folds # type: ignore elif valform == YAMLValueFormats.LITERAL: new_type = LiteralScalarString diff --git a/yamlpath/wrappers/consoleprinter.py b/yamlpath/wrappers/consoleprinter.py index 027039eb..55e9151b 100644 --- a/yamlpath/wrappers/consoleprinter.py +++ b/yamlpath/wrappers/consoleprinter.py @@ -22,7 +22,6 @@ CommentedSet, TaggedScalar ) -from ruamel.yaml.scalarstring import FoldedScalarString from yamlpath.wrappers.nodecoords import NodeCoords @@ -274,7 +273,7 @@ def _debug_scalar(data: Any, **kwargs) -> str: dtype = "{}({})".format(dtype, type(data.value)) # Report fold points, if present - if isinstance(data, FoldedScalarString) and hasattr(data, 'fold_pos'): + if hasattr(data, "fold_pos"): dtype += ",folded@{}".format(data.fold_pos) print_prefix += anchor_prefix