[Piglit] [PATCH 4/9] backends: Refactor FSyncMixin
Dylan Baker
baker.dylan.c at gmail.com
Tue Sep 23 17:55:51 PDT 2014
This change will be used by the next patch
Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
framework/backends/abstract.py | 8 ++++----
framework/backends/json_.py | 8 ++++----
framework/backends/junit.py | 3 +++
3 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/framework/backends/abstract.py b/framework/backends/abstract.py
index 137a7ba..3815304 100644
--- a/framework/backends/abstract.py
+++ b/framework/backends/abstract.py
@@ -39,17 +39,17 @@ class FSyncMixin(object):
"""
def __init__(self, file_fsync=False, **options):
self._file_sync = file_fsync
- assert self._file
- def _fsync(self):
+ def _fsync(self, file_):
""" Sync the file to disk
If self._fsync is truthy this will sync self._file to disk
"""
+ file_.flush()
+
if self._file_sync:
- self._file.flush()
- os.fsync(self._file.fileno())
+ os.fsync(file_.fileno())
class Backend(object):
diff --git a/framework/backends/json_.py b/framework/backends/json_.py
index b37a7de..9273e4f 100644
--- a/framework/backends/json_.py
+++ b/framework/backends/json_.py
@@ -219,7 +219,7 @@ class JSONBackend(FSyncMixin, Backend):
self.__indent_level += 1
self.__is_collection_empty.append(True)
self._open_containers.append('dict')
- self._fsync()
+ self._fsync(self._file)
def _close_dict(self):
self.__indent_level -= 1
@@ -230,7 +230,7 @@ class JSONBackend(FSyncMixin, Backend):
self._file.write('}')
assert self._open_containers[-1] == 'dict'
self._open_containers.pop()
- self._fsync()
+ self._fsync(self._file)
def _write_dict_item(self, key, value):
# Write key.
@@ -239,7 +239,7 @@ class JSONBackend(FSyncMixin, Backend):
# Write value.
self.__write(value)
- self._fsync()
+ self._fsync(self._file)
def _write_dict_key(self, key):
# Write comma if this is not the initial item in the dict.
@@ -253,7 +253,7 @@ class JSONBackend(FSyncMixin, Backend):
self._file.write(': ')
self.__inhibit_next_indent = True
- self._fsync()
+ self._fsync(self._file)
def write_test(self, name, data):
""" Write a test into the JSON tests dictionary """
diff --git a/framework/backends/junit.py b/framework/backends/junit.py
index 9156d4f..51f55a6 100644
--- a/framework/backends/junit.py
+++ b/framework/backends/junit.py
@@ -54,10 +54,12 @@ class JUnitBackend(FSyncMixin, Backend):
'<testsuite name="piglit" tests="{}">\n'.format(
metadata['test_count']))
self._test_suffix = metadata["test_suffix"]
+ self._fsync(self._file)
def finalize(self, metadata=None):
self._file.write('</testsuite>\n')
self._file.write('</testsuites>\n')
+ self._fsync(self._file)
self._file.close()
def write_test(self, name, data):
@@ -101,3 +103,4 @@ class JUnitBackend(FSyncMixin, Backend):
self._file.write(etree.tostring(element))
self._file.write('\n')
+ self._fsync(self._file)
--
2.1.1
More information about the Piglit
mailing list