Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ddgs/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ def cli() -> None:
def safe_entry_point() -> None:
"""Run the CLI tool in try-except block to catch all exceptions."""
logging.basicConfig(level=logging.WARNING)
# Fix Windows GBK encoding issues by setting stdout to UTF-8
if sys.platform == "win32" and hasattr(sys.stdout, "reconfigure"):
try:
sys.stdout.reconfigure(encoding="utf-8")
sys.stderr.reconfigure(encoding="utf-8")
except Exception: # noqa: BLE001
pass # Fallback to original encoding if reconfigure fails
try:
cli()
except Exception as ex: # noqa: BLE001
Expand Down
6 changes: 6 additions & 0 deletions tests/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ def test_books_command() -> None:
assert "title" in result.output


def test_extract_command() -> None:
result = runner.invoke(cli, ["extract", "-u", "https://www.technologyreview.com/2026/01/12/1130697/10-breakthrough-technologies-2026/"])
assert result.exit_code == 0
assert "Breakthrough" in result.output


def test_text_workflow(tmp_path: Path) -> None:
"""Combined test for text search, save, and download functionality."""
# Step 1: Get text results
Expand Down