def _GetTestsFromProguard(jar_path): p = proguard.Dump(jar_path) class_lookup = dict((c['class'], c) for c in p['classes']) def is_test_class(c): return c['class'].endswith('Test') def is_test_method(m): return m['method'].startswith('test') def recursive_class_annotations(c): s = c['superclass'] if s in class_lookup: a = recursive_class_annotations(class_lookup[s]) else: a = {} a.update(c['annotations']) return a def stripped_test_class(c): return { 'class': c['class'], 'annotations': recursive_class_annotations(c), 'methods': [m for m in c['methods'] if is_test_method(m)], 'superclass': c['superclass'], } return [stripped_test_class(c) for c in p['classes'] if is_test_class(c)]
def _GetProguardData(self): logging.info('Retrieving test methods via proguard.') p = proguard.Dump(self._jar_path) class_lookup = dict((c['class'], c) for c in p['classes']) def recursive_get_annotations(c): s = c['superclass'] if s in class_lookup: a = recursive_get_annotations(class_lookup[s]) else: a = {} a.update(c['annotations']) return a test_classes = (c for c in p['classes'] if c['class'].endswith('Test')) for c in test_classes: class_annotations = recursive_get_annotations(c) test_methods = (m for m in c['methods'] if m['method'].startswith('test')) for m in test_methods: qualified_method = '%s#%s' % (c['class'], m['method']) annotations = dict(class_annotations) annotations.update(m['annotations']) self._test_methods[qualified_method] = m self._test_methods[qualified_method][ 'annotations'] = annotations logging.info('Storing proguard output to %s', self._pickled_proguard_name) d = { 'VERSION': PICKLE_FORMAT_VERSION, 'TEST_METHODS': self._test_methods, 'JAR_MD5SUM': md5sum.CalculateHostMd5Sums(self._jar_path)[os.path.realpath( self._jar_path)] } with open(self._pickled_proguard_name, 'w') as f: f.write(pickle.dumps(d))