Move the re.compile into the core.Enivironment constructor, which
reduces code duplication. It also allows us to pass environment data on
initilization of the object, rather that having edit it's attributes
individually.

Signed-off-by: Dylan Baker <baker.dyla...@gmail.com>
---
 framework/core.py        | 26 +++++++++++++++++++-------
 piglit-print-commands.py | 13 +++++--------
 piglit-run.py            | 44 ++++++++++++++++----------------------------
 3 files changed, 40 insertions(+), 43 deletions(-)

diff --git a/framework/core.py b/framework/core.py
index 645598f..3856ddf 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -371,14 +371,26 @@ class TestrunResult:
 #############################################################################
 
 class Environment:
-       def __init__(self):
-               # If disabled, runs all tests serially from the main thread.
-               self.concurrent = True
-               self.execute = True
-               self.filter = []
+       def __init__(self, concurrent=True, execute=True, include_filter=[],
+                       exclude_filter=[], valgrind=False):
+               self.concurrent     = concurrent
+               self.execute        = execute
+               self.filter         = []
                self.exclude_filter = []
-               self.exclude_tests = set()
-               self.valgrind = False
+               self.exclude_tests  = set()
+               self.valgrind       = valgrind
+
+               """
+               The filter lists that are read in should be a list of string 
objects,
+               however, the filters need to be a list or regex object.
+
+               This code uses re.compile to rebuild the lists and set 
self.filter
+               """
+               for each in include_filter:
+                       self.filter.append(re.compile(each))
+               for each in exclude_filter:
+                       self.exclude_filter.append(re.compile(each))
+
 
        def run(self, command):
                try:
diff --git a/piglit-print-commands.py b/piglit-print-commands.py
index d4a2a52..0b55282 100755
--- a/piglit-print-commands.py
+++ b/piglit-print-commands.py
@@ -24,7 +24,6 @@
 
 import argparse
 import os.path as path
-import re
 import sys, os
 import time
 import traceback
@@ -58,13 +57,11 @@ def main():
 
        args = parser.parse_args()
 
-       env = core.Environment()
-
-       # Append includes and excludes to env
-       for each in args.include_tests:
-               env.filter.append(re.compile(each))
-       for each in args.exclude_tests:
-               env.exclude_filter.append(re.compile(each))
+       # Set the environment, pass in the included and excluded tests
+       env = core.Environment(
+                       exclude_filter=args.exclude_tests,
+                       include_filter=args.include_tests,
+                       )
 
        # Change to the piglit's path
        piglit_dir = path.dirname(path.realpath(sys.argv[0]))
diff --git a/piglit-run.py b/piglit-run.py
index 57997c5..f323244 100755
--- a/piglit-run.py
+++ b/piglit-run.py
@@ -24,7 +24,6 @@
 
 import argparse
 import os.path as path
-import re
 import sys, os
 import time
 import traceback
@@ -39,11 +38,8 @@ from framework.threads import synchronized_self
 #############################################################################
 
 def main():
-       env = core.Environment()
-
        parser = argparse.ArgumentParser(sys.argv)
 
-
        # Either require that a name for the test is passed or that
        # resume is requested
        excGroup1 = parser.add_mutually_exclusive_group()
@@ -55,8 +51,10 @@ def main():
                        action  = "store_true",
                        help    = "Resume an interupted test run")
 
+       # Setting the --dry-run flag is equivalent to env.execute=false
        parser.add_argument("-d", "--dry-run",
-                       action  = "store_true",
+                       action  = "store_false",
+                       dest    = "execute",
                        help    = "Do not execute the tests")
        parser.add_argument("-t", "--include-tests",
                        default = [],
@@ -68,8 +66,10 @@ def main():
                        action  = "append",
                        metavar = "<regex>",
                        help    = "Exclude matching tests (can be used more 
than once)")
+       # setting --no-concurrency is equivalent to concurrency=false
        parser.add_argument("--no-concurrency",
                        action  = "store_true",
+                       dest    = "concurrency",
                        help    = "Disable concurrent test runs")
        parser.add_argument("-p", "--platform",
                        choices = ["glx", "x11_egl", "wayland", "gbm"],
@@ -90,18 +90,6 @@ def main():
        if args.platform is not None:
                os.environ['PIGLIT_PLATFORM'] = args.platform
 
-       # Set dry-run
-       if args.dry_run is True:
-               env.execute = False
-
-       # Set valgrind
-       if args.valgrind is True:
-               env.valgrind = True
-
-       # Turn concurency off if requested
-       if args.no_concurrency is True:
-               env.concurrent = False
-
        # If resume is requested attempt to load the results file
        # in the specified path
        if args.resume is True:
@@ -110,23 +98,23 @@ def main():
                # Load settings from the old results JSON
                old_results = core.loadTestResults(resultsDir)
                profileFilename = old_results.options['profile']
-               for value in old_results.options['filter']:
-                       test_filter.append(value)
-                       env.filter.append(re.compile(value))
-               for value in old_results.options['exclude_filter']:
-                       exclude_filter.append(value)
-                       env.exclude_filter.append(re.compile(value))
+
+               # Changing the args to the old args allows us to set them
+               # all in one places down the way
+               args.exclude_tests = old_results.options['exclude_filter']
+               args.include_tests = old_results.options['filter']
 
        # Otherwise parse additional settings from the command line
        else:
                profileFilename = args.testFile
                resultsDir = args.resultsPath
 
-               # Set the excluded and included tests regex
-               for each in args.include_tests:
-                       env.filter.append(re.compile(each))
-               for each in args.exclude_tests:
-                       env.exclude_filter.append(re.compile(each))
+       # Pass arguments into Environment
+       env = core.Environment(concurrent=args.concurrency,
+                       exclude_filter=args.exclude_tests,
+                       include_filter=args.include_tests,
+                       execute=args.execute,
+                       valgrind=args.valgrind)
 
        # Change working directory to the root of the piglit directory
        piglit_dir = path.dirname(path.realpath(sys.argv[0]))
-- 
1.8.1.2

_______________________________________________
Piglit mailing list
Piglit@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to