nchammas commented on code in PR #59250:
URL: https://github.com/apache/spark/pull/59250#discussion_r4375964531
##########
dev/sparktestsupport/modules.py:
##########
@@ -102,6 +105,58 @@ def is_ignored_file(filename: str) -> bool:
return False
+class TestStage(Enum):
+ """
+ When a shell script test goal runs in dev/run-tests.py.
+ """
+
+ # Before the Spark build.
+ PRE_BUILD = "pre_build"
+
+
+@dataclass(frozen=True)
+class ShellScriptTestGoal:
+ """
+ Describe a shell script test goal.
+
+ >>> goal = ShellScriptTestGoal("dev/example")
+ >>> goal.stage.value
+ 'pre_build'
+
+ A plain-string stage would silently never match, so it is rejected:
+
+ >>> ShellScriptTestGoal("dev/example", "post_build")
+ Traceback (most recent call last):
+ ...
+ TypeError: Unsupported test stage: 'post_build'
+
+ The path may be a `str` or `Path`, and is normalized:
+
+ >>> ShellScriptTestGoal(Path("./dev//example")) ==
ShellScriptTestGoal("dev/example")
+ True
+
+ The path is a repository-relative script:
+
+ >>> ShellScriptTestGoal("/tmp/example")
+ Traceback (most recent call last):
+ ...
+ ValueError: Shell script path must be relative to repo root: '/tmp/example'
+ """
+
+ path: str | Path
+ stage: TestStage = TestStage.PRE_BUILD
+
+ def __post_init__(self) -> None:
+ if not isinstance(self.stage, TestStage):
+ raise TypeError(f"Unsupported test stage: {self.stage!r}")
+ # `Path` rejects non-path types and normalizes spellings like
"./dev//x".
+ path = Path(self.path)
+ # We have to call `object.__setattr__` because the class is frozen.
+ object.__setattr__(self, "path", path)
+ if path == Path() or path.is_absolute() or ".." in path.parts:
Review Comment:
Addressed in the latest diff.
##########
dev/sparktestsupport/utils.py:
##########
@@ -154,6 +156,27 @@ def determine_modules_to_test(changed_modules,
deduplicated=True):
)
+def determine_shell_script_test_goals(
+ test_modules: Sequence[modules.Module], stage: modules.TestStage
+) -> tuple[modules.ShellScriptTestGoal, ...]:
+ """
+ Return the shell script test goals that the given modules declare for a
stage.
+
+ Goals are returned in the order determined by the modules passed in,
+ preserving each module's declaration order. Each goal is returned only
once:
+
+ >>> from pathlib import Path
+ >>> goals = determine_shell_script_test_goals(
+ ... [modules.root], modules.TestStage.PRE_BUILD)
Review Comment:
Fixed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]