[Piglit] [PATCH 1/7] framework tests: use grouptools for joining groups

Dylan Baker baker.dylan.c at gmail.com
Thu Mar 12 15:42:04 PDT 2015


Since the format is subject to change, it is a bad idea to not use
grouptools. Since grouptools is already well tested this should not be
problematic.

This produces no changes in the unit tests, but it does make them more
robust.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/tests/backends_tests.py   | 16 +++++++---------
 framework/tests/grouptools_tests.py | 31 ++++++++++++++++++++-----------
 framework/tests/profile_tests.py    | 29 ++++++++++++++++-------------
 framework/tests/results_tests.py    | 32 +++++++++++++++++---------------
 framework/tests/results_v0_tests.py |  4 ++++
 framework/tests/results_v1_tests.py |  2 ++
 framework/tests/results_v2_tests.py |  3 ++-
 framework/tests/results_v3_tests.py |  2 ++
 8 files changed, 70 insertions(+), 49 deletions(-)

diff --git a/framework/tests/backends_tests.py b/framework/tests/backends_tests.py
index b43302a..5b3b10c 100644
--- a/framework/tests/backends_tests.py
+++ b/framework/tests/backends_tests.py
@@ -35,9 +35,7 @@ except ImportError:
     import json
 import nose.tools as nt
 
-import framework.core as core
-import framework.results as results
-import framework.backends as backends
+from framework import core, results, backends, grouptools
 import framework.tests.utils as utils
 
 
@@ -110,7 +108,7 @@ class TestJUnitSingleTest(TestJunitNoTests):
         test = backends.JUnitBackend(cls.tdir)
         test.initialize(BACKEND_INITIAL_META)
         test.write_test(
-            'a/test/group/test1',
+            grouptools.join('a', 'test', 'group', 'test1'),
             results.TestResult({
                 'time': 1.2345,
                 'result': 'pass',
@@ -140,7 +138,7 @@ class TestJUnitMultiTest(TestJUnitSingleTest):
         test = backends.JUnitBackend(cls.tdir)
         test.initialize(BACKEND_INITIAL_META)
         test.write_test(
-            'a/test/group/test1',
+            grouptools.join('a', 'test', 'group', 'test1'),
             results.TestResult({
                 'time': 1.2345,
                 'result': 'pass',
@@ -150,7 +148,7 @@ class TestJUnitMultiTest(TestJUnitSingleTest):
             })
         )
         test.write_test(
-            'a/different/test/group/test2',
+            grouptools.join('a', 'different', 'test', 'group', 'test2'),
             results.TestResult({
                 'time': 1.2345,
                 'result': 'fail',
@@ -182,7 +180,7 @@ def test_json_initialize_metadata():
 class TestJSONTestMethod(utils.StaticDirectory):
     @classmethod
     def setup_class(cls):
-        cls.test_name = 'a/test/group/test1'
+        cls.test_name = grouptools.join('a', 'test', 'group', 'test1')
         cls.result = results.TestResult({
             'time': 1.2345,
             'result': 'pass',
@@ -217,7 +215,7 @@ class TestJSONTestMethod(utils.StaticDirectory):
 class TestJSONTestFinalize(utils.StaticDirectory):
     @classmethod
     def setup_class(cls):
-        cls.test_name = 'a/test/group/test1'
+        cls.test_name = grouptools.join('a', 'test', 'group', 'test1')
         cls.result = results.TestResult({
             'time': 1.2345,
             'result': 'pass',
@@ -257,7 +255,7 @@ def test_junit_skips_bad_tests():
         test = backends.JUnitBackend(tdir)
         test.initialize(BACKEND_INITIAL_META)
         test.write_test(
-            'a/test/group/test1',
+            grouptools.join('a', 'test', 'group', 'test1'),
             results.TestResult({
                 'time': 1.2345,
                 'result': 'pass',
diff --git a/framework/tests/grouptools_tests.py b/framework/tests/grouptools_tests.py
index 94f44af..4efe746 100644
--- a/framework/tests/grouptools_tests.py
+++ b/framework/tests/grouptools_tests.py
@@ -130,17 +130,24 @@ def generate_tests():
     This cannot test all corners of the more complicated members.
 
     """
-    # pylint: disable=line-too-long
     tests = [
-        ('testname', grouptools.testname, 'g1/g2/t1', 't1'),
-        ('groupname', grouptools.groupname, 'g1/g2/t1', 'g1/g2'),
-        ('splitname', grouptools.splitname, 'g1/g2/t1', ('g1/g2', 't1')),
-        ('commonprefix', grouptools.commonprefix, ['g1/g2/1', 'g1/g2/2'], 'g1/g2/'),
-        ('join', grouptools.join, ['g1/g2', 't1'], 'g1/g2/t1', True),
-        ('split', grouptools.split, 'g1/g2/t1', ['g1', 'g2', 't1']),
-        ('relgroup', grouptools.relgroup, ['g1/g2/g3/t1', 'g1/g2'], 'g3/t1', True)
+        ('testname', grouptools.testname, grouptools.join('g1', 'g2', 't1'),
+         't1'),
+        ('groupname', grouptools.groupname, grouptools.join('g1', 'g2', 't1'),
+         grouptools.join('g1', 'g2')),
+        ('splitname', grouptools.splitname, grouptools.join('g1', 'g2', 't1'),
+         (grouptools.join('g1', 'g2'), 't1')),
+        ('commonprefix', grouptools.commonprefix,
+         [grouptools.join('g1', 'g2', '1'), grouptools.join('g1', 'g2', '2')],
+         grouptools.join('g1', 'g2', '')),
+        ('join', grouptools.join, [grouptools.join('g1', 'g2'), 't1'],
+         grouptools.join('g1', 'g2', 't1'), True),
+        ('split', grouptools.split, grouptools.join('g1', 'g2', 't1'),
+         ['g1', 'g2', 't1']),
+        ('relgroup', grouptools.relgroup,
+         [grouptools.join('g1', 'g2', 'g3', 't1'), grouptools.join('g1', 'g2')],
+         grouptools.join('g3', 't1'), True)
     ]
-    # pylint: enable=line-too-long
 
     for args in tests:
         test_class = _GroupToolsTest(*args)
@@ -166,12 +173,14 @@ def test_split_input_empty():
 
 def test_from_path_posix():
     """grouptools.from_path: doesn't change posixpaths."""
-    nt.assert_equal(grouptools.from_path('foo/bar'), 'foo/bar')
+    nt.assert_equal(grouptools.from_path('foo/bar'),
+                    grouptools.join('foo', 'bar'))
 
 
 def test_from_path_nt():
     """grouptools.from_path: converts \\ to / in nt paths."""
-    nt.assert_equal(grouptools.from_path('foo\\bar'), 'foo/bar')
+    nt.assert_equal(grouptools.from_path('foo\\bar'),
+                    grouptools.join('foo', 'bar'))
 
 
 def test_from_path_dot():
diff --git a/framework/tests/profile_tests.py b/framework/tests/profile_tests.py
index 96337c6..74a255e 100644
--- a/framework/tests/profile_tests.py
+++ b/framework/tests/profile_tests.py
@@ -90,12 +90,15 @@ def test_testprofile_set_dmesg_false():
 def test_testprofile_update_test_list():
     """ TestProfile.update() updates TestProfile.test_list """
     profile1 = profile.TestProfile()
-    profile1.test_list['group1/test1'] = utils.Test(['test1'])
+    group1 = grouptools.join('group1', 'test1')
+    group2 = grouptools.join('group1', 'test2')
+
+    profile1.test_list[group1] = utils.Test(['test1'])
 
 
     profile2 = profile.TestProfile()
-    profile2.test_list['group1/test1'] = utils.Test(['test3'])
-    profile2.test_list['group2/test2'] = utils.Test(['test2'])
+    profile2.test_list[group1] = utils.Test(['test3'])
+    profile2.test_list[group2] = utils.Test(['test2'])
 
     profile1.update(profile2)
 
@@ -106,10 +109,10 @@ class TestPrepareTestListMatches(object):
     """Create tests for TestProfile.prepare_test_list filtering"""
     def __init__(self):
         self.data = {
-            'group1/test1': 'thingy',
-            'group1/group3/test2': 'thing',
-            'group3/test5': 'other',
-            'group4/Test9': 'is_caps',
+            grouptools.join('group1', 'test1'): 'thingy',
+            grouptools.join('group1', 'group3', 'test2'): 'thing',
+            grouptools.join('group3', 'test5'): 'other',
+            grouptools.join('group4', 'Test9'): 'is_caps',
         }
 
     def test_matches_filter_mar_1(self):
@@ -138,21 +141,21 @@ class TestPrepareTestListMatches(object):
         profile_.test_list = self.data
         profile_._prepare_test_list(env)
 
-        baseline = {'group3/test5': 'other'}
+        baseline = {grouptools.join('group3', 'test5'): 'other'}
 
         nt.assert_dict_equal(profile_.test_list, baseline)
 
     def test_matches_env_exclude(self):
         """TestProfile.prepare_test_list: 'not path in env.exclude_tests"""
         env = core.Options()
-        env.exclude_tests.add('group3/test5')
+        env.exclude_tests.add(grouptools.join('group3', 'test5'))
 
         profile_ = profile.TestProfile()
         profile_.test_list = self.data
         profile_._prepare_test_list(env)
 
         baseline = copy.deepcopy(self.data)
-        del baseline['group3/test5']
+        del baseline[grouptools.join('group3', 'test5')]
 
         nt.assert_dict_equal(profile_.test_list, baseline)
 
@@ -165,7 +168,7 @@ class TestPrepareTestListMatches(object):
         profile_._prepare_test_list(env)
 
         baseline = copy.deepcopy(self.data)
-        del baseline['group3/test5']
+        del baseline[grouptools.join('group3', 'test5')]
 
         nt.assert_dict_equal(profile_.test_list, baseline)
 
@@ -177,7 +180,7 @@ class TestPrepareTestListMatches(object):
         profile_.test_list = self.data
         profile_._prepare_test_list(env)
 
-        nt.assert_not_in('group4/Test9', profile_.test_list)
+        nt.assert_not_in(grouptools.join('group4', 'Test9'), profile_.test_list)
 
 
 @utils.no_error
@@ -251,4 +254,4 @@ def test_testprofile_groupmanager_name_str():
     with prof.group_manager(GleanTest, 'foo') as g:
         g('abc')
 
-    nt.ok_('foo/abc' in prof.test_list)
+    nt.ok_(grouptools.join('foo', 'abc') in prof.test_list)
diff --git a/framework/tests/results_tests.py b/framework/tests/results_tests.py
index 6d90990..8e1a894 100644
--- a/framework/tests/results_tests.py
+++ b/framework/tests/results_tests.py
@@ -27,11 +27,9 @@ import json
 
 import nose.tools as nt
 
-import framework.tests.utils as utils
-import framework.results as results
-import framework.status as status
-import framework.backends as backends
+from framework import results, status, backends, grouptools
 from framework.tests.backends_tests import BACKEND_INITIAL_META
+import framework.tests.utils as utils
 
 
 def check_initialize(target):
@@ -166,9 +164,9 @@ def test_resume_load():
     with utils.tempdir() as f:
         backend = backends.JSONBackend(f)
         backend.initialize(BACKEND_INITIAL_META)
-        backend.write_test("group1/test1", {'result': 'fail'})
-        backend.write_test("group1/test2", {'result': 'pass'})
-        backend.write_test("group2/test3", {'result': 'fail'})
+        backend.write_test(grouptools.join("group1', 'test1"), {'result': 'fail'})
+        backend.write_test(grouptools.join("group1', 'test2"), {'result': 'pass'})
+        backend.write_test(grouptools.join("group2', 'test3"), {'result': 'fail'})
 
         try:
             results.TestrunResult.resume(f)
@@ -181,15 +179,17 @@ def test_resume_load_valid():
     with utils.tempdir() as f:
         backend = backends.JSONBackend(f)
         backend.initialize(BACKEND_INITIAL_META)
-        backend.write_test("group1/test1", {'result': 'fail'})
-        backend.write_test("group1/test2", {'result': 'pass'})
-        backend.write_test("group2/test3", {'result': 'fail'})
+        backend.write_test(grouptools.join('group1', 'test1'), {'result': 'fail'})
+        backend.write_test(grouptools.join('group1', 'test2'), {'result': 'pass'})
+        backend.write_test(grouptools.join('group2', 'test3'), {'result': 'fail'})
 
         test = results.TestrunResult.resume(f)
 
         nt.assert_set_equal(
             set(test.tests.keys()),
-            set(['group1/test1', 'group1/test2', 'group2/test3']),
+            set([grouptools.join('group1', 'test1'),
+                 grouptools.join('group1', 'test2'),
+                 grouptools.join('group2', 'test3')]),
         )
 
 
@@ -198,9 +198,9 @@ def test_resume_load_invalid():
     with utils.tempdir() as f:
         backend = backends.JSONBackend(f)
         backend.initialize(BACKEND_INITIAL_META)
-        backend.write_test("group1/test1", {'result': 'fail'})
-        backend.write_test("group1/test2", {'result': 'pass'})
-        backend.write_test("group2/test3", {'result': 'fail'})
+        backend.write_test(grouptools.join('group1', 'test1'), {'result': 'fail'})
+        backend.write_test(grouptools.join('group1', 'test2'), {'result': 'pass'})
+        backend.write_test(grouptools.join('group2', 'test3'), {'result': 'fail'})
         with open(os.path.join(f, 'tests', 'x.json'), 'w') as w:
             w.write('foo')
 
@@ -208,5 +208,7 @@ def test_resume_load_invalid():
 
         nt.assert_set_equal(
             set(test.tests.keys()),
-            set(['group1/test1', 'group1/test2', 'group2/test3']),
+            set([grouptools.join('group1', 'test1'),
+                 grouptools.join('group1', 'test2'),
+                 grouptools.join('group2', 'test3')]),
         )
diff --git a/framework/tests/results_v0_tests.py b/framework/tests/results_v0_tests.py
index ff01339..83f3a48 100644
--- a/framework/tests/results_v0_tests.py
+++ b/framework/tests/results_v0_tests.py
@@ -31,6 +31,10 @@ import nose.tools as nt
 import framework.results as results
 import framework.tests.utils as utils
 
+# NOTE: It is very important to NOT use grouptools in this file.
+# The grouptools module changes and is updated from time to time, but this file
+# must remain static. It tests the update from one static version to another
+# static version.
 
 DATA = {}
 DATA['options'] = {
diff --git a/framework/tests/results_v1_tests.py b/framework/tests/results_v1_tests.py
index 7ce8b92..f4bfc82 100644
--- a/framework/tests/results_v1_tests.py
+++ b/framework/tests/results_v1_tests.py
@@ -31,6 +31,8 @@ import nose.tools as nt
 import framework.results as results
 import framework.tests.utils as utils
 
+# NOTE: do NOT use grouptools in this module, see v0 tests for explanation
+
 
 class TestV2Update(object):
     """Test V1 to V2 of results."""
diff --git a/framework/tests/results_v2_tests.py b/framework/tests/results_v2_tests.py
index 3367ffb..d34f2e5 100644
--- a/framework/tests/results_v2_tests.py
+++ b/framework/tests/results_v2_tests.py
@@ -22,7 +22,6 @@
 
 from __future__ import print_function, absolute_import, division
 
-import os
 try:
     import simplejson as json
 except ImportError:
@@ -32,6 +31,8 @@ import nose.tools as nt
 import framework.results as results
 import framework.tests.utils as utils
 
+# NOTE: do NOT use grouptools in this module, see v0 tests for explanation
+
 DATA = {
     "results_version": 2,
     "name": "test",
diff --git a/framework/tests/results_v3_tests.py b/framework/tests/results_v3_tests.py
index 21164b8..c04d0c6 100644
--- a/framework/tests/results_v3_tests.py
+++ b/framework/tests/results_v3_tests.py
@@ -33,6 +33,8 @@ import nose.tools as nt
 import framework.results as results
 import framework.tests.utils as utils
 
+# NOTE: do NOT use grouptools in this module, see v0 tests for explanation
+
 TEST_DATA = {
     'returncode': 0,
     'err': None,
-- 
2.3.1



More information about the Piglit mailing list