[Piglit] [PATCH 02/19] python: Don't call methods that are not equivalent to Backend API externally

Dylan Baker baker.dylan.c at gmail.com
Thu Aug 28 15:35:30 PDT 2014


This patch removes external calls to JSONWriter methods that are not
part of the Backend API (or closely equivalent), since those methods
will be changed from public to protected.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/programs/run.py | 14 +-------------
 framework/results.py      | 19 ++++++++++++++++---
 2 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/framework/programs/run.py b/framework/programs/run.py
index 34d1a8d..0664f02 100644
--- a/framework/programs/run.py
+++ b/framework/programs/run.py
@@ -223,9 +223,6 @@ def run(input_):
     json_writer.initialize_json(options, results.name,
                                 core.collect_system_info())
 
-    json_writer.write_dict_key('tests')
-    json_writer.open_dict()
-
     profile = framework.profile.merge_test_profiles(args.test_profile)
     profile.results_dir = args.results_path
 
@@ -236,13 +233,8 @@ def run(input_):
     profile.run(opts, json_writer)
     time_end = time.time()
 
-    json_writer.close_dict()
-
     results.time_elapsed = time_end - time_start
-    json_writer.write_dict_item('time_elapsed', results.time_elapsed)
-
-    # End json.
-    json_writer.close_json()
+    json_writer.close_json({'time_elapsed': results.time_elapsed})
 
     print('Thank you for running Piglit!\n'
           'Results have been written to ' + result_filepath)
@@ -281,9 +273,6 @@ def resume(input_):
     json_writer.initialize_json(results.options, results.name,
                                 core.collect_system_info())
 
-    json_writer.write_dict_key('tests')
-    json_writer.open_dict()
-
     for key, value in results.tests.iteritems():
         json_writer.write_dict_item(key, value)
         opts.exclude_tests.add(key)
@@ -296,7 +285,6 @@ def resume(input_):
     # This is resumed, don't bother with time since it wont be accurate anyway
     profile.run(opts, json_writer)
 
-    json_writer.close_dict()
     json_writer.close_json()
 
     print("Thank you for running Piglit!\n"
diff --git a/framework/results.py b/framework/results.py
index 9b00cf5..490883b 100644
--- a/framework/results.py
+++ b/framework/results.py
@@ -235,18 +235,31 @@ class JSONWriter(object):
         for key, value in env.iteritems():
             self.write_dict_item(key, value)
 
-    def close_json(self):
+        # Open the tests dictinoary so that tests can be written
+        self.write_dict_key('tests')
+        self.open_dict()
+
+    def close_json(self, metadata=None):
         """ End json serialization and cleanup
 
         This method is called after all of tests are written, it closes any
         containers that are still open and closes the file
 
         """
+        # Close the tests dictionary
         self.close_dict()
-        # Parens make this evaluate differently?
+
+        # Write closing metadata
+        if metadata:
+            for key, value in metadata.iteritems():
+                self.write_dict_item(key, value)
+
+        # Close the root dictionary object
+        self.close_dict()
+
+        # Close the file.
         assert self._open_containers == [], \
             "containers stack: {0}".format(self._open_containers)
-
         self.file.close()
 
     @synchronized_self
-- 
2.1.0



More information about the Piglit mailing list