Skip to content

Commit a0146e2

Browse files
committed
[AIENG-294] add validation
1 parent ea69f9e commit a0146e2

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

smart_tests/commands/subset.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ def warn(msg: str):
280280
self.is_get_tests_from_guess = is_get_tests_from_guess
281281
self.use_case = use_case
282282

283+
self._validate_print_input_snapshot_option_enabled()
284+
283285
self.file_path_normalizer = FilePathNormalizer(base_path, no_base_path_inference=no_base_path_inference)
284286

285287
self.test_paths: list[list[dict[str, str]]] = []
@@ -599,6 +601,41 @@ def _should_skip_stdin(self) -> bool:
599601
return True
600602
return False
601603

604+
def _validate_print_input_snapshot_option(self):
605+
if not self.print_input_snapshot_id:
606+
return
607+
608+
conflicts: list[str] = []
609+
option_checks = [
610+
("--target", self.target is not None),
611+
("--time", self.time is not None),
612+
("--confidence", self.confidence is not None),
613+
("--goal-spec", self.goal_spec is not None),
614+
("--rest", self.rest is not None),
615+
("--bin", self.bin_target is not None),
616+
("--same-bin", bool(self.same_bin_files)),
617+
("--ignore-new-tests", self.ignore_new_tests),
618+
("--ignore-flaky-tests-above", self.ignore_flaky_tests_above is not None),
619+
("--prioritize-tests-failed-within-hours", self.prioritize_tests_failed_within_hours is not None),
620+
("--prioritized-tests-mapping", self.prioritized_tests_mapping_file is not None),
621+
("--get-tests-from-previous-sessions", self.is_get_tests_from_previous_sessions),
622+
("--get-tests-from-guess", self.is_get_tests_from_guess),
623+
("--output-exclusion-rules", self.is_output_exclusion_rules),
624+
("--non-blocking", self.is_non_blocking),
625+
]
626+
627+
for option_name, is_set in option_checks:
628+
if is_set:
629+
conflicts.append(option_name)
630+
631+
if conflicts:
632+
conflict_list = ", ".join(conflicts)
633+
print_error_and_die(
634+
f"--print-input-snapshot-id cannot be used with {conflict_list}.",
635+
self.tracking_client,
636+
Tracking.ErrorEvent.USER_ERROR,
637+
)
638+
602639
def _print_input_snapshot_id_value(self, subset_result: SubsetResult):
603640
if not subset_result.subset_id:
604641
raise click.ClickException(

tests/commands/test_subset.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,26 @@ def test_subset_print_input_snapshot_id(self):
135135
self.assert_success(result)
136136
self.assertEqual(result.stdout, "456\n")
137137

138+
@responses.activate
139+
@mock.patch.dict(os.environ, {"SMART_TESTS_TOKEN": CliTestCase.smart_tests_token})
140+
def test_subset_print_input_snapshot_id_disallows_subset_options(self):
141+
pipe = "test_1.py\n"
142+
143+
result = self.cli(
144+
"subset",
145+
"file",
146+
"--target",
147+
"30%",
148+
"--session",
149+
self.session,
150+
"--print-input-snapshot-id",
151+
mix_stderr=False,
152+
input=pipe,
153+
)
154+
155+
self.assert_exit_code(result, 1)
156+
self.assertIn("--print-input-snapshot-id cannot be used with --target", result.stderr)
157+
138158
@responses.activate
139159
@mock.patch.dict(os.environ, {"SMART_TESTS_TOKEN": CliTestCase.smart_tests_token})
140160
def test_subset_with_observation_session(self):

0 commit comments

Comments
 (0)