Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(779)

Side by Side Diff: tools/testing/test_case.py

Issue 8260004: Addresses Python style issues in test_configuration.py and test_case.py (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: After merge up Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/testing/test_configuration.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 # for details. All rights reserved. Use of this source code is governed by a 2 # for details. All rights reserved. Use of this source code is governed by a
3 # BSD-style license that can be found in the LICENSE file. 3 # BSD-style license that can be found in the LICENSE file.
4 4
5 import atexit 5 """Common TestCase subclasses used to define a single test."""
6 import fileinput 6
7 import os 7 import os
8 import test
9 import platform
10 import re
11 import sys
12 import tempfile 8 import tempfile
13 9
14 import architecture
15 import test 10 import test
16 import utils 11 from testing import architecture
17 12
18 from os.path import join, exists, basename
19
20 import utils
21 13
22 class Error(Exception): 14 class Error(Exception):
23 pass 15 pass
24 16
25 17
26 class StandardTestCase(test.TestCase): 18 class StandardTestCase(test.TestCase):
27 def __init__(self, context, path, filename, mode, arch, vm_options = []): 19 """A test case defined by a *Test.dart file."""
20
21 def __init__(self, context, path, filename, mode, arch, vm_options=None):
28 super(StandardTestCase, self).__init__(context, path) 22 super(StandardTestCase, self).__init__(context, path)
29 self.filename = filename 23 self.filename = filename
30 self.mode = mode 24 self.mode = mode
31 self.arch = arch 25 self.arch = arch
32 self.run_arch = architecture.GetArchitecture(self.arch, self.mode, 26 self.run_arch = architecture.GetArchitecture(self.arch, self.mode,
33 self.filename) 27 self.filename)
34 for flag in context.flags: 28 for flag in context.flags:
35 self.run_arch.vm_options.append(flag) 29 self.run_arch.vm_options.append(flag)
36 30
37 for flag in vm_options: 31 if vm_options:
38 self.run_arch.vm_options.append(flag) 32 for flag in vm_options:
33 self.run_arch.vm_options.append(flag)
39 34
40 def IsNegative(self): 35 def IsNegative(self):
41 return self.GetName().endswith("NegativeTest") 36 return self.GetName().endswith('NegativeTest')
42 37
43 def GetLabel(self): 38 def GetLabel(self):
44 return "%s%s %s" % (self.mode, self.arch, '/'.join(self.path)) 39 return '%s%s %s' % (self.mode, self.arch, '/'.join(self.path))
45 40
46 def GetCommand(self): 41 def GetCommand(self):
47 return self.run_arch.GetRunCommand(); 42 return self.run_arch.GetRunCommand()
48 43
49 def GetName(self): 44 def GetName(self):
50 return self.path[-1] 45 return self.path[-1]
51 46
52 def GetPath(self): 47 def GetPath(self):
53 return os.path.dirname(self.filename) 48 return os.path.dirname(self.filename)
54 49
55 def GetSource(self): 50 def GetSource(self):
56 return file(self.filename).read() 51 return file(self.filename).read()
57 52
58 def Cleanup(self): 53 def Cleanup(self):
59 # TODO(ngeoffray): We run out of space on the build bots for these tests if 54 # TODO(ngeoffray): We run out of space on the build bots for these tests if
60 # the temp directories are not removed right after running the test. 55 # the temp directories are not removed right after running the test.
61 if not self.context.keep_temporary_files: self.run_arch.Cleanup() 56 if not self.context.keep_temporary_files:
57 self.run_arch.Cleanup()
62 58
63 59
64 class MultiTestCase(StandardTestCase): 60 class MultiTestCase(StandardTestCase):
61 """Multiple test cases defined within a single *Test.dart file."""
65 62
66 def __init__(self, context, path, filename, kind, mode, arch): 63 def __init__(self, context, path, filename, kind, mode, arch):
67 super(MultiTestCase, self).__init__(context, path, filename, mode, arch) 64 super(MultiTestCase, self).__init__(context, path, filename, mode, arch)
68 self.kind = kind 65 self.kind = kind
69 66
70 def GetCommand(self): 67 def GetCommand(self):
68 """Returns a commandline to execute to perform the test."""
71 return self.run_arch.GetRunCommand( 69 return self.run_arch.GetRunCommand(
72 fatal_static_type_errors=(self.kind == 'static type error')); 70 fatal_static_type_errors=(self.kind == 'static type error'))
73 71
74 def IsNegative(self): 72 def IsNegative(self):
73 """Determine if this is a negative test. by looking at @ directives.
74
75 A negative test is considered to pas if its outcome is FAIL.
76
77 Returns:
78 True if this is a negative test.
79 """
75 if self.kind == 'compile-time error': 80 if self.kind == 'compile-time error':
76 return True 81 return True
77 if self.kind == 'runtime error': 82 if self.kind == 'runtime error':
78 return False 83 return False
79 if self.kind == 'static type error': 84 if self.kind == 'static type error':
80 return self.run_arch.HasFatalTypeErrors() 85 return self.run_arch.HasFatalTypeErrors()
81 return False 86 return False
82 87
88
83 class BrowserTestCase(StandardTestCase): 89 class BrowserTestCase(StandardTestCase):
90 """A test case that executes inside a browser (or DumpRenderTree)."""
91
84 def __init__(self, context, path, filename, 92 def __init__(self, context, path, filename,
85 fatal_static_type_errors, mode, arch): 93 fatal_static_type_errors, mode, arch):
86 super(BrowserTestCase, self).__init__(context, path, filename, mode, arch) 94 super(BrowserTestCase, self).__init__(context, path, filename, mode, arch)
87 self.fatal_static_type_errors = fatal_static_type_errors 95 self.fatal_static_type_errors = fatal_static_type_errors
88 96
89
90 def Run(self): 97 def Run(self):
98 """Optionally compiles and then runs the specified test."""
91 command = self.run_arch.GetCompileCommand(self.fatal_static_type_errors) 99 command = self.run_arch.GetCompileCommand(self.fatal_static_type_errors)
92 if command != None: 100 if command:
93 # We change the directory where dartc will be launched because 101 # We change the directory where dartc will be launched because
94 # it is not predictable on the location of the compiled file. In 102 # it is not predictable on the location of the compiled file. In
95 # case the test is a web test, we make sure the app file is not 103 # case the test is a web test, we make sure the app file is not
96 # in a subdirectory. 104 # in a subdirectory.
97 cwd = None 105 cwd = None
98 if self.run_arch.is_web_test: cwd = self.run_arch.temp_dir 106 if self.run_arch.is_web_test: cwd = self.run_arch.temp_dir
99 command = command[:1] + self.context.flags + command[1:] 107 command = command[:1] + self.context.flags + command[1:]
100 test_output = self.RunCommand(command, cwd=cwd, cleanup=False) 108 test_output = self.RunCommand(command, cwd=cwd, cleanup=False)
101 109
102 # If errors were found, fail fast and show compile errors: 110 # If errors were found, fail fast and show compile errors:
103 if test_output.output.exit_code != 0: 111 if test_output.output.exit_code != 0:
104 return test_output 112 return test_output
105 113
106 command = self.run_arch.GetRunCommand(); 114 command = self.run_arch.GetRunCommand()
107 test_output = self.RunCommand(command) 115 test_output = self.RunCommand(command)
108 # The return value of DumpRenderedTree does not indicate test failing, but 116 # The return value of DumpRenderedTree does not indicate test failing, but
109 # the output does. 117 # the output does.
110 if self.run_arch.HasFailed(test_output.output.stdout): 118 if self.run_arch.HasFailed(test_output.output.stdout):
111 test_output.output.exit_code = 1 119 test_output.output.exit_code = 1
112 120
113 return test_output 121 return test_output
114 122
115 123
116 class CompilationTestCase(test.TestCase): 124 class CompilationTestCase(test.TestCase):
117 """ Run the dartc compiler on a given top level dart file """ 125 """Run the dartc compiler on a given top level .dart file."""
126
118 def __init__(self, path, context, filename, mode, arch): 127 def __init__(self, path, context, filename, mode, arch):
119 super(CompilationTestCase, self).__init__(context, path) 128 super(CompilationTestCase, self).__init__(context, path)
120 self.filename = filename 129 self.filename = filename
121 self.mode = mode 130 self.mode = mode
122 self.arch = arch 131 self.arch = arch
123 self.run_arch = architecture.GetArchitecture(self.arch, self.mode, 132 self.run_arch = architecture.GetArchitecture(self.arch, self.mode,
124 self.filename) 133 self.filename)
125 self.temp_dir = tempfile.mkdtemp(prefix='dartc-output-') 134 self.temp_dir = tempfile.mkdtemp(prefix='dartc-output-')
126 135
127 def IsNegative(self): 136 def IsNegative(self):
128 return False 137 return False
129 138
130 def GetLabel(self): 139 def GetLabel(self):
131 return "%s/%s %s" % (self.mode, self.arch, '/'.join(self.path)) 140 return '%s/%s %s' % (self.mode, self.arch, '/'.join(self.path))
132 141
133 def GetCommand(self): 142 def GetCommand(self):
134 cmd = self.context.GetDartC(self.mode, self.arch); 143 """Returns a command line to run the test."""
144 cmd = self.context.GetDartC(self.mode, self.arch)
135 cmd += self.context.flags 145 cmd += self.context.flags
136 cmd += ['-check-only', 146 cmd += ['-check-only',
137 '-fatal-type-errors', 147 '-fatal-type-errors',
138 '-Werror', 148 '-Werror',
139 '-out', self.temp_dir, 149 '-out', self.temp_dir,
140 self.filename] 150 self.filename]
141 151
142 return cmd 152 return cmd
143 153
144 def GetName(self): 154 def GetName(self):
145 return self.path[-1] 155 return self.path[-1]
OLDNEW
« no previous file with comments | « no previous file | tools/testing/test_configuration.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698