[Piglit] [PATCH 06/19] results.py: Merge initialize_json into constructor

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


This moves the Initial metadata write into the constructor, like Backend
expects.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/programs/run.py        | 18 +++++++++---------
 framework/results.py             |  7 +++++--
 framework/tests/results_tests.py |  8 +++++++-
 3 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/framework/programs/run.py b/framework/programs/run.py
index 873b252..c7aa789 100644
--- a/framework/programs/run.py
+++ b/framework/programs/run.py
@@ -208,12 +208,6 @@ def run(input_):
     else:
         results.name = path.basename(args.results_path)
 
-    # Begin json.
-    result_filepath = path.join(args.results_path, 'results.json')
-    json_writer = framework.results.JSONWriter(
-        result_filepath,
-        file_fsync=opts.sync)
-
     # Create a dictionary to pass to initialize json, it needs the contents of
     # the env dictionary and profile and platform information
     options = {'profile': args.test_profile}
@@ -223,7 +217,13 @@ def run(input_):
         options['platform'] = args.platform
     options['name'] = results.name
     options['env'] = core.collect_system_info()
-    json_writer.initialize_json(options)
+
+    # Begin json.
+    result_filepath = path.join(args.results_path, 'results.json')
+    json_writer = framework.results.JSONWriter(
+        result_filepath,
+        options,
+        file_fsync=opts.sync)
 
     profile = framework.profile.merge_test_profiles(args.test_profile)
     profile.results_dir = args.results_path
@@ -269,11 +269,11 @@ def resume(input_):
 
     opts.env['PIGLIT_PLATFORM'] = results.options['platform']
 
+    results.options['env'] = core.collect_system_info()
     results_path = path.join(args.results_path, 'results.json')
     json_writer = framework.results.JSONWriter(results_path,
+                                               results.options,
                                                file_fsync=opts.sync)
-    results.options['env'] = core.collect_system_info()
-    json_writer.initialize_json(results.options)
 
     for key, value in results.tests.iteritems():
         json_writer.write_dict_item(key, value)
diff --git a/framework/results.py b/framework/results.py
index c24ce52..0b69f9d 100644
--- a/framework/results.py
+++ b/framework/results.py
@@ -176,7 +176,7 @@ class JSONWriter(object):
 
     INDENT = 4
 
-    def __init__(self, f, file_fsync=False):
+    def __init__(self, f, metadata, file_fsync=False):
         self.file = open(f, 'w')
         self.fsync = file_fsync
         self.__indent_level = 0
@@ -207,7 +207,10 @@ class JSONWriter(object):
         # is popped and written into the json
         self._open_containers = []
 
-    def initialize_json(self, metadata):
+        # Write initial metadata into the backend store
+        self._initialize(metadata)
+
+    def _initialize(self, metadata):
         """ Write boilerplate json code
 
         This writes all of the json except the actual tests.
diff --git a/framework/tests/results_tests.py b/framework/tests/results_tests.py
index 75ca01f..778882c 100644
--- a/framework/tests/results_tests.py
+++ b/framework/tests/results_tests.py
@@ -29,6 +29,12 @@ import framework.results as results
 import framework.status as status
 
 
+BACKEND_INITIAL_META = {
+    'name': 'name',
+    'env': {},
+}
+
+
 def check_initialize(target):
     """ Check that a class initializes without error """
     func = target()
@@ -62,7 +68,7 @@ def test_initialize_jsonwriter():
 
     """
     with utils.with_tempfile('') as tfile:
-        func = results.JSONWriter(tfile, file_fsync=False)
+        func = results.JSONWriter(tfile, BACKEND_INITIAL_META)
         assert isinstance(func, results.JSONWriter)
 
 
-- 
2.1.0



More information about the Piglit mailing list