Skip to content

Commit

Permalink
Shift rules_for_testing into the test itself (pantsbuild#19752)
Browse files Browse the repository at this point in the history
This was confusing me, because we don't actually use this plugin
in-repo, it's only for a test. So I moved it into the test.

This has the added benefit of having Pants code not depend on
`internal_plugin` code.
  • Loading branch information
thejcannon authored Sep 1, 2023
1 parent 9bc96c4 commit e658334
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 51 deletions.
4 changes: 0 additions & 4 deletions pants-plugins/internal_plugins/rules_for_testing/BUILD

This file was deleted.

Empty file.
34 changes: 0 additions & 34 deletions pants-plugins/internal_plugins/rules_for_testing/register.py

This file was deleted.

1 change: 0 additions & 1 deletion src/python/pants/engine/internals/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ python_tests(
name="scheduler_integration_test",
sources=["scheduler_integration_test.py"],
dependencies=[
"pants-plugins/internal_plugins/rules_for_testing",
"testprojects/src/python:hello_directory",
],
timeout=180,
Expand Down
66 changes: 54 additions & 12 deletions src/python/pants/engine/internals/scheduler_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

import os
from pathlib import Path
from textwrap import dedent

from pants.testutil.pants_integration_test import ensure_daemon, run_pants
from pants.testutil.pants_integration_test import ensure_daemon, run_pants, setup_tmpdir
from pants.util.contextutil import temporary_dir


Expand All @@ -27,14 +28,55 @@ def test_visualize_to():

@ensure_daemon
def test_graceful_termination(use_pantsd: bool) -> None:
result = run_pants(
[
"--backend-packages=['pants.backend.python', 'internal_plugins.rules_for_testing']",
"list-and-die-for-testing",
"testprojects/src/python/hello/greet:greet",
],
use_pantsd=use_pantsd,
)
result.assert_failure()
assert result.stdout == "testprojects/src/python/hello/greet:greet\n"
assert result.exit_code == 42
sources = {
"in_repo_plugins/bender/register.py": dedent(
'''\
from pants.engine.addresses import Addresses
from pants.engine.console import Console
from pants.engine.goal import Goal, GoalSubsystem
from pants.engine.rules import QueryRule, collect_rules, goal_rule
class ListAndDieForTestingSubsystem(GoalSubsystem):
"""A fast and deadly variant of `./pants list`."""
name = "list-and-die-for-testing"
help = "A fast and deadly variant of `./pants list`."
class ListAndDieForTesting(Goal):
subsystem_cls = ListAndDieForTestingSubsystem
environment_behavior = Goal.EnvironmentBehavior.LOCAL_ONLY
@goal_rule
def fast_list_and_die_for_testing(console: Console, addresses: Addresses) -> ListAndDieForTesting:
for address in addresses:
console.print_stdout(address.spec)
return ListAndDieForTesting(exit_code=42)
def rules():
return [
*collect_rules(),
# NB: Would be unused otherwise.
QueryRule(ListAndDieForTestingSubsystem, []),
]
'''
),
"in_repo_plugins/bender/__init__.py": "",
}

with setup_tmpdir(sources) as tmpdir:
result = run_pants(
[
f"--pythonpath=['{tmpdir}/in_repo_plugins']",
"--backend-packages=['pants.backend.python', 'bender']",
"list-and-die-for-testing",
"testprojects/src/python/hello/greet:greet",
],
use_pantsd=use_pantsd,
)
result.assert_failure()
assert result.stdout == "testprojects/src/python/hello/greet:greet\n", result.stderr
assert result.exit_code == 42

0 comments on commit e658334

Please sign in to comment.