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

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: Now code should be up to python style guide rules. 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') | tools/testing/test_configuration.py » ('J')
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):
19 """A test case defined by a .dart file."""
ngeoffray 2011/10/13 08:03:38 Maybe say a *Test.dart file. But feel free to igno
zundel 2011/10/13 11:07:44 SGTM, Done.
20
27 def __init__(self, context, path, filename, mode, arch): 21 def __init__(self, context, path, filename, mode, arch):
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 def IsNegative(self): 31 def IsNegative(self):
38 return self.GetName().endswith("NegativeTest") 32 return self.GetName().endswith('NegativeTest')
39 33
40 def GetLabel(self): 34 def GetLabel(self):
41 return "%s%s %s" % (self.mode, self.arch, '/'.join(self.path)) 35 return '%s%s %s' % (self.mode, self.arch, '/'.join(self.path))
42 36
43 def GetCommand(self): 37 def GetCommand(self):
44 return self.run_arch.GetRunCommand(); 38 return self.run_arch.GetRunCommand()
45 39
46 def GetName(self): 40 def GetName(self):
47 return self.path[-1] 41 return self.path[-1]
48 42
49 def GetPath(self): 43 def GetPath(self):
50 return os.path.dirname(self.filename) 44 return os.path.dirname(self.filename)
51 45
52 def GetSource(self): 46 def GetSource(self):
53 return file(self.filename).read() 47 return file(self.filename).read()
54 48
55 def Cleanup(self): 49 def Cleanup(self):
56 # TODO(ngeoffray): We run out of space on the build bots for these tests if 50 # TODO(ngeoffray): We run out of space on the build bots for these tests if
57 # the temp directories are not removed right after running the test. 51 # the temp directories are not removed right after running the test.
58 if not self.context.keep_temporary_files: self.run_arch.Cleanup() 52 if not self.context.keep_temporary_files:
53 self.run_arch.Cleanup()
59 54
60 55
61 class MultiTestCase(StandardTestCase): 56 class MultiTestCase(StandardTestCase):
57 """Multiple test cases defined within a single .dart file."""
ngeoffray 2011/10/13 08:03:38 ditto
zundel 2011/10/13 11:07:44 Done.
62 58
63 def __init__(self, context, path, filename, kind, mode, arch): 59 def __init__(self, context, path, filename, kind, mode, arch):
64 super(MultiTestCase, self).__init__(context, path, filename, mode, arch) 60 super(MultiTestCase, self).__init__(context, path, filename, mode, arch)
65 self.kind = kind 61 self.kind = kind
66 62
67 def GetCommand(self): 63 def GetCommand(self):
64 """Returns a commandline to execute to perform the test."""
68 return self.run_arch.GetRunCommand( 65 return self.run_arch.GetRunCommand(
69 fatal_static_type_errors=(self.kind == 'static type error')); 66 fatal_static_type_errors=(self.kind == 'static type error'))
70 67
71 def IsNegative(self): 68 def IsNegative(self):
69 """Returns True if this is a negative test (should return FAIL)."""
ngeoffray 2011/10/13 08:03:38 The comment is parenthesis is confusing, I would p
zundel 2011/10/13 11:07:44 Done.
72 if self.kind == 'compile-time error': 70 if self.kind == 'compile-time error':
73 return True 71 return True
74 if self.kind == 'runtime error': 72 if self.kind == 'runtime error':
75 return False 73 return False
76 if self.kind == 'static type error': 74 if self.kind == 'static type error':
77 return self.run_arch.HasFatalTypeErrors() 75 return self.run_arch.HasFatalTypeErrors()
78 return False 76 return False
79 77
78
80 class BrowserTestCase(StandardTestCase): 79 class BrowserTestCase(StandardTestCase):
80 """A test case that executes inside a browser (or DumpRenderTree)."""
81
81 def __init__(self, context, path, filename, 82 def __init__(self, context, path, filename,
82 fatal_static_type_errors, mode, arch): 83 fatal_static_type_errors, mode, arch):
83 super(BrowserTestCase, self).__init__(context, path, filename, mode, arch) 84 super(BrowserTestCase, self).__init__(context, path, filename, mode, arch)
84 self.fatal_static_type_errors = fatal_static_type_errors 85 self.fatal_static_type_errors = fatal_static_type_errors
85 86
86
87 def Run(self): 87 def Run(self):
88 """Optionally compiles and then runs the specified test."""
88 command = self.run_arch.GetCompileCommand(self.fatal_static_type_errors) 89 command = self.run_arch.GetCompileCommand(self.fatal_static_type_errors)
89 if command != None: 90 if command:
90 # We change the directory where dartc will be launched because 91 # We change the directory where dartc will be launched because
91 # it is not predictable on the location of the compiled file. In 92 # it is not predictable on the location of the compiled file. In
92 # case the test is a web test, we make sure the app file is not 93 # case the test is a web test, we make sure the app file is not
93 # in a subdirectory. 94 # in a subdirectory.
94 cwd = None 95 cwd = None
95 if self.run_arch.is_web_test: cwd = self.run_arch.temp_dir 96 if self.run_arch.is_web_test: cwd = self.run_arch.temp_dir
96 command = command[:1] + self.context.flags + command[1:] 97 command = command[:1] + self.context.flags + command[1:]
97 test_output = self.RunCommand(command, cwd=cwd, cleanup=False) 98 test_output = self.RunCommand(command, cwd=cwd, cleanup=False)
98 99
99 # If errors were found, fail fast and show compile errors: 100 # If errors were found, fail fast and show compile errors:
100 if test_output.output.exit_code != 0: 101 if test_output.output.exit_code != 0:
101 return test_output 102 return test_output
102 103
103 command = self.run_arch.GetRunCommand(); 104 command = self.run_arch.GetRunCommand()
104 test_output = self.RunCommand(command) 105 test_output = self.RunCommand(command)
105 # The return value of DumpRenderedTree does not indicate test failing, but 106 # The return value of DumpRenderedTree does not indicate test failing, but
106 # the output does. 107 # the output does.
107 if self.run_arch.HasFailed(test_output.output.stdout): 108 if self.run_arch.HasFailed(test_output.output.stdout):
108 test_output.output.exit_code = 1 109 test_output.output.exit_code = 1
109 110
110 return test_output 111 return test_output
111 112
112 113
113 class CompilationTestCase(test.TestCase): 114 class CompilationTestCase(test.TestCase):
114 """ Run the dartc compiler on a given top level dart file """ 115 """Run the dartc compiler on a given top level dart file."""
116
115 def __init__(self, path, context, filename, mode, arch): 117 def __init__(self, path, context, filename, mode, arch):
116 super(CompilationTestCase, self).__init__(context, path) 118 super(CompilationTestCase, self).__init__(context, path)
117 self.filename = filename 119 self.filename = filename
118 self.mode = mode 120 self.mode = mode
119 self.arch = arch 121 self.arch = arch
120 self.run_arch = architecture.GetArchitecture(self.arch, self.mode, 122 self.run_arch = architecture.GetArchitecture(self.arch, self.mode,
121 self.filename) 123 self.filename)
122 self.temp_dir = tempfile.mkdtemp(prefix='dartc-output-') 124 self.temp_dir = tempfile.mkdtemp(prefix='dartc-output-')
123 125
124 def IsNegative(self): 126 def IsNegative(self):
125 return False 127 return False
126 128
127 def GetLabel(self): 129 def GetLabel(self):
128 return "%s/%s %s" % (self.mode, self.arch, '/'.join(self.path)) 130 return '%s/%s %s' % (self.mode, self.arch, '/'.join(self.path))
129 131
130 def GetCommand(self): 132 def GetCommand(self):
131 cmd = self.context.GetDartC(self.mode, self.arch); 133 """Returns a command line to run the test."""
134 cmd = self.context.GetDartC(self.mode, self.arch)
132 cmd += self.context.flags 135 cmd += self.context.flags
133 cmd += ['-check-only', 136 cmd += ['-check-only',
134 '-fatal-type-errors', 137 '-fatal-type-errors',
135 '-Werror', 138 '-Werror',
136 '-out', self.temp_dir, 139 '-out', self.temp_dir,
137 self.filename] 140 self.filename]
138 141
139 return cmd 142 return cmd
140 143
141 def GetName(self): 144 def GetName(self):
142 return self.path[-1] 145 return self.path[-1]
OLDNEW
« no previous file with comments | « no previous file | tools/testing/test_configuration.py » ('j') | tools/testing/test_configuration.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698