From f7982d9e9d139d3cbb562bdbb1f9c9b5005a9298 Mon Sep 17 00:00:00 2001 From: Klaus Zerwes Date: Tue, 28 Nov 2023 09:55:30 +0100 Subject: [PATCH 1/7] fix recursive call to _substmerge (issue #60) --- hiyapyco/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hiyapyco/__init__.py b/hiyapyco/__init__.py index 9d2eeb3..2c989bc 100644 --- a/hiyapyco/__init__.py +++ b/hiyapyco/__init__.py @@ -368,10 +368,10 @@ def _substmerge(self, a, b): logger.debug('deepmerge dict: set key %s' % k) a[k] = b[k] elif isinstance(b, listTypes): - logger.debug('deepmerge: dict <- list ... "%s" <- "%s"' % (a, b,)) + logger.debug('substmerge: dict <- list ... "%s" <- "%s"' % (a, b,)) for bd in b: if isinstance(bd, dict): - a = self._deepmerge(a, bd) + a = self._substmerge(a, bd) else: raise HiYaPyCoImplementationException( 'can not merge element from list of type %s to dict ' From 260fff600e57336d2c427586d7992aa8f75f2517 Mon Sep 17 00:00:00 2001 From: Klaus Zerwes Date: Tue, 28 Nov 2023 10:39:56 +0100 Subject: [PATCH 2/7] fix more substmerge related logger statements --- hiyapyco/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hiyapyco/__init__.py b/hiyapyco/__init__.py index 2c989bc..c319c9c 100644 --- a/hiyapyco/__init__.py +++ b/hiyapyco/__init__.py @@ -342,7 +342,7 @@ def _simplemerge(self, a, b): def _substmerge(self, a, b): logger.debug('>' * 30) - logger.debug('deepmerge %s and %s' % (a, b,)) + logger.debug('substmerge %s and %s' % (a, b,)) # FIXME: make None usage configurable if b is None: logger.debug('pass as b is None') @@ -352,7 +352,7 @@ def _substmerge(self, a, b): # subsititues list, don't merge them if a is None or isinstance(b, primitiveTypes) or isinstance(b, listTypes): - logger.debug('deepmerge: replace a "%s" w/ b "%s"' % (a, b,)) + logger.debug('substmerge: replace a "%s" w/ b "%s"' % (a, b,)) a = b elif isinstance(a, dict): From 2abf8af1e1c9a3dcab7f48d6f14f75fa1f62c38c Mon Sep 17 00:00:00 2001 From: Klaus Zerwes Date: Wed, 29 Nov 2023 07:30:02 +0100 Subject: [PATCH 3/7] issue #60 : replace more substmerge recursive calls --- hiyapyco/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hiyapyco/__init__.py b/hiyapyco/__init__.py index c319c9c..fa0637d 100644 --- a/hiyapyco/__init__.py +++ b/hiyapyco/__init__.py @@ -357,15 +357,15 @@ def _substmerge(self, a, b): elif isinstance(a, dict): if isinstance(b, dict): - logger.debug('deepmerge: dict ... "%s" and "%s"' % (a, b,)) + logger.debug('substmerge: dict ... "%s" and "%s"' % (a, b,)) for k in b: if k in a: logger.debug( - 'deepmerge dict: loop for key "%s": "%s" and "%s"' % (k, a[k], b[k],) + 'substmerge dict: loop for key "%s": "%s" and "%s"' % (k, a[k], b[k],) ) - a[k] = self._deepmerge(a[k], b[k]) + a[k] = self._substmerge(a[k], b[k]) else: - logger.debug('deepmerge dict: set key %s' % k) + logger.debug('substmerge dict: set key %s' % k) a[k] = b[k] elif isinstance(b, listTypes): logger.debug('substmerge: dict <- list ... "%s" <- "%s"' % (a, b,)) From a691bc6e2816adacd91bb4832faaa3ef50a66bac Mon Sep 17 00:00:00 2001 From: Klaus Zerwes Date: Wed, 29 Nov 2023 07:34:13 +0100 Subject: [PATCH 4/7] Makefile : improve test debug options --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ae15d45..dcf10d5 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,8 @@ SHELL = /bin/bash PYVERSIONS ?= $(shell py3versions -i) PYVERSIONSPATHS = $(shell for PV in $(PYVERSIONS); do which $$PV; done) +TESTLOGLEVEL ?= WARN + .PHONY: test examples testinstall all PYTHONPATH=$(shell pwd) @@ -42,7 +44,7 @@ test: for p in $(PYVERSIONS); do \ echo "python version $$p"; \ for t in test/test_*.py; do \ - $$p -t $$t; \ + $$p -t $$t -l $(TESTLOGLEVEL); \ RET=$$?; \ if [ $$RET -gt 0 ]; then break 2; fi; \ done; \ From 5d115f81281612c9175f0c1c9ed439e885dc47b9 Mon Sep 17 00:00:00 2001 From: Klaus Zerwes Date: Wed, 29 Nov 2023 07:38:28 +0100 Subject: [PATCH 5/7] issue #60 : fixed list test for substmerge --- test/test_merge.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_merge.py b/test/test_merge.py index c6215fb..df6928a 100755 --- a/test/test_merge.py +++ b/test/test_merge.py @@ -47,7 +47,7 @@ t = conf['array'] logger.info('test list val ... %s' % t) -assert t == ['base1', 'base2', 'baseext1', 'baseext2'] +assert t == ['baseext1', 'baseext2'] t = conf['hash'] logger.info('test simple dict ... %s' % t) From 0cfba1af0c3b331aad03ecefecbae27924b7aece Mon Sep 17 00:00:00 2001 From: Klaus Zerwes Date: Wed, 29 Nov 2023 08:19:16 +0100 Subject: [PATCH 6/7] issue #60 : fixed deeplist test for substmerge --- test/test_merge.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_merge.py b/test/test_merge.py index df6928a..3a7cfe6 100755 --- a/test/test_merge.py +++ b/test/test_merge.py @@ -55,7 +55,7 @@ t = conf['deeplist'] logger.info('test deeplist ... %s' % t) -assert t == [{'d1': {'d1k1': 'v1', 'd1k2': 'v2', 'd1ext': 'vext'}}, {'d2': {'d2k2': 'x2', 'd2k1': 'x1'}}, {'d32': {'a': 'A2A2', 'c': 'CCC', 'b': 'B2'}, 'd31': {'a': 'AAA', 'c': 'C', 'b': 'B'}}, {'dext1': {'d1k1ext': 'v1ext'}}] +assert t == [{'d1': {'d1ext': 'vext'}}, {'dext1': {'d1k1ext': 'v1ext'}}, {'d31': {'a': 'AAA'}, 'd32': {'a': 'A2A2', 'c': 'CCC'}}] t = conf.get('deepmap') logger.info('test deepmap ... %s' % t) From 391b00db8749db181cd7c12666e61890df5de53d Mon Sep 17 00:00:00 2001 From: Klaus Zerwes Date: Wed, 29 Nov 2023 08:28:40 +0100 Subject: [PATCH 7/7] issue #60 : fixed substmerge in logger statement --- hiyapyco/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hiyapyco/__init__.py b/hiyapyco/__init__.py index fa0637d..c77880e 100644 --- a/hiyapyco/__init__.py +++ b/hiyapyco/__init__.py @@ -383,7 +383,7 @@ def _substmerge(self, a, b): 'can not merge %s to %s (@ "%s" try to merge "%s")' % (type(b), type(a), a, b,) ) - logger.debug('end deepmerge part: return: "%s"' % a) + logger.debug('end substmerge part: return: "%s"' % a) logger.debug('<' * 30) return a