Skip to content

Commit

Permalink
🐛 [-bug] Addressed even more issues with test stream capabilities (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrownell authored May 31, 2024
2 parents b86b549 + 697971a commit 992b048
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions src/dbrownell_Common/TestHelpers/StreamTestHelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# ----------------------------------------------------------------------
"""Test helpers for content found in ../Streams"""

import os
import re
import sys

Expand Down Expand Up @@ -134,17 +135,33 @@ def GenerateDoneManagerAndContent(
def InitializeStreamCapabilities(
stream=sys.stdout,
) -> None:
"""Ensure that the provided stream outputs consistently within a variety of different environments."""
"""\
Ensure that the provided stream outputs consistently within a variety of different environments.
Usage within a test:
@pytest.fixture(InitializeStreamCapabilities(), scope="session", autouse=True)
if not hasattr(
"""

# Initialization can only happen once
if hasattr(
stream,
Capabilities._EMBEDDED_CAPABILITIES_ATTRIBUTE_NAME, # pylint: disable=protected-access
):
Capabilities(
columns=120,
is_headless=True,
is_interactive=False,
supports_colors=True,
stream=stream,
no_column_warning=True,
)
return

# Override any environment variables that might impact the way in which the output is generated
os.environ[Capabilities.SIMULATE_TERMINAL_COLUMNS_ENV_VAR] = str(Capabilities.DEFAULT_COLUMNS)
os.environ[Capabilities.SIMULATE_TERMINAL_INTERACTIVE_ENV_VAR] = "0"
os.environ[Capabilities.SIMULATE_TERMINAL_COLORS_ENV_VAR] = "1"
os.environ[Capabilities.SIMULATE_TERMINAL_HEADLESS_ENV_VAR] = "1"

# Associate the capabilities with the stream
Capabilities(
columns=Capabilities.DEFAULT_COLUMNS,
is_interactive=False,
is_headless=True,
supports_colors=True,
stream=stream,
no_column_warning=True,
)

0 comments on commit 992b048

Please sign in to comment.