[Piglit] [PATCH 28/42] status_tests.py: update some tests to more current standards

Dylan Baker baker.dylan.c at gmail.com
Wed Apr 22 15:10:17 PDT 2015


Use more utils functions, fold helpers into the test they are used in,
etc.

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

diff --git a/framework/tests/status_tests.py b/framework/tests/status_tests.py
index 52ad134..1a9c948 100644
--- a/framework/tests/status_tests.py
+++ b/framework/tests/status_tests.py
@@ -52,16 +52,16 @@ FIXES = list(itertools.combinations(reversed(STATUSES), 2)) + \
 NO_OPS = ('skip', 'notrun')
 
 
+ at utils.no_error
 def initialize_status():
     """ status.Status inializes """
-    test = status.Status('test', 1)
-    assert test
+    status.Status('test', 1)
 
 
+ at utils.no_error
 def initialize_nochangestatus():
     """ NoChangeStatus initializes """
-    nc = status.NoChangeStatus('test')
-    assert nc
+    status.NoChangeStatus('test')
 
 
 def compare_status_nochangestatus():
@@ -69,18 +69,16 @@ def compare_status_nochangestatus():
     status.CRASH < status.PASS
 
 
-def check_lookup(stat):
-    """ Lookup a status """
-    stt = status.status_lookup(stat)
-    assert stt
-
-
 @utils.nose_generator
 def test_gen_lookup():
     """ Generator that attempts to do a lookup on all statuses """
+    @utils.no_error
+    def test(status_):
+        status.status_lookup(status_)
+
     for stat in STATUSES + ['skip', 'notrun']:
-        check_lookup.description = "Lookup: {}".format(stat)
-        yield check_lookup, stat
+        test.description = "Lookup: {}".format(stat)
+        yield test, stat
 
 
 @nt.raises(status.StatusException)
@@ -97,24 +95,13 @@ def test_status_in():
     assert stat in slist
 
 
-def is_regression(new, old):
-    """ Test that old -> new is a regression """
-    assert status.status_lookup(new) < status.status_lookup(old)
-
-
-def is_fix(new, old):
-    """ Test that new -> old is a fix """
-    assert status.status_lookup(new) > status.status_lookup(old)
-
-
-def is_not_equivalent(new, old):
-    """ Test that new != old """
-    assert status.status_lookup(new) != status.status_lookup(old)
-
-
 @utils.nose_generator
 def test_is_regression():
     """ Generate all tests for regressions """
+    def is_regression(new, old):
+        """ Test that old -> new is a regression """
+        assert status.status_lookup(new) < status.status_lookup(old)
+
     for new, old in REGRESSIONS:
         is_regression.description = ("Test that {0} -> {1} is a "
                                      "regression".format(old, new))
@@ -124,6 +111,10 @@ def test_is_regression():
 @utils.nose_generator
 def test_is_fix():
     """ Generates all tests for fixes """
+    def is_fix(new, old):
+        """ Test that new -> old is a fix """
+        assert status.status_lookup(new) > status.status_lookup(old)
+
     for new, old in FIXES:
         is_fix.description = ("Test that {0} -> {1} is a "
                               "fix".format(new, old))
@@ -133,31 +124,34 @@ def test_is_fix():
 @utils.nose_generator
 def test_is_change():
     """ Test that status -> !status is a change """
+    def is_not_equivalent(new, old):
+        """ Test that new != old """
+        assert status.status_lookup(new) != status.status_lookup(old)
+
     for new, old in itertools.permutations(STATUSES, 2):
         is_not_equivalent.description = ("Test that {0} -> {1} is a "
                                          "change".format(new, old))
         yield is_not_equivalent, new, old
 
 
-def check_not_change(new, old):
-    """ Check that a status doesn't count as a change 
-
-    This checks that new < old and old < new do not return true. This is meant
-    for checking skip and notrun, which we don't want to show up as regressions
-    and fixes, but to go in their own special catagories.
-
-    """
-    nt.assert_false(new < old,
-                    msg="{new} -> {old}, is a change "
-                        "but shouldn't be".format(**locals()))
-    nt.assert_false(new > old,
-                    msg="{new} <- {old}, is a change "
-                        "but shouldn't be".format(**locals()))
-
-
 @utils.nose_generator
 def test_not_change():
     """ Skip and NotRun should not count as changes """
+    def check_not_change(new, old):
+        """ Check that a status doesn't count as a change 
+
+        This checks that new < old and old < new do not return true. This is meant
+        for checking skip and notrun, which we don't want to show up as regressions
+        and fixes, but to go in their own special catagories.
+
+        """
+        nt.assert_false(new < old,
+                        msg="{new} -> {old}, is a change "
+                            "but shouldn't be".format(**locals()))
+        nt.assert_false(new > old,
+                        msg="{new} <- {old}, is a change "
+                            "but shouldn't be".format(**locals()))
+
     for nochange, stat in itertools.permutations(NO_OPS, 2):
         check_not_change.description = \
             "{0} -> {1} should not be a change".format(nochange, stat)
@@ -168,6 +162,18 @@ def test_not_change():
 @utils.nose_generator
 def test_max_statuses():
     """ Verify that max() works between skip and non-skip statuses """
+    def _max_nochange_stat(nochange, stat):
+        """ max(nochange, stat) should = stat """
+        nt.assert_equal(
+            stat, max(nochange, stat),
+            msg="max({nochange}, {stat}) = {stat}".format(**locals()))
+
+    def _max_stat_nochange(nochange, stat):
+        """ max(stat, nochange) should = stat """
+        nt.assert_equal(
+            stat, max(stat, nochange),
+            msg="max({stat}, {nochange}) = {stat}".format(**locals()))
+
     for nochange, stat in itertools.product(NO_OPS, STATUSES):
         nochange = status.status_lookup(nochange)
         stat = status.status_lookup(stat)
@@ -180,20 +186,6 @@ def test_max_statuses():
         yield _max_stat_nochange, nochange, stat
 
 
-def _max_nochange_stat(nochange, stat):
-    """ max(nochange, stat) should = stat """
-    nt.assert_equal(
-        stat, max(nochange, stat),
-        msg="max({nochange}, {stat}) = {stat}".format(**locals()))
-
-
-def _max_stat_nochange(nochange, stat):
-    """ max(stat, nochange) should = stat """
-    nt.assert_equal(
-        stat, max(stat, nochange),
-        msg="max({stat}, {nochange}) = {stat}".format(**locals()))
-
-
 def check_operator(obj, op, result):
     """ Test that the result of running an operator on an object is expected
 
-- 
2.3.5



More information about the Piglit mailing list