[Piglit] [PATCH 01/24] framework: fix bug in Test class

Dylan Baker baker.dylan.c at gmail.com
Mon Jan 5 13:50:22 PST 2015


This adds a test and a fix for a bug in the way the Test class is
implemented. Currently Test stores the value passed to it for test
arguments, and mutates these. Now, since most tests currently use a
string which is an immutable object (changes are actually
re-assignment), this hasn't been a problem, but later in this series
this will cause subtle problems.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/test/base.py        |  3 ++-
 framework/tests/base_tests.py | 30 ++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/framework/test/base.py b/framework/test/base.py
index 851f5f8..d92d4c8 100644
--- a/framework/test/base.py
+++ b/framework/test/base.py
@@ -35,6 +35,7 @@ import threading
 import signal
 import itertools
 import abc
+import copy
 
 from framework.core import Options
 from framework.results import TestResult
@@ -124,7 +125,7 @@ class Test(object):
     def __init__(self, command, run_concurrent=False):
         self._command = None
         self.run_concurrent = run_concurrent
-        self.command = command
+        self._command = copy.copy(command)
         self.env = {}
         self.result = TestResult({'result': 'fail'})
         self.cwd = None
diff --git a/framework/tests/base_tests.py b/framework/tests/base_tests.py
index c22e1ac..c800634 100644
--- a/framework/tests/base_tests.py
+++ b/framework/tests/base_tests.py
@@ -125,3 +125,33 @@ def test_run_command_early():
 
     test = Test_('foo')
     test.run()
+
+
+ at nt.raises(AssertionError)
+def test_no_string():
+    TestTest('foo')
+
+
+def test_mutation():
+    """Test.command does not mutate the value it was provided
+
+    There is a very subtle bug in all.py that causes the key values to be
+    changed before they are assigned in some cases. This is because the right
+    side of an assignment is evalated before the left side, so
+
+    >>> profile = {}
+    >>> args = ['a', 'b']
+    >>> profile[' '.join(args)] = PiglitGLTest(args)
+    >>> profile.keys()
+    ['bin/a b']
+
+    """
+    class _Test(TestTest):
+        def __init__(self, *args, **kwargs):
+            super(_Test, self).__init__(*args, **kwargs)
+            self._command[0] = 'bin/' + self._command[0]
+
+    args = ['a', 'b']
+    _Test(args)
+
+    nt.assert_list_equal(args, ['a', 'b'])
-- 
2.2.1



More information about the Piglit mailing list