Skip to content

Commit

Permalink
Merge pull request #586 from launchableinc/support-lineage-option
Browse files Browse the repository at this point in the history
Support lineage option
  • Loading branch information
Konboi authored Jul 19, 2023
2 parents 2e92637 + a1d2688 commit 4498a6a
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 5 deletions.
8 changes: 8 additions & 0 deletions launchable/commands/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def find_or_create_session(
is_observation: bool = False,
links: List[str] = [],
is_no_build: bool = False,
lineage: Optional[str] = None,
) -> Optional[str]:
"""Determine the test session ID to be used.
Expand All @@ -28,6 +29,11 @@ def find_or_create_session(
Args:
session: The --session option value
build_name: The --build option value
flavor: The --flavor option values
is_observation: The --observation value
links: The --link option values
is_no_build: The --no-build option value
lineage: lineage option value
"""
from .record.session import session as session_command

Expand All @@ -45,6 +51,7 @@ def find_or_create_session(
is_observation=is_observation,
links=links,
is_no_build=is_no_build,
lineage=lineage,
)
saved_build_name = read_build()
return read_session(str(saved_build_name))
Expand Down Expand Up @@ -83,6 +90,7 @@ def find_or_create_session(
is_observation=is_observation,
links=links,
is_no_build=is_no_build,
lineage=lineage,
)
return read_session(saved_build_name)

Expand Down
10 changes: 10 additions & 0 deletions launchable/commands/record/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ def _validate_session_name(ctx, param, value):
metavar='SESSION_NAME',
callback=_validate_session_name,
)
@click.option(
'--lineage',
'lineage',
help='Set lineage name. A lineage is a set of test sessions grouped and this option value will be used for a lineage name.',
required=False,
type=str,
metavar='LINEAGE',
)
@click.pass_context
def session(
ctx: click.core.Context,
Expand All @@ -93,6 +101,7 @@ def session(
links: List[str] = [],
is_no_build: bool = False,
session_name: Optional[str] = None,
lineage: Optional[str] = None,
):
"""
print_session is for backward compatibility.
Expand Down Expand Up @@ -132,6 +141,7 @@ def session(
"flavors": flavor_dict,
"isObservation": is_observation,
"noBuild": is_no_build,
"lineage": lineage,
}

_links = capture_link(os.environ)
Expand Down
14 changes: 12 additions & 2 deletions launchable/commands/record/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ def _validate_group(ctx, param, value):
type=str,
metavar='SESSION_NAME',
)
@click.option(
'--lineage',
'lineage',
help='Set lineage name. This option value will be passed to the record session command if a session isn\'t created yet.',
required=False,
type=str,
metavar='LINEAGE',
)
@click.pass_context
def tests(
context: click.core.Context,
Expand All @@ -158,7 +166,8 @@ def tests(
is_allow_test_before_build: bool,
links: List[str] = [],
is_no_build: bool = False,
session_name: Optional[str] = None
session_name: Optional[str] = None,
lineage: Optional[str] = None,
):
logger = Logger()

Expand Down Expand Up @@ -200,7 +209,8 @@ def tests(
session=session,
build_name=build_name,
flavor=flavor,
links=links))
links=links,
lineage=lineage))
build_name = read_build()
record_start_at = get_record_start_at(session_id, client)

Expand Down
10 changes: 10 additions & 0 deletions launchable/commands/subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@
help="If you want to only send test reports, please use this option",
is_flag=True,
)
@click.option(
'--lineage',
'lineage',
help='Set lineage name. This option value will be passed to the record session command if a session isn\'t created yet.',
required=False,
type=str,
metavar='LINEAGE',
)
@click.pass_context
def subset(
context: click.core.Context,
Expand All @@ -161,6 +169,7 @@ def subset(
ignore_flaky_tests_above: Optional[float],
links: List[str] = [],
is_no_build: bool = False,
lineage: Optional[str] = None,
):

if is_observation and is_get_tests_from_previous_sessions:
Expand All @@ -180,6 +189,7 @@ def subset(
is_observation=is_observation,
links=links,
is_no_build=is_no_build,
lineage=lineage
)
file_path_normalizer = FilePathNormalizer(base_path, no_base_path_inference=no_base_path_inference)

Expand Down
38 changes: 35 additions & 3 deletions tests/commands/record/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ def test_run_session_without_flavor(self):
self.assertEqual(result.exit_code, 0)

payload = json.loads(responses.calls[0].request.body.decode())
self.assert_json_orderless_equal({"flavors": {}, "isObservation": False, "links": [], "noBuild": False}, payload)
self.assert_json_orderless_equal(
{"flavors": {},
"isObservation": False, "links": [],
"noBuild": False, "lineage": None},
payload)

@responses.activate
@mock.patch.dict(os.environ, {
Expand All @@ -49,6 +53,7 @@ def test_run_session_with_flavor(self):
"isObservation": False,
"links": [],
"noBuild": False,
"lineage": None,
}, payload)

with self.assertRaises(ValueError):
Expand All @@ -68,7 +73,11 @@ def test_run_session_with_observation(self):

payload = json.loads(responses.calls[0].request.body.decode())

self.assert_json_orderless_equal({"flavors": {}, "isObservation": True, "links": [], "noBuild": False}, payload)
self.assert_json_orderless_equal(
{"flavors": {},
"isObservation": True, "links": [],
"noBuild": False, "lineage": None},
payload)

@responses.activate
@mock.patch.dict(os.environ, {
Expand Down Expand Up @@ -99,4 +108,27 @@ def test_run_session_with_session_name(self):
self.assertEqual(result.exit_code, 0)

payload = json.loads(responses.calls[2].request.body.decode())
self.assert_json_orderless_equal({"flavors": {}, "isObservation": False, "links": [], "noBuild": False}, payload)
self.assert_json_orderless_equal(
{"flavors": {},
"isObservation": False, "links": [],
"noBuild": False, "lineage": None},
payload)

@responses.activate
@mock.patch.dict(os.environ, {
"LAUNCHABLE_TOKEN": CliTestCase.launchable_token,
'LANG': 'C.UTF-8',
}, clear=True)
def test_run_session_with_lineage(self):
result = self.cli("record", "session", "--build", self.build_name,
"--lineage", "example-lineage")
self.assertEqual(result.exit_code, 0)

payload = json.loads(responses.calls[0].request.body.decode())
self.assert_json_orderless_equal({
"flavors": {},
"isObservation": False,
"links": [],
"noBuild": False,
"lineage": "example-lineage",
}, payload)

0 comments on commit 4498a6a

Please sign in to comment.