1import os 2import json 3import xml.etree.ElementTree as ET 4import sys 5 6 7STATIC_FILENAME = "tmp.xml" 8KNOWN_FAILING_FILENAME = "known_failing_names.txt" 9 10 11class FileDownloader(object): 12 13 def __init__(self, file_url): 14 self.file_url = file_url 15 16 def __enter__(self): 17 os.system("wget -O %s %s" % (STATIC_FILENAME, self.file_url)) 18 os.system("touch %s" % KNOWN_FAILING_FILENAME) 19 20 def __exit__(self, *args): 21 os.system("rm %s" % STATIC_FILENAME) 22 23 24class TestCase(object): 25 26 def __init__(self, xml_test): 27 self._xml_test = xml_test 28 29 @property 30 def name(self): 31 return self._xml_test.get("name") 32 33 @property 34 def passed(self): 35 return self._xml_test.get("result") == "pass" 36 37 def __repr__(self): 38 return "%s: %s" % (self.name, self.passed) 39 40 41def generate_tests_from_file(fname): 42 tree = ET.parse(fname) 43 result = tree.getroot() 44 for module in result: 45 for test_case in module: 46 for test in test_case: 47 yield TestCase(test) 48 49 50def get_failing_tests(fname): 51 return filter( 52 lambda test: not test.passed, 53 generate_tests_from_file(fname), 54 ) 55 56 57def get_failing_test_names(fname): 58 return map( 59 lambda test: test.name, 60 get_failing_tests(fname), 61 ) 62 63 64def get_known_failing_names(): 65 try: 66 with open(KNOWN_FAILING_FILENAME, "rb") as f: 67 return [line for line in f.read().splitlines() if line] 68 except IOError: 69 return [] 70 71 72def new_test_failures(failing_test_names, known_failing_test_names): 73 return sorted( 74 list( 75 set(failing_test_names) - set(known_failing_test_names), 76 ), 77 ) 78 79 80if __name__ == "__main__": 81 print "Any known test failures can be added to %s as a new line" % KNOWN_FAILING_FILENAME 82 try: 83 input_test_url = sys.argv[1] 84 except IndexError: 85 print "Supply *result_*.xml URL from a build from https://partner.android.com/" 86 sys.exit(1) 87 88 with FileDownloader(input_test_url): 89 print "Current failing tests" 90 print json.dumps( 91 sorted( 92 new_test_failures( 93 get_failing_test_names(STATIC_FILENAME), 94 get_known_failing_names(), 95 ), 96 ), 97 indent=4, 98 ) 99