How to use the mobly.utils.grep 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 / controllers / android_device_lib / snippet_client.py View on Github external
def _check_app_installed(self):
        # Check that the Mobly Snippet app is installed for the current user.
        user_id = self._adb.current_user_id
        out = self._adb.shell('pm list package --user %s' % user_id)
        if not utils.grep('^package:%s$' % self.package, out):
            raise AppStartPreCheckError(
                self._ad,
                '%s is not installed for user %s.' % (self.package, user_id))
        # Check that the app is instrumented.
        out = self._adb.shell('pm list instrumentation')
        matched_out = utils.grep(
            '^instrumentation:%s/%s' %
            (self.package, _INSTRUMENTATION_RUNNER_PACKAGE), out)
        if not matched_out:
            raise AppStartPreCheckError(
                self._ad,
                '%s is installed, but it is not instrumented.' % self.package)
        match = re.search(r'^instrumentation:(.*)\/(.*) \(target=(.*)\)$',
                          matched_out[0])
        target_name = match.group(3)
        # Check that the instrumentation target is installed if it's not the
        # same as the snippet package.
        if target_name != self.package:
            out = self._adb.shell('pm list package --user %s' % user_id)
            if not utils.grep('^package:%s$' % target_name, out):
                raise AppStartPreCheckError(
                    self._ad,
github google / mobly / mobly / controllers / android_device_lib / sl4a_client.py View on Github external
def start_app_and_connect(self):
        """Overrides superclass."""
        # Check that sl4a is installed
        out = self._adb.shell('pm list package')
        if not utils.grep('com.googlecode.android_scripting', out):
            raise jsonrpc_client_base.AppStartError(
                self._ad,
                '%s is not installed on %s' % (_APP_NAME, self._adb.serial))
        self.disable_hidden_api_blacklist()

        # sl4a has problems connecting after disconnection, so kill the apk and
        # try connecting again.
        try:
            self.stop_app()
        except Exception as e:
            self.log.warning(e)

        # Launch the app
        self.device_port = _DEVICE_SIDE_PORT
        self._adb.shell(_LAUNCH_CMD % self.device_port)
github google / mobly / mobly / controllers / android_device_lib / snippet_client.py View on Github external
def _check_app_installed(self):
        # Check that the Mobly Snippet app is installed for the current user.
        user_id = self._adb.current_user_id
        out = self._adb.shell('pm list package --user %s' % user_id)
        if not utils.grep('^package:%s$' % self.package, out):
            raise AppStartPreCheckError(
                self._ad,
                '%s is not installed for user %s.' % (self.package, user_id))
        # Check that the app is instrumented.
        out = self._adb.shell('pm list instrumentation')
        matched_out = utils.grep(
            '^instrumentation:%s/%s' %
            (self.package, _INSTRUMENTATION_RUNNER_PACKAGE), out)
        if not matched_out:
            raise AppStartPreCheckError(
                self._ad,
                '%s is installed, but it is not instrumented.' % self.package)
        match = re.search(r'^instrumentation:(.*)\/(.*) \(target=(.*)\)$',
                          matched_out[0])
        target_name = match.group(3)
        # Check that the instrumentation target is installed if it's not the