[Piglit] [PATCH 05/19] results.py: Change JSONWriter to take a string rather than file object

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


Since not every backend wants a file type not passing one is much nicer
than passing a file. In addition, it removes code duplication between
run and resume.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/programs/run.py        | 5 ++---
 framework/results.py             | 2 +-
 framework/tests/results_tests.py | 3 +--
 3 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/framework/programs/run.py b/framework/programs/run.py
index dbcc2c6..873b252 100644
--- a/framework/programs/run.py
+++ b/framework/programs/run.py
@@ -210,9 +210,8 @@ def run(input_):
 
     # Begin json.
     result_filepath = path.join(args.results_path, 'results.json')
-    result_file = open(result_filepath, 'w')
     json_writer = framework.results.JSONWriter(
-        result_file,
+        result_filepath,
         file_fsync=opts.sync)
 
     # Create a dictionary to pass to initialize json, it needs the contents of
@@ -271,7 +270,7 @@ def resume(input_):
     opts.env['PIGLIT_PLATFORM'] = results.options['platform']
 
     results_path = path.join(args.results_path, 'results.json')
-    json_writer = framework.results.JSONWriter(open(results_path, 'w+'),
+    json_writer = framework.results.JSONWriter(results_path,
                                                file_fsync=opts.sync)
     results.options['env'] = core.collect_system_info()
     json_writer.initialize_json(results.options)
diff --git a/framework/results.py b/framework/results.py
index 5e1f06d..c24ce52 100644
--- a/framework/results.py
+++ b/framework/results.py
@@ -177,7 +177,7 @@ class JSONWriter(object):
     INDENT = 4
 
     def __init__(self, f, file_fsync=False):
-        self.file = f
+        self.file = open(f, 'w')
         self.fsync = file_fsync
         self.__indent_level = 0
         self.__inhibit_next_indent = False
diff --git a/framework/tests/results_tests.py b/framework/tests/results_tests.py
index 95e76db..75ca01f 100644
--- a/framework/tests/results_tests.py
+++ b/framework/tests/results_tests.py
@@ -22,7 +22,6 @@
 
 
 import os
-import tempfile
 import json
 import nose.tools as nt
 import framework.tests.utils as utils
@@ -62,7 +61,7 @@ def test_initialize_jsonwriter():
     arguments
 
     """
-    with tempfile.TemporaryFile() as tfile:
+    with utils.with_tempfile('') as tfile:
         func = results.JSONWriter(tfile, file_fsync=False)
         assert isinstance(func, results.JSONWriter)
 
-- 
2.1.0



More information about the Piglit mailing list