[Piglit] [PATCH 2/2] results_v0_tests.py: Test that results with no version or version 0 work

Dylan Baker baker.dylan.c at gmail.com
Wed Dec 31 11:59:03 PST 2014


This tests for the bug fixed in 8673b6e1b98

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/tests/results_v0_tests.py | 46 +++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/framework/tests/results_v0_tests.py b/framework/tests/results_v0_tests.py
index daa9fd5..ff01339 100644
--- a/framework/tests/results_v0_tests.py
+++ b/framework/tests/results_v0_tests.py
@@ -21,8 +21,10 @@
 """ Module provides tests for converting version zero results to version 1 """
 
 from __future__ import print_function, absolute_import
+import os
 import json
 import copy
+import tempfile
 
 import nose.tools as nt
 
@@ -221,3 +223,47 @@ def test_subtests_with_slash():
 def test_handle_fixed_subtests():
     """ Version 1: Correctly handle new single entry subtests correctly """
     assert 'group3/groupA/test' in RESULT.tests.iterkeys()
+
+
+def _load_with_update(data):
+    """If the file is not results.json, it will be renamed.
+
+    This ensures that the right file is removed.
+
+    """
+    try:
+        with utils.with_tempfile(json.dumps(data)) as t:
+            result = results.load_results(t)
+    except OSError as e:
+        # There is the potential that the file will be renamed. In that event
+        # remove the renamed files
+        if e.errno == 2:
+            os.unlink(os.path.join(tempfile.tempdir, 'results.json'))
+            os.unlink(os.path.join(tempfile.tempdir, 'results.json.old'))
+        else:
+            raise
+
+    return result
+
+
+def test_load_results_unversioned():
+    """results.load_results: Loads unversioned results and updates correctly.
+
+    This is just a random change to show that the update path is being hit.
+
+    """
+    result = _load_with_update(DATA)
+    nt.assert_equal(result.tests['sometest']['dmesg'], 'this\nis\ndmesg')
+
+
+def test_load_results_v0():
+    """results.load_results: Loads results v0 and updates correctly.
+
+    This is just a random change to show that the update path is being hit.
+
+    """
+    data = copy.deepcopy(DATA)
+    data['results_version'] = 0
+
+    result = _load_with_update(data)
+    nt.assert_equal(result.tests['sometest']['dmesg'], 'this\nis\ndmesg')
-- 
2.2.1



More information about the Piglit mailing list