Skip to content

Commit

Permalink
[android] Raise an exception when an instr test filter doesn't match …
Browse files Browse the repository at this point in the history
…a test.

BUG=662018

Review-Url: https://codereview.chromium.org/2473783004
Cr-Commit-Position: refs/heads/master@{#430763}
  • Loading branch information
jbudorick authored and Commit bot committed Nov 8, 2016
1 parent 2658d76 commit ab83a46
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
9 changes: 9 additions & 0 deletions build/android/pylib/base/test_exception.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.


class TestException(Exception):
"""Base class for exceptions thrown by the test runner."""
pass

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from devil.android import md5sum
from pylib import constants
from pylib.base import base_test_result
from pylib.base import test_exception
from pylib.base import test_instance
from pylib.constants import host_paths
from pylib.instrumentation import test_result
Expand Down Expand Up @@ -52,14 +53,14 @@
_PICKLE_FORMAT_VERSION = 10


class MissingSizeAnnotationError(Exception):
class MissingSizeAnnotationError(test_exception.TestException):
def __init__(self, class_name):
super(MissingSizeAnnotationError, self).__init__(class_name +
': Test method is missing required size annotation. Add one of: ' +
', '.join('@' + a for a in _VALID_ANNOTATIONS))


class ProguardPickleException(Exception):
class ProguardPickleException(test_exception.TestException):
pass


Expand Down Expand Up @@ -352,6 +353,14 @@ def _SaveTestsToPickle(pickle_path, jar_path, tests):
pickle.dump(pickle_data, pickle_file)


class UnmatchedFilterException(test_exception.TestException):
"""Raised when a user specifies a filter that doesn't match any tests."""

def __init__(self, test_filter):
super(UnmatchedFilterException, self).__init__(
'Test filter "%s" matched no tests.' % test_filter)


class InstrumentationTestInstance(test_instance.TestInstance):

def __init__(self, args, isolate_delegate, error_func):
Expand Down Expand Up @@ -654,6 +663,8 @@ def GetTests(self):
tests = GetAllTests(self.test_jar)
filtered_tests = FilterTests(
tests, self._test_filter, self._annotations, self._excluded_annotations)
if self._test_filter and not filtered_tests:
raise UnmatchedFilterException(self._test_filter)
return self._ParametrizeTestsWithFlags(self._InflateTests(filtered_tests))

# pylint: disable=no-self-use
Expand Down
1 change: 1 addition & 0 deletions build/android/test_runner.pydeps
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pylib/base/environment.py
pylib/base/environment_factory.py
pylib/base/test_collection.py
pylib/base/test_dispatcher.py
pylib/base/test_exception.py
pylib/base/test_instance.py
pylib/base/test_instance_factory.py
pylib/base/test_run.py
Expand Down

0 comments on commit ab83a46

Please sign in to comment.