FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Strip multi-word rich tags when rich is not installed by wolfgang-aura · Pull Request #1807 · python-kasa/python-kasa · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion kasa/cli/common.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
# but only lower case tags to avoid stripping out
# raw data from the device that is printed from
# the device state.
rich_formatting = re.compile(r"\[/?[a-z]+]")
rich_formatting = re.compile(r"\[/?[a-z]+(?: [a-z]+)*]")

def _strip_rich_formatting(echo_func):
"""Strip rich formatting from messages."""
Expand Down
16 changes: 16 additions & 0 deletions tests/test_cli.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import importlib.util
import json
import re
import sys
from datetime import datetime
from unittest.mock import ANY, PropertyMock, patch
from zoneinfo import ZoneInfo
Expand Down Expand Up @@ -1552,3 +1554,17 @@ async def test_discover_config_invalid(
)
assert res.exit_code == 1
assert "--target is not a valid option for single host discovery" in res.output


def test_echo_strips_rich_tags_without_rich(monkeypatch, capsys):
"""Multi-word rich tags are stripped when rich is not installed."""
monkeypatch.setitem(sys.modules, "rich", None)
spec = importlib.util.find_spec("kasa.cli.common")
assert spec
assert spec.loader
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)

module._echo("[bold red]Only discover is available[/bold red] [ABC]")

assert capsys.readouterr().out == "Only discover is available [ABC]\n"
Loading

Back | FazBrowse Home | New Git URL