Beispiel #1
0
        def run(self):
            """called after tests are scanned to compute the optimized order"""

            # When Error occurs, return the test name as it is passed.
            output = self.test_paths
            rests = []
            summary = {}
            subset_id = ""
            is_brainless = False

            if not session_id:
                # Session ID in --session is missing. It might be caused by Launchable API errors.
                pass
            else:
                try:
                    client = LaunchableClient(
                        test_runner=context.invoked_subcommand,
                        dry_run=context.obj.dry_run)

                    # temporarily extend the timeout because subset API response has become slow
                    # TODO: remove this line when API response return respose within 60 sec
                    timeout = (5, 180)
                    payload = self.get_payload(session_id, target, duration)

                    res = client.request("post",
                                         "subset",
                                         timeout=timeout,
                                         payload=payload,
                                         compress=True)

                    res.raise_for_status()

                    output = res.json()["testPaths"]
                    rests = res.json()["rest"]
                    subset_id = res.json()["subsettingId"]
                    summary = res.json()["summary"]
                    is_brainless = res.json()["isBrainless"]

                except Exception as e:
                    if os.getenv(REPORT_ERROR_KEY):
                        raise e
                    else:
                        click.echo(e, err=True)
                    click.echo(click.style(
                        "Warning: the service failed to subset. Falling back to running all tests",
                        fg='yellow'),
                               err=True)

            if len(output) == 0:
                click.echo(click.style(
                    "Error: no tests found matching the path.", 'yellow'),
                           err=True)
                return

            if split:
                click.echo("subset/{}".format(subset_id))
            else:
                self.output_handler(output, rests)

            # When Launchable returns an error, the cli skips showing summary report
            if "subset" not in summary.keys() or "rest" not in summary.keys():
                return

            build_name, test_session_id = parse_session(session_id)
            org, workspace = get_org_workspace()

            header = [
                "", "Candidates", "Estimated duration (%)",
                "Estimated duration (min)"
            ]
            rows = [
                [
                    "Subset",
                    len(output),
                    summary["subset"].get("rate", 0.0),
                    summary["subset"].get("duration", 0.0),
                ],
                [
                    "Remainder",
                    len(rests),
                    summary["rest"].get("rate", 0.0),
                    summary["rest"].get("duration", 0.0),
                ],
                [],
                [
                    "Total",
                    len(output) + len(rests),
                    summary["subset"].get("rate", 0.0) +
                    summary["rest"].get("rate", 0.0),
                    summary["subset"].get("rate", 0.0) +
                    summary["rest"].get("duration", 0.0),
                ],
            ]

            if is_brainless:
                click.echo("Your model is currently in training", err=True)

            click.echo(
                "Launchable created subset {} for build {} (test session {}) in workspace {}/{}\n"
                .format(subset_id, build_name, test_session_id, org,
                        workspace),
                err=True)

            click.echo(tabulate(rows, header, tablefmt="github"), err=True)

            click.echo(
                "\nRun `launchable inspect subset --subset-id {}` to view full subset details"
                .format(subset_id),
                err=True)
Beispiel #2
0
 def test_get_org_workspace_no_environment_variables(self):
     org, workspace = get_org_workspace()
     self.assertIsNone(org)
     self.assertIsNone(workspace)
Beispiel #3
0
 def test_get_org_workspace_LAUNCHABLE_TOKEN_and_LAUNCHABLE_ORGANIZATION_and_LAUNCHABLE_WORKSPACE(self):
     org, workspace = get_org_workspace()
     self.assertEqual("token_org", org)
     self.assertEqual("token_wp", workspace)
Beispiel #4
0
 def test_get_org_workspace_LAUNCHABLE_ORGANIZATION_and_LAUNCHABLE_WORKSPACE(self):
     org, workspace = get_org_workspace()
     self.assertEqual("launchableinc", org)
     self.assertEqual("test", workspace)
Beispiel #5
0
 def test_get_org_workspace_valid_LAUNCHABLE_TOKEN(self):
     org, workspace = get_org_workspace()
     self.assertEqual("launchableinc", org)
     self.assertEqual("test", workspace)
Beispiel #6
0
 def test_get_org_workspace_invalid_LAUNCHABLE_TOKEN(self):
     org, workspace = get_org_workspace()
     self.assertIsNone(org)
     self.assertIsNone(workspace)