Skip to content

Commit

Permalink
test: more tests of debug output control
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Jan 22, 2023
1 parent ff127f8 commit e1ae48e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions coverage/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def filter_text(text: str, filters: Iterable[Callable[[str], str]]) -> str:
return text + ending


class CwdTracker: # pragma: debugging
class CwdTracker:
"""A class to add cwd info to debug messages."""
def __init__(self) -> None:
self.cwd: Optional[str] = None
Expand All @@ -293,7 +293,7 @@ def filter(self, text: str) -> str:
return text


class DebugOutputFile: # pragma: debugging
class DebugOutputFile:
"""A file-like object that includes pid and cwd information."""
def __init__(
self,
Expand Down
15 changes: 12 additions & 3 deletions tests/test_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,22 +239,31 @@ def debug_sys(self) -> None:

def test_stderr_default(self) -> None:
self.debug_sys()
assert_good_debug_sys(self.stderr())
out, err = self.stdouterr()
assert out == ""
assert_good_debug_sys(err)

def test_envvar(self) -> None:
self.set_environ("COVERAGE_DEBUG_FILE", "debug.out")
self.debug_sys()
assert self.stderr() == ""
assert self.stdouterr() == ("", "")
with open("debug.out") as f:
assert_good_debug_sys(f.read())

def test_config_file(self) -> None:
self.make_file(".coveragerc", "[run]\ndebug_file = lotsa_info.txt")
self.debug_sys()
assert self.stderr() == ""
assert self.stdouterr() == ("", "")
with open("lotsa_info.txt") as f:
assert_good_debug_sys(f.read())

def test_stdout_alias(self) -> None:
self.set_environ("COVERAGE_DEBUG_FILE", "stdout")
self.debug_sys()
out, err = self.stdouterr()
assert err == ""
assert_good_debug_sys(out)


def f_one(*args: Any, **kwargs: Any) -> str:
"""First of the chain of functions for testing `short_stack`."""
Expand Down

0 comments on commit e1ae48e

Please sign in to comment.