from pants.testutil.rule_runner import RuleRunner def test_my_rule(): runner = RuleRunner() result = runner.run_goal_rule("my_goal", my_rule, inputs=[FileContent("foo.txt", b"hello world")]) assert result == [FileContent("bar.txt", b"HELLO WORLD")] def my_rule(rule_context: RuleContext, inputs: List[Target]) -> Tuple[RustBinaryTarget, ...]: input_file = rule_context.file_digests[inputs[0].address].path_globs[0] output_file = PurePath("bar.txt") rule_context.materialize_directory(DirectoryToMaterialize({output_file: "HELLO WORLD"})) output = RustBinaryTarget({}, address=Address("", target_name="my_binary")) return output,In this example, we define a test for a rule that takes a single input file and converts it to an output file. We create a RuleRunner instance, then call its `run_goal_rule()` method, which takes the name of the goal we want to run, the rule we want to test, and any inputs (in this case, a file with the content "hello world"). We then assert that the result of running the rule is a file with the content "HELLO WORLD". Package/library: pants.testutil.rule_runner Overall, the RuleRunner class from the pants.testutil.rule_runner package is a powerful tool for testing Pants rules in isolation, and it can help significantly streamline the development and testing process.