diff --git a/launchable/commands/inspect/tests.py b/launchable/commands/inspect/tests.py index 4f224e080..4ff145d23 100644 --- a/launchable/commands/inspect/tests.py +++ b/launchable/commands/inspect/tests.py @@ -7,10 +7,10 @@ import click from tabulate import tabulate -from ..helper import require_session from ...utils.authentication import ensure_org_workspace from ...utils.launchable_client import LaunchableClient from ...utils.session import parse_session +from ..helper import require_session class TestResult(object): diff --git a/launchable/commands/record/case_event.py b/launchable/commands/record/case_event.py index 20e9b7de9..823ad51df 100644 --- a/launchable/commands/record/case_event.py +++ b/launchable/commands/record/case_event.py @@ -1,11 +1,10 @@ import datetime import sys -from typing import Callable, Dict, Optional, Any +from typing import Any, Callable, Dict, Optional import dateutil.parser from dateutil.tz import tzlocal - -from junitparser import Error, Failure, Skipped, TestCase, TestSuite, IntAttr # type: ignore +from junitparser import Error, Failure, IntAttr, Skipped, TestCase, TestSuite # type: ignore from ...testpath import FilePathNormalizer, TestPath diff --git a/launchable/commands/subset.py b/launchable/commands/subset.py index 9eaa01cee..e25d3b184 100644 --- a/launchable/commands/subset.py +++ b/launchable/commands/subset.py @@ -43,6 +43,12 @@ help='subsetting by confidence from 0% to 100%', type=PERCENTAGE, ) +@click.option( + '--goal-spec', + 'goal_spec', + help='subsetting by programmatic goal definition', + type=str, +) @click.option( '--session', 'session', @@ -185,6 +191,7 @@ def subset( duration: Optional[DurationType], flavor: Sequence[Tuple[str, str]], confidence: Optional[PercentageType], + goal_spec: Optional[str], split: bool, no_base_path_inference: bool, ignore_new_tests: bool, @@ -431,6 +438,11 @@ def get_payload( "type": "subset-by-confidence", "percentage": confidence } + elif goal_spec is not None: + payload["goal"] = { + "type": "subset-by-goal-spec", + "goal": goal_spec + } else: payload['useServerSideOptimizationTarget'] = True diff --git a/launchable/test_runners/flutter.py b/launchable/test_runners/flutter.py index 1234b1c2f..5c69cc028 100644 --- a/launchable/test_runners/flutter.py +++ b/launchable/test_runners/flutter.py @@ -1,6 +1,5 @@ import json import pathlib -from pathlib import Path from typing import Dict, Generator, List, Optional import click diff --git a/launchable/test_runners/prove.py b/launchable/test_runners/prove.py index 009659eb8..67c83910a 100644 --- a/launchable/test_runners/prove.py +++ b/launchable/test_runners/prove.py @@ -1,11 +1,11 @@ +import re + import click from junitparser import TestCase, TestSuite # type: ignore -import re from ..testpath import TestPath from . import launchable - TEARDOWN = "(teardown)" diff --git a/launchable/utils/sax.py b/launchable/utils/sax.py index 9ed952e5f..6cee59f4e 100644 --- a/launchable/utils/sax.py +++ b/launchable/utils/sax.py @@ -4,6 +4,7 @@ from xml.sax import make_parser from xml.sax.handler import ContentHandler from xml.sax.xmlreader import AttributesImpl + import click diff --git a/tests/commands/test_subset.py b/tests/commands/test_subset.py index 271f60818..df95c3d7e 100644 --- a/tests/commands/test_subset.py +++ b/tests/commands/test_subset.py @@ -208,6 +208,39 @@ def test_subset_targetless(self): payload = json.loads(gzip.decompress(responses.calls[0].request.body).decode()) self.assertTrue(payload.get('useServerSideOptimizationTarget')) + @responses.activate + @mock.patch.dict(os.environ, {"LAUNCHABLE_TOKEN": CliTestCase.launchable_token}) + def test_subset_goalspec(self): + # make sure --goal-spec gets translated properly to a JSON request payload + responses.replace( + responses.POST, + "{}/intake/organizations/{}/workspaces/{}/subset".format( + get_base_url(), + self.organization, + self.workspace), + json={ + "testPaths": [ + [{"type": "file", "name": "test_aaa.py"}], + ], + "testRunner": "file", + "rest": [], + "subsettingId": 123, + }, + status=200) + + result = self.cli( + "subset", + "--session", + self.session, + "--goal-spec", + "foo(),bar(zot=3%)", + "file", + input="test_aaa.py") + self.assert_success(result) + + payload = json.loads(gzip.decompress(responses.calls[0].request.body).decode()) + self.assertEqual(payload.get('goal').get('goal'), "foo(),bar(zot=3%)") + @responses.activate @mock.patch.dict(os.environ, {"LAUNCHABLE_TOKEN": CliTestCase.launchable_token}) def test_subset_ignore_flaky_tests_above(self): diff --git a/tests/data/cucumber/report/result.json b/tests/data/cucumber/report/result.json index 3cc9efdd2..778e1d6cb 100644 --- a/tests/data/cucumber/report/result.json +++ b/tests/data/cucumber/report/result.json @@ -1989,4 +1989,4 @@ } ] } -] \ No newline at end of file +] diff --git a/tests/data/flutter/record_test_result.json b/tests/data/flutter/record_test_result.json index 63bcf3361..0f792fcb1 100644 --- a/tests/data/flutter/record_test_result.json +++ b/tests/data/flutter/record_test_result.json @@ -60,4 +60,4 @@ "noBuild": false, "flavors": [], "testSuite": "" -} \ No newline at end of file +} diff --git a/tests/data/playwright/record_test_result.json b/tests/data/playwright/record_test_result.json index 8f31f3037..01d6d9616 100644 --- a/tests/data/playwright/record_test_result.json +++ b/tests/data/playwright/record_test_result.json @@ -1680,4 +1680,4 @@ "noBuild": false, "flavors": [], "testSuite": "" -} \ No newline at end of file +} diff --git a/tests/data/playwright/record_test_result_with_json.json b/tests/data/playwright/record_test_result_with_json.json index 452b1573a..ad9c2da1b 100644 --- a/tests/data/playwright/record_test_result_with_json.json +++ b/tests/data/playwright/record_test_result_with_json.json @@ -2406,4 +2406,4 @@ "noBuild": false, "flavors": [], "testSuite": "" -} \ No newline at end of file +} diff --git a/tests/data/playwright/report.json b/tests/data/playwright/report.json index 88e594d65..069ae136d 100644 --- a/tests/data/playwright/report.json +++ b/tests/data/playwright/report.json @@ -3615,4 +3615,4 @@ "unexpected": 3, "flaky": 6 } -} \ No newline at end of file +} diff --git a/tests/data/playwright/report.xml b/tests/data/playwright/report.xml index a413993a5..9bfe1f3ce 100644 --- a/tests/data/playwright/report.xml +++ b/tests/data/playwright/report.xml @@ -578,4 +578,4 @@ Retry count: [33m3[39m - \ No newline at end of file +