示例#1
0
def _PrepareBundles(working_dir, app_under_test_path, test_bundle_path):
    """Prepares the bundles in work directory.

  If the original bundle is .ipa, the .ipa file will be unzipped under
  working_dir. If the original bundle is .app/.xctest and the bundle file is not
  in working_dir, the bundle file will be copied to working_dir.

  Args:
    working_dir: string, the working directory.
    app_under_test_path: string, the path of the application to be tested.
        It can be .ipa or .app. It can be None.
    test_bundle_path: string, the path of the test bundle to be tested. It can
        be .ipa or .xctest.

  Returns:
    a tuple with two items:
      a path of app under test directory (.app) under work directory.
      a path of test bundle directory (.xctest) under work directory.

  Raises:
    ios_errors.IllegalArgumentError: if the app under test/test bundle does not
      exist or its extension is invaild.
  """
    working_dir = os.path.abspath(working_dir)
    app_under_test_dir = None
    if app_under_test_path:
        if not os.path.exists(app_under_test_path):
            raise ios_errors.IllegalArgumentError(
                'The app under test does not exists: %s' % app_under_test_path)
        if not (app_under_test_path.endswith('.app')
                or app_under_test_path.endswith('.ipa')):
            raise ios_errors.IllegalArgumentError(
                'The app under test %s should be with .app or .ipa extension.'
                % app_under_test_path)

        app_under_test_dir = os.path.join(
            working_dir,
            os.path.splitext(os.path.basename(app_under_test_path))[0] +
            '.app')
        if not os.path.exists(app_under_test_dir):
            if app_under_test_path.endswith('.ipa'):
                extract_app_under_test_dir = bundle_util.ExtractApp(
                    app_under_test_path, working_dir)
                shutil.move(extract_app_under_test_dir, app_under_test_dir)
            elif not os.path.abspath(app_under_test_path).startswith(
                    working_dir):
                # Only copies the app under test if it is not in working directory.
                shutil.copytree(app_under_test_path, app_under_test_dir)
            else:
                app_under_test_dir = app_under_test_path

    if not os.path.exists(test_bundle_path):
        raise ios_errors.IllegalArgumentError(
            'The test bundle does not exists: %s' % test_bundle_path)
    if not (test_bundle_path.endswith('.xctest')
            or test_bundle_path.endswith('.ipa')
            or test_bundle_path.endswith('.zip')):
        raise ios_errors.IllegalArgumentError(
            'The test bundle %s should be with .xctest, .ipa or .zip extension.'
            % test_bundle_path)

    test_bundle_dir = os.path.join(
        working_dir,
        os.path.splitext(os.path.basename(test_bundle_path))[0] + '.xctest')
    if not os.path.exists(test_bundle_dir):
        if test_bundle_path.endswith('.ipa') or test_bundle_path.endswith(
                '.zip'):
            extract_test_bundle_dir = bundle_util.ExtractTestBundle(
                test_bundle_path, working_dir)
            shutil.move(extract_test_bundle_dir, test_bundle_dir)
        elif not os.path.abspath(test_bundle_path).startswith(working_dir):
            # Only copies the test bundle if it is not in working directory.
            shutil.copytree(test_bundle_path, test_bundle_dir)
        else:
            test_bundle_dir = test_bundle_path

    return app_under_test_dir, test_bundle_dir
示例#2
0
def _PrepareBundles(working_dir, app_under_test_path, test_bundle_path):
    """Prepares the bundles in work directory.

  If the original bundle is .ipa, the .ipa file will be unzipped under
  working_dir. If the original bundle is .app/.xctest and the bundle file is not
  in working_dir, the bundle file will be copied to working_dir.

  Args:
    working_dir: string, the working directory.
    app_under_test_path: string, the path of the application to be tested.
        It can be .ipa or .app. It can be None.
    test_bundle_path: string, the path of the test bundle to be tested. It can
        be .ipa or .xctest.

  Returns:
    a tuple with two items:
      a path of app under test directory (.app) under work directory.
      a path of test bundle directory (.xctest) under work directory.

  Raises:
    ios_errors.IllegalArgumentError: if the app under test/test bundle does not
      exist or its extension is invaild.
  """
    working_dir = os.path.abspath(working_dir)
    app_under_test_dir = None
    if app_under_test_path:
        if not os.path.exists(app_under_test_path):
            raise ios_errors.IllegalArgumentError(
                'The app under test does not exists: %s' % app_under_test_path)
        if not (app_under_test_path.endswith('.app')
                or app_under_test_path.endswith('.ipa')):
            raise ios_errors.IllegalArgumentError(
                'The app under test %s should be with .app or .ipa extension.'
                % app_under_test_path)

        app_under_test_dir = os.path.join(
            working_dir,
            os.path.splitext(os.path.basename(app_under_test_path))[0] +
            '.app')
        if not os.path.exists(app_under_test_dir):
            if app_under_test_path.endswith('.ipa'):
                extract_app_under_test_dir = bundle_util.ExtractApp(
                    app_under_test_path, working_dir)
                shutil.move(extract_app_under_test_dir, app_under_test_dir)
            elif not os.path.abspath(app_under_test_path).startswith(
                    working_dir):
                # Only copies the app under test if it is not in working directory.
                shutil.copytree(app_under_test_path, app_under_test_dir)
            else:
                app_under_test_dir = app_under_test_path

    if not os.path.exists(test_bundle_path):
        raise ios_errors.IllegalArgumentError(
            'The test bundle does not exists: %s' % test_bundle_path)
    if not (test_bundle_path.endswith('.xctest')
            or test_bundle_path.endswith('.ipa')
            or test_bundle_path.endswith('.zip')):
        raise ios_errors.IllegalArgumentError(
            'The test bundle %s should be with .xctest, .ipa or .zip extension.'
            % test_bundle_path)

    bundle_copied = False
    test_bundle_dir = os.path.join(
        working_dir,
        os.path.splitext(os.path.basename(test_bundle_path))[0] + '.xctest')
    if not os.path.exists(test_bundle_dir):
        if test_bundle_path.endswith('.ipa') or test_bundle_path.endswith(
                '.zip'):
            extract_test_bundle_dir = bundle_util.ExtractTestBundle(
                test_bundle_path, working_dir)
            shutil.move(extract_test_bundle_dir, test_bundle_dir)
            bundle_copied = True
        elif not os.path.abspath(test_bundle_path).startswith(working_dir):
            # Only copies the test bundle if it is not in working directory.
            shutil.copytree(test_bundle_path, test_bundle_dir)
            bundle_copied = True
        else:
            test_bundle_dir = test_bundle_path
    plugins_path = os.path.join(test_bundle_dir, "PlugIns")
    if not app_under_test_dir and os.path.isdir(plugins_path):
        try:
            app = next(
                filter(lambda x: x.endswith(".app"), os.listdir(plugins_path)))
            app = os.path.join(plugins_path, app)
            app_dest_dir = os.path.join(
                working_dir,
                os.path.splitext(os.path.basename(app))[0] + '.app')
            if bundle_copied:
                shutil.move(app, app_dest_dir)
            else:
                shutil.copy(app, app_dest_dir)
            # Only set this after the copy/move has successfully completed
            app_under_test_dir = app_dest_dir
        except StopIteration:
            pass

    return app_under_test_dir, test_bundle_dir