From 0b234462a5ee55b5529b03f5c42c1e247cc7e2b0 Mon Sep 17 00:00:00 2001
From: Enric Tejedor Saavedra <enric.tejedor.saavedra@cern.ch>
Date: Fri, 16 Dec 2016 11:33:49 +0100
Subject: [PATCH] Ensure JSON is sorted when dumping it in the notebook.

In Python2, the dumps function of the json module always returns the
same JSON string for a given Python dictionary across different runs.
In Python3, the returned JSON changes across runs, in particular the
order in which dictionary keys are shown, which complicates the
notebook tests of the interactive neural networks. Only with a sorted
JSON we can compare the newly generated notebook with a reference notebook.
---
 bindings/pyroot/JsMVA/Factory.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/bindings/pyroot/JsMVA/Factory.py b/bindings/pyroot/JsMVA/Factory.py
index 13fda564266..2d47dc16fd7 100644
--- a/bindings/pyroot/JsMVA/Factory.py
+++ b/bindings/pyroot/JsMVA/Factory.py
@@ -152,7 +152,7 @@ def GetDeepNetworkOld(xml_file, returnObj=False):
     network["synapses"] = synapses
     if returnObj:
         return network
-    return json.dumps(network)
+    return json.dumps(network, sort_keys = True)
 
 ## Reads deep neural network weights from file and returns it in JSON format.
 # @param xml_file path to DNN weight file
@@ -196,7 +196,7 @@ def GetDeepNetwork(xml_file, returnObj=False):
     network["layers"] = layers
     if returnObj:
         return network
-    return json.dumps(network)
+    return json.dumps(network, sort_keys = True)
 
 ## Reads neural network weights from file and returns it in JSON format
 # @param xml_file path to weight file
@@ -231,7 +231,7 @@ def GetNetwork(xml_file):
             neurons[label]["weights"] = weights
         net["layer_"+str(layer.get('Index'))] = neurons
     network["layout"] = net
-    return json.dumps(network)
+    return json.dumps(network, sort_keys = True)
 
 ## Helper class for reading decision tree from XML file
 class TreeReader:
-- 
GitLab