Skip to content

Commit

Permalink
output full commandline for debug logging (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
keisuke-nakata authored Feb 21, 2024
1 parent e345592 commit 39b7d59
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 39 deletions.
15 changes: 1 addition & 14 deletions pysen/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,6 @@
get_reporter_logger,
)

_COMMAND_REPR_MAX_LENGTH = 150
_OMIT_REPR = "..."


def _truncate_command_sequence(cmds: str) -> str:
if len(cmds) <= _COMMAND_REPR_MAX_LENGTH:
return cmds

prefix_length = _COMMAND_REPR_MAX_LENGTH - len(_OMIT_REPR)
assert prefix_length > 0
prefix = cmds[:prefix_length]
return f"{prefix}{_OMIT_REPR}"


class Reporter:
def __init__(self, name: str) -> None:
Expand Down Expand Up @@ -81,7 +68,7 @@ def report_diagnostics(self, diagnostics: Sequence[Diagnostic]) -> None:
self._diagnostics.extend(diagnostics)

def report_command(self, cmd: str) -> None:
self._logger.debug(f"> {_truncate_command_sequence(cmd)}")
self._logger.debug(f"> {cmd}")
self._commands.append(cmd)

@property
Expand Down
26 changes: 1 addition & 25 deletions tests/test_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
import pytest

from pysen.diagnostic import Diagnostic, FLCMFormatter
from pysen.reporter import (
_COMMAND_REPR_MAX_LENGTH,
_OMIT_REPR,
Reporter,
ReporterFactory,
_truncate_command_sequence,
)
from pysen.reporter import Reporter, ReporterFactory

BASE_DIR = pathlib.Path(__file__).resolve().parent

Expand Down Expand Up @@ -86,21 +80,3 @@ def test_reporter_factory() -> None:

out = factory.format_diagnostic_summary(FLCMFormatter)
assert f"{BASE_DIR / 'hoge.py'}:1:3:foo: error" in out


def test__truncate_command_sequence() -> None:
assert _truncate_command_sequence("abcde") == "abcde"

str_a = "a" * _COMMAND_REPR_MAX_LENGTH
assert _truncate_command_sequence(str_a) == str_a

def assert_truncated(original: str, formatted: str) -> None:
assert original != formatted
assert formatted.endswith(_OMIT_REPR)
assert len(formatted) == _COMMAND_REPR_MAX_LENGTH

str_b = str_a + "a"
assert_truncated(str_b, _truncate_command_sequence(str_b))

str_c = str_a + "a" * 100
assert_truncated(str_c, _truncate_command_sequence(str_c))

0 comments on commit 39b7d59

Please sign in to comment.