Skip to content

Incremental engine for long horizon agents 🌟 Star if you like it!

816 B
Raw Blame
"""The CLI writes UTF-8 to piped output whatever the locale's encoding."""

from __future__ import annotations

import io

from cocoindex.cli import _utf8_when_piped


def test_piped_output_in_a_legacy_encoding_switches_to_utf8() -> None:
    raw = io.BytesIO()
    # No newline translation, so the bytes are the same on Windows.
    stream = io.TextIOWrapper(raw, encoding="cp1252", newline="\n")
    _utf8_when_piped(stream)
    stream.write("βœ“ Dropped App (target states reverted Β· <0.1s)\n")
    stream.flush()
    assert (
        raw.getvalue().decode("utf-8")
        == "βœ“ Dropped App (target states reverted Β· <0.1s)\n"
    )


def test_utf8_output_is_left_alone() -> None:
    stream = io.TextIOWrapper(io.BytesIO(), encoding="UTF8")
    _utf8_when_piped(stream)
    assert stream.encoding == "UTF8"