1 #-------------------------------------------------------------------------
2 # drawElements Quality Program utilities
3 # --------------------------------------
5 # Copyright 2015 The Android Open Source Project
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
19 #-------------------------------------------------------------------------
23 from xml.dom.minidom import Document
26 def __init__(self, casePath, description, caseType):
27 self.casePath = casePath
28 self.description = description
29 self.caseType = caseType
32 def findAllMatches(haystack, needle):
36 ndx = haystack.find(needle, ndx+1)
42 def createAncestors(casePath):
44 for dotNdx in findAllMatches(casePath, "."):
45 ancestorPath = casePath[:dotNdx]
46 if ancestorPath not in caseNameHash:
47 case = TestCase(ancestorPath, "Test Group", "TestGroup")
48 parentCase.children.append(case)
49 caseNameHash[ancestorPath] = case
51 parentCase = caseNameHash[ancestorPath]
54 def exportCase (doc, parent, testCase):
55 #print testCase.name, testCase.caseType
56 element = doc.createElement("TestCase")
57 element.setAttribute("Name", testCase.casePath.rsplit(".", 2)[-1])
58 element.setAttribute("Description", testCase.description)
59 element.setAttribute("CaseType", testCase.caseType)
60 parent.appendChild(element)
61 for child in testCase.children:
62 exportCase(doc, element, child)
66 packageName = sys.argv[1]
68 rootCase = TestCase(packageName, packageName, "TestPackage" )
69 caseNameHash = { packageName:rootCase }
70 caseRE = re.compile(r"^\s*([a-zA-Z0-9_\.\-]+) '([^']*)' (\w+)\s*$".replace(" ", r"\s+"))
72 lines = open(packageName + ".cases").readlines()
76 if line.startswith(packageName + "."):
77 m = caseRE.match(line)
80 description = m.group(2)
82 parent = createAncestors(casePath)
83 parent.children.append(TestCase(casePath, description, caseType))
86 # Create XML document.
88 element = doc.createElement("TestCaseList")
89 doc.appendChild(element)
90 for testCase in rootCase.children:
91 exportCase(doc, element, testCase)
94 xml = doc.toprettyxml(indent=" ")
95 open(packageName + "-cases.xml", "wt").write(xml)
97 print "%d cases converted." % numMatches