From 265349a75f3f3208647538a3464fea8da22e47e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= Date: Thu, 4 Oct 2018 08:48:59 +0200 Subject: [PATCH] tree: Sort TreeEnvironment on fingerprint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The fingerprint must be static across executions, but TreeEnvironment is simple unsorted dictionary. Let's sort it on demand (usually only for fingerprint). Signed-off-by: Lukáš Doktor --- avocado/core/tree.py | 27 ++++++++++++++++--- .../tests/test_multiplex.py | 2 +- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/avocado/core/tree.py b/avocado/core/tree.py index 1eed57d0..f0d16950 100644 --- a/avocado/core/tree.py +++ b/avocado/core/tree.py @@ -84,12 +84,31 @@ class TreeEnvironment(dict): return cpy def __str__(self): + """ + String representation using __str__ on items to improve readability + """ + return self.to_text(False) + + def to_text(self, sort=False): + """ + Human readable representation + + :param sort: Sorted to provide stable output + :rtype: str + """ + def _iteritems_sorted(dictionary): + return sorted(iteritems(dictionary)) + # Use __str__ instead of __repr__ to improve readability if self: - _values = ["%s: %s" % _ for _ in iteritems(self)] + if sort: + _iteritems = _iteritems_sorted + else: + _iteritems = iteritems + _values = ["%s: %s" % _ for _ in _iteritems(self)] values = "{%s}" % ", ".join(_values) _origin = ["%s: %s" % (key, node.path) - for key, node in iteritems(self.origin)] + for key, node in _iteritems(self.origin)] origin = "{%s}" % ", ".join(_origin) else: values = "{}" @@ -133,7 +152,7 @@ class TreeNodeEnvOnly(object): return True def fingerprint(self): - return "%s%s" % (self.path, self.environment) + return "%s%s" % (self.path, self.environment.to_text(True)) def get_environment(self): return self.environment @@ -225,7 +244,7 @@ class TreeNode(object): """ Reports string which represents the value of this node. """ - return "%s%s" % (self.path, self.environment) + return "%s%s" % (self.path, self.environment.to_text(True)) def add_child(self, node): """ diff --git a/optional_plugins/varianter_yaml_to_mux/tests/test_multiplex.py b/optional_plugins/varianter_yaml_to_mux/tests/test_multiplex.py index 0fbd085e..5fc45581 100644 --- a/optional_plugins/varianter_yaml_to_mux/tests/test_multiplex.py +++ b/optional_plugins/varianter_yaml_to_mux/tests/test_multiplex.py @@ -14,7 +14,7 @@ basedir = os.path.abspath(basedir) AVOCADO = os.environ.get("UNITTEST_AVOCADO_CMD", "./scripts/avocado") DEBUG_OUT = b""" -Variant mint-debug-amd-virtio-a9d2: amd@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-environment.yaml, virtio@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-environment.yaml, mint@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-environment.yaml, debug@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-environment.yaml +Variant mint-debug-amd-virtio-022a: amd@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-environment.yaml, virtio@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-environment.yaml, mint@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-environment.yaml, debug@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-environment.yaml /distro/mint:init => systemv@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-environment.yaml:/distro/mint /env/debug:opt_CFLAGS => -O0 -g@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-environment.yaml:/env/debug /hw/cpu/amd:cpu_CFLAGS => -march=athlon64@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-environment.yaml:/hw/cpu/amd -- GitLab