-
-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
60 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Copyright 2024 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
from dataclasses import dataclass | ||
|
||
from pants.engine.rules import DeleteRule, collect_rules, rule | ||
from pants.testutil.rule_runner import QueryRule, RuleRunner | ||
|
||
|
||
@dataclass(frozen=True) | ||
class IntRequest: | ||
pass | ||
|
||
|
||
@rule | ||
async def original_rule(request: IntRequest) -> int: | ||
return 0 | ||
|
||
|
||
@rule | ||
def new_rule(request: IntRequest) -> int: | ||
return 42 | ||
|
||
|
||
def test_delete() -> None: | ||
rule_runner = RuleRunner( | ||
target_types=[], | ||
rules=[ | ||
*collect_rules( | ||
{ | ||
"original_rule": original_rule, | ||
} | ||
), | ||
QueryRule(int, [IntRequest]), | ||
], | ||
) | ||
|
||
result = rule_runner.request(int, [IntRequest()]) | ||
assert result == 0 | ||
|
||
rule_runner = RuleRunner( | ||
target_types=[], | ||
rules=[ | ||
*collect_rules( | ||
{ | ||
"original_rule": original_rule, | ||
"new_rule": new_rule, | ||
} | ||
), | ||
DeleteRule.create(original_rule), | ||
QueryRule(int, [IntRequest]), | ||
], | ||
) | ||
|
||
result = rule_runner.request(int, [IntRequest()]) | ||
assert result == 42 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters