Skip to content

Commit

Permalink
Add new test for passing with cache clear
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnan-chandra committed Aug 1, 2023
1 parent a861ab5 commit 01c0d38
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import json
from textwrap import dedent
from typing import Iterable
from pants.util.contextutil import temporary_dir
from pants.util.dirutil import safe_rmtree

import pytest

Expand Down Expand Up @@ -138,6 +140,26 @@ def test_passing(rule_runner: PythonRuleRunner) -> None:
assert result[0].report == EMPTY_DIGEST


def test_passing_cache_clear(rule_runner: PythonRuleRunner) -> None:
rule_runner.write_files({f"{PACKAGE}/f.py": GOOD_FILE, f"{PACKAGE}/BUILD": "python_sources()"})
with temporary_dir() as named_caches:
tgt = rule_runner.get_target(Address(PACKAGE, relative_file_path="f.py"))
result = run_pyright(rule_runner, [tgt], extra_args=[f"--named-caches-dir={named_caches}"])
assert len(result) == 1
assert result[0].exit_code == 0
assert "0 errors" in result[0].stdout
assert result[0].report == EMPTY_DIGEST
# Remove the cache dir and run the tests again - should yield the same result
safe_rmtree(named_caches)
# On the second run, the result should be the same as the first even though the cache directory
# has been deleted.
result = run_pyright(rule_runner, [tgt], extra_args=[f"--named-caches-dir={named_caches}"])
assert len(result) == 1
assert result[0].exit_code == 0
assert "0 errors" in result[0].stdout
assert result[0].report == EMPTY_DIGEST


def test_failing(rule_runner: PythonRuleRunner) -> None:
rule_runner.write_files({f"{PACKAGE}/f.py": BAD_FILE, f"{PACKAGE}/BUILD": "python_sources()"})
tgt = rule_runner.get_target(Address(PACKAGE, relative_file_path="f.py"))
Expand Down

0 comments on commit 01c0d38

Please sign in to comment.