How to use the mobly.signals function in mobly

To help you get started, we’ve selected a few mobly examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google / mobly / mobly / test_runner.py View on Github external
args.test_bed)
    # Parse test specifiers if exist.
    tests = None
    if args.tests:
        tests = args.tests
    # Execute the test class with configs.
    ok = True
    for config in test_configs:
        runner = TestRunner(log_dir=config.log_path,
                            testbed_name=config.testbed_name)
        with runner.mobly_logger():
            runner.add_test_class(config, test_class, tests)
            try:
                runner.run()
                ok = runner.results.is_all_pass and ok
            except signals.TestAbortAll:
                pass
            except:
                logging.exception('Exception when executing %s.',
                                  config.testbed_name)
                ok = False
    if not ok:
        sys.exit(1)
github google / mobly / mobly / controller_manager.py View on Github external
None if no config existed for this controller and it was not a
            required controller.

        Raises:
            ControllerError:
                * The controller module has already been registered.
                * The actual number of objects instantiated is less than the
                * `min_number`.
                * `required` is True and no corresponding config can be found.
                * Any other error occurred in the registration process.
        """
        verify_controller_module(module)
        # Use the module's name as the ref name
        module_ref_name = module.__name__.split('.')[-1]
        if module_ref_name in self._controller_objects:
            raise signals.ControllerError(
                'Controller module %s has already been registered. It cannot '
                'be registered again.' % module_ref_name)
        # Create controller objects.
        module_config_name = module.MOBLY_CONTROLLER_CONFIG_NAME
        if module_config_name not in self.controller_configs:
            if required:
                raise signals.ControllerError(
                    'No corresponding config found for %s' %
                    module_config_name)
            logging.warning(
                'No corresponding config found for optional controller %s',
                module_config_name)
            return None
        try:
            # Make a deep copy of the config to pass to the controller module,
            # in case the controller module modifies the config internally.
github google / mobly / mobly / controller_manager.py View on Github external
Args:
        module: An object that is a controller module. This is usually
            imported with import statements or loaded by importlib.

    Raises:
        ControllerError: if the module does not match the Mobly controller
            interface, or one of the required members is null.
    """
    required_attributes = ('create', 'destroy', 'MOBLY_CONTROLLER_CONFIG_NAME')
    for attr in required_attributes:
        if not hasattr(module, attr):
            raise signals.ControllerError(
                'Module %s missing required controller module attribute'
                ' %s.' % (module.__name__, attr))
        if not getattr(module, attr):
            raise signals.ControllerError(
                'Controller interface %s in %s cannot be null.' %
                (attr, module.__name__))
github google / mobly / mobly / expects.py View on Github external
If the expectation is not met, the test is marked as fail after its
    execution finishes.

    Error message is "first != second" by default. Additional explanation can
    be supplied in the message.

    Args:
        first: The first object to compare.
        second: The second object to compare.
        msg: A string that adds additional info about the failure.
        extras: An optional field for extra information to be included in test
            result.
    """
    try:
        asserts.assert_equal(first, second, msg, extras)
    except signals.TestSignal as e:
        logging.exception('Expected %s equals to %s, but they are not.', first,
                          second)
        recorder.add_error(e)
github google / mobly / mobly / asserts.py View on Github external
def fail(msg, extras=None):
    """Explicitly fail a test.

    Args:
        msg: A string explaining the details of the failure.
        extras: An optional field for extra information to be included in
            test result.

    Raises:
        signals.TestFailure: Mark a test as failed.
    """
    raise signals.TestFailure(msg, extras)
github google / mobly / mobly / expects.py View on Github external
def expect_true(condition, msg, extras=None):
    """Expects an expression evaluates to True.

    If the expectation is not met, the test is marked as fail after its
    execution finishes.

    Args:
        expr: The expression that is evaluated.
        msg: A string explaining the details in case of failure.
        extras: An optional field for extra information to be included in test
            result.
    """
    try:
        asserts.assert_true(condition, msg, extras)
    except signals.TestSignal as e:
        logging.exception('Expected a `True` value, got `False`.')
        recorder.add_error(e)
github google / mobly / mobly / asserts.py View on Github external
msg: A string that adds additional info about the failure.
        extras: An optional field for extra information to be included in
            test result.
    """
    my_msg = None
    try:
        _pyunit_proxy.assertEqual(first, second)
    except AssertionError as e:
        my_msg = str(e)
        if msg:
            my_msg = "%s %s" % (my_msg, msg)

    # This raise statement is outside of the above except statement to prevent
    # Python3's exception message from having two tracebacks.
    if my_msg is not None:
        raise signals.TestFailure(my_msg, extras=extras)
github google / mobly / mobly / controllers / monsoon.py View on Github external
serials: A list of Monsoon (integer) serials.

    Returns:
        A list of Monsoon objects.
    """
    objs = []
    for s in serials:
        objs.append(Monsoon(serial=s))
    return objs


def destroy(objs):
    return


class MonsoonError(mobly.signals.ControllerError):
    """Raised for exceptions encountered in monsoon lib."""


class MonsoonProxy(object):
    """Class that directly talks to monsoon over serial.

    Provides a simple class to use the power meter, e.g.

    .. code-block:: python

        mon = monsoon.Monsoon()
        mon.SetVoltage(3.7)
        mon.StartDataCollection()
        mydata = []
        while len(mydata) < 1000:
            mydata.extend(mon.CollectData())
github google / mobly / mobly / asserts.py View on Github external
def abort_all(reason, extras=None):
    """Abort all subsequent tests, including the ones not in this test class or
    iteration.

    Args:
        reason: The reason to abort.
        extras: An optional field for extra information to be included in
            test result.

    Raises:
        signals.TestAbortAll: Abort all subsequent tests.
    """
    raise signals.TestAbortAll(reason, extras)
github google / mobly / mobly / controllers / android_device_lib / errors.py View on Github external
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Module for errors thrown from AndroidDevice object.

from mobly import signals

HIERARCHY_TOKEN = '::'


class Error(signals.ControllerError):
    pass


class DeviceError(Error):
    """Raised for errors specific to an AndroidDevice object."""

    def __init__(self, ad, msg):
        template = '%s %s'
        # If the message starts with the hierarchy token, don't add the extra
        # space.
        if isinstance(msg, str) and msg.startswith(HIERARCHY_TOKEN):
            template = '%s%s'
        new_msg = template % (repr(ad), msg)
        super(DeviceError, self).__init__(new_msg)