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

Side by Side Diff: tools/unittest_output.py

Issue 11000052: tools/test.py: Add support for JUnit compatible XML output (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 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
« tools/test.py ('K') | « tools/test-wrapper-gypbuild.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2008 the V8 project authors. All rights reserved.
Jakob Kummerow 2012/09/28 17:38:52 nit: 2012
2 # Redistribution and use in source and binary forms, with or without
3 # modification, are permitted provided that the following conditions are
4 # met:
5 #
6 # * Redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer.
8 # * Redistributions in binary form must reproduce the above
9 # copyright notice, this list of conditions and the following
10 # disclaimer in the documentation and/or other materials provided
11 # with the distribution.
12 # * Neither the name of Google Inc. nor the names of its
13 # contributors may be used to endorse or promote products derived
14 # from this software without specific prior written permission.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 import xml.etree.ElementTree as xml
29 import sys
30 import time
31 import threading
32 import string
33 import os
Jakob Kummerow 2012/09/28 17:38:52 nit: please sort imports alphabetically
34
Jakob Kummerow 2012/09/28 17:38:52 nit: two newlines between top-level definitions
35 def getProperTestName(name):
Jakob Kummerow 2012/09/28 17:38:52 Why do you need to extract the test's name from it
36 proper = name
37 proper = filter(lambda x: not "--testing_serialization_file" in x, proper)
38 proper = filter(lambda x: not "--test" == x, proper)
39 proper = map(lambda x: string.replace(x, os.getcwd() + "/", ""), proper)
40 proper = string.join(proper[1:], "_")
41 return proper
42
Jakob Kummerow 2012/09/28 17:38:52 nit: two newlines between top-level definitions
43 class UnitTestOutput:
44 class testCase:
45 def __init__(self, name):
46 self.root = xml.Element("testcase")
47 self.root.attrib["name"] = name
48 self.starttime = time.time()
Jakob Kummerow 2012/09/28 17:38:52 No reason to measure execution time here. It is me
49
50 def finish(self, failed, failMsg = None):
51 elapsed = time.time() - self.starttime
52 self.root.attrib["time"] = str(round(elapsed,2))
53 if failed:
54 failure = xml.Element("failure")
55 failure.text = failMsg
56 self.root.append(failure)
57
58 def getElement(self):
59 return self.root
60
61 class UnitTestLocal(threading.local):
Jakob Kummerow 2012/09/28 17:38:52 In the new test driver, the progress indicators ar
62 def __init__(self):
63 self.curtest = None
64
65 def __init__(self, testName):
66 self.root = xml.Element("testsuite")
67 self.root.attrib["name"] = testName
68 self.local = UnitTestOutput.UnitTestLocal()
69 self.local.curtest = None
70
71 def startNewTest(self, name):
72 if self.local.curtest != None:
73 self.finishCurrentTest(False)
74 self.local.curtest = self.testCase(name)
75
76 def finishCurrentTest(self, newName, failed, failMsg = None):
77 if self.local.curtest != None:
78 self.local.curtest.finish(failed, failMsg)
79 if newName:
80 name = getProperTestName(newName)
81 self.local.curtest.root.attrib["name"] = name
82 self.root.append(self.local.curtest.getElement())
83 else:
84 sys.stderr.write("Tried to finish test but no test is active!")
85 self.local.curtest = None
86
87 def finishAndWrite(self, file):
88 if self.local.curtest != None:
89 self.finishCurrentTest(False)
90 xml.ElementTree(self.root).write(file, "UTF-8")
91
OLDNEW
« tools/test.py ('K') | « tools/test-wrapper-gypbuild.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698