]> git.cworth.org Git - apitrace-tests/commitdiff
Better code organization.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Sat, 17 Mar 2012 14:24:29 +0000 (14:24 +0000)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Sat, 17 Mar 2012 14:24:29 +0000 (14:24 +0000)
app_driver.py
base_driver.py
tool_driver.py

index a44badea1566d4248e80ed28374359dd22710fe7..33d2d5e65dccfa09326a92ecf00c232242400eca 100755 (executable)
@@ -137,7 +137,7 @@ class TraceChecker:
 
 
 
 
 
 
-class TestCase:
+class AppDriver(Driver):
 
     cmd = None
     cwd = None
 
     cmd = None
     cwd = None
@@ -155,6 +155,7 @@ class TestCase:
     threshold_precision = 12.0
 
     def __init__(self):
     threshold_precision = 12.0
 
     def __init__(self):
+        Driver.__init__(self)
         self.stateCache = {}
     
     def runApp(self):
         self.stateCache = {}
     
     def runApp(self):
@@ -405,19 +406,8 @@ class TestCase:
         cmd += [self.trace_file]
         return popen(cmd, stdout=stdout)
 
         cmd += [self.trace_file]
         return popen(cmd, stdout=stdout)
 
-    def run(self):
-        self.runApp()
-        self.traceApp()
-        self.checkTrace()
-        self.retrace()
-
-        pass_()
-
-
-class AppMain(Main):
-
     def createOptParser(self):
     def createOptParser(self):
-        optparser = Main.createOptParser(self)
+        optparser = Driver.createOptParser(self)
 
         optparser.add_option(
             '-a', '--api', metavar='API',
 
         optparser.add_option(
             '-a', '--api', metavar='API',
@@ -434,7 +424,7 @@ class AppMain(Main):
 
         return optparser
 
 
         return optparser
 
-    def main(self):
+    def run(self):
         global options
 
         (options, args) = self.parseOptions()
         global options
 
         (options, args) = self.parseOptions()
@@ -442,17 +432,20 @@ class AppMain(Main):
         if not os.path.exists(options.results):
             os.makedirs(options.results)
 
         if not os.path.exists(options.results):
             os.makedirs(options.results)
 
-        test = TestCase()
-        test.verbose = options.verbose
+        self.verbose = options.verbose
 
 
-        test.cmd = args
-        test.cwd = options.cwd
-        test.api = options.api
-        test.ref_dump = options.ref_dump
-        test.results = options.results
+        self.cmd = args
+        self.cwd = options.cwd
+        self.api = options.api
+        self.ref_dump = options.ref_dump
+        self.results = options.results
 
 
-        test.run()
+        self.runApp()
+        self.traceApp()
+        self.checkTrace()
+        self.retrace()
 
 
+        pass_()
 
 if __name__ == '__main__':
 
 if __name__ == '__main__':
-    AppMain().main()
+    AppDriver().run()
index 51032bdab51cc9026a2990d20074c4fc23a72de8..1be143288fffd5af79245757674b0434aabd66a1 100644 (file)
@@ -124,8 +124,10 @@ def get_scripts_path():
     sys.exit(1)
 
 
     sys.exit(1)
 
 
-class Main:
-    global options
+class Driver:
+
+    def __init__(self):
+        pass
 
     def createOptParser(self):
         default_apitrace = 'apitrace'
 
     def createOptParser(self):
         default_apitrace = 'apitrace'
@@ -164,8 +166,11 @@ class Main:
 
         sys.path.insert(0, get_scripts_path())
 
 
         sys.path.insert(0, get_scripts_path())
 
+        self.options = options
+        self.args = args
+
         return options, args
 
         return options, args
 
-    def main(self):
+    def run(self):
         raise NotImplementedError
 
         raise NotImplementedError
 
index 63c10af72bcd1f22a9b02510425e53053a8ad7ed..4cc36c65bab78bf7584a947dd6c656bd03675861 100755 (executable)
@@ -74,50 +74,30 @@ class AsciiComparer:
 
 
 
 
 
 
-class TestCase:
+class ToolDriver(Driver):
 
 
-    cmd = None
-    cwd = None
-    ref_dump = None
-
-    verbose = False
-
-    def __init__(self):
-        pass
-    
     def runTool(self):
         '''Run the application standalone, skipping this test if it fails by
         some reason.'''
 
     def runTool(self):
         '''Run the application standalone, skipping this test if it fails by
         some reason.'''
 
-        if not self.cmd:
-            return
-
-        if self.ref_dump:
+        if self.options.ref_dump:
             stdout = subprocess.PIPE
         else:
             stdout = None
 
             stdout = subprocess.PIPE
         else:
             stdout = None
 
-        cmd = [options.apitrace] + self.cmd
-        p = popen(cmd, cwd=self.cwd, stdout=stdout)
+        cmd = [self.options.apitrace] + self.args
+        p = popen(cmd, cwd=options.cwd, stdout=stdout)
 
 
-        if self.ref_dump:
-            comparer = AsciiComparer(p.stdout, self.ref_dump, self.verbose)
+        if self.options.ref_dump:
+            comparer = AsciiComparer(p.stdout, self.options.ref_dump, self.options.verbose)
             comparer.compare()
 
         p.wait()
         if p.returncode != 0:
             fail('tool returned code %i' % p.returncode)
             comparer.compare()
 
         p.wait()
         if p.returncode != 0:
             fail('tool returned code %i' % p.returncode)
-
-    def run(self):
-        self.runTool()
-
-        pass_()
-
-
-class ToolMain(Main):
-
+    
     def createOptParser(self):
     def createOptParser(self):
-        optparser = Main.createOptParser(self)
+        optparser = Driver.createOptParser(self)
 
         optparser.add_option(
             '--ref-dump', metavar='PATH',
 
         optparser.add_option(
             '--ref-dump', metavar='PATH',
@@ -126,20 +106,15 @@ class ToolMain(Main):
 
         return optparser
 
 
         return optparser
 
-    def main(self):
+    def run(self):
         global options
 
         (options, args) = self.parseOptions()
 
         global options
 
         (options, args) = self.parseOptions()
 
-        test = TestCase()
-        test.verbose = options.verbose
-
-        test.cmd = args
-        test.cwd = options.cwd
-        test.ref_dump = options.ref_dump
+        self.runTool()
 
 
-        test.run()
+        pass_()
 
 
 if __name__ == '__main__':
 
 
 if __name__ == '__main__':
-    ToolMain().main()
+    ToolDriver().run()