Skip to content

Commit

Permalink
[internal] define process result source map once instead of on every …
Browse files Browse the repository at this point in the history
…call to _format_test_summary (pantsbuild#14019)

instead of on every call to _format_test_summary

follow up for pantsbuild#13889
  • Loading branch information
asherf authored Dec 29, 2021
1 parent 22c566e commit 2d1d194
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/python/pants/core/goals/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,15 +505,16 @@ async def run_tests(
return Test(exit_code)


_SOURCE_MAP = {
ProcessResultMetadata.Source.MEMOIZED: "memoized",
ProcessResultMetadata.Source.RAN_REMOTELY: "ran remotely",
ProcessResultMetadata.Source.HIT_LOCALLY: "cached locally",
ProcessResultMetadata.Source.HIT_REMOTELY: "cached remotely",
}


def _format_test_summary(result: TestResult, run_id: RunId, console: Console) -> str:
"""Format the test summary printed to the console."""
source_map = {
ProcessResultMetadata.Source.MEMOIZED: "memoized",
ProcessResultMetadata.Source.RAN_REMOTELY: "ran remotely",
ProcessResultMetadata.Source.HIT_LOCALLY: "cached locally",
ProcessResultMetadata.Source.HIT_REMOTELY: "cached remotely",
}

if result.result_metadata:
if result.exit_code == 0:
sigil = console.sigil_succeeded()
Expand All @@ -522,7 +523,7 @@ def _format_test_summary(result: TestResult, run_id: RunId, console: Console) ->
sigil = console.sigil_failed()
status = "failed"

source = source_map.get(result.result_metadata.source(run_id))
source = _SOURCE_MAP.get(result.result_metadata.source(run_id))
source_print = f" ({source})" if source else ""

elapsed_print = ""
Expand Down

0 comments on commit 2d1d194

Please sign in to comment.