File: android_test_parser.py

package info (click to toggle)
android-platform-tools 29.0.6-28
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 365,224 kB
  • sloc: cpp: 1,049,638; java: 460,532; ansic: 375,452; asm: 301,257; xml: 134,509; python: 92,731; perl: 62,008; sh: 26,753; makefile: 3,210; javascript: 3,172; yacc: 1,403; lex: 455; awk: 368; ruby: 183; sql: 140
file content (98 lines) | stat: -rw-r--r-- 2,109 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import os
import json
import xml.etree.ElementTree as ET
import sys


STATIC_FILENAME = "tmp.xml"
KNOWN_FAILING_FILENAME = "known_failing_names.txt"


class FileDownloader(object):

  def __init__(self, file_url):
    self.file_url = file_url

  def __enter__(self):
    os.system("wget -O %s %s" % (STATIC_FILENAME, self.file_url))
    os.system("touch %s" % KNOWN_FAILING_FILENAME)

  def __exit__(self, *args):
    os.system("rm %s" % STATIC_FILENAME)


class TestCase(object):

  def __init__(self, xml_test):
    self._xml_test = xml_test

  @property
  def name(self):
    return self._xml_test.get("name")

  @property
  def passed(self):
    return self._xml_test.get("result") == "pass"

  def __repr__(self):
    return "%s: %s" % (self.name, self.passed)


def generate_tests_from_file(fname):
  tree = ET.parse(fname)
  result = tree.getroot()
  for module in result:
    for test_case in module:
      for test in test_case:
        yield TestCase(test)


def get_failing_tests(fname):
  return filter(
    lambda test: not test.passed,
    generate_tests_from_file(fname),
  )


def get_failing_test_names(fname):
  return map(
    lambda test: test.name,
    get_failing_tests(fname),
  )


def get_known_failing_names():
  try:
    with open(KNOWN_FAILING_FILENAME, "rb") as f:
      return [line for line in f.read().splitlines() if line]
  except IOError:
    return []


def new_test_failures(failing_test_names, known_failing_test_names):
  return sorted(
    list(
      set(failing_test_names) - set(known_failing_test_names),
    ),
  )


if __name__ == "__main__":
  print "Any known test failures can be added to %s as a new line" % KNOWN_FAILING_FILENAME
  try:
    input_test_url = sys.argv[1]
  except IndexError:
    print "Supply *result_*.xml URL from a build from https://partner.android.com/"
    sys.exit(1)

  with FileDownloader(input_test_url):
    print "Current failing tests"
    print json.dumps(
      sorted(
        new_test_failures(
          get_failing_test_names(STATIC_FILENAME),
          get_known_failing_names(),
        ),
      ),
      indent=4,
    )