Skip to content

Commit feb082c

Browse files
jqueguinerclaude
andcommitted
test(cli): fix Windows CI mojibake in test_cli_with_lang_to
delegator.run decoded subprocess stdout with the Windows ANSI code page (cp1252), turning UTF-8 'é' (0xC3 0xA9) into 'é' and breaking the Spanish currency assertion on every Windows tox env. Replace delegator with subprocess.run, force encoding="utf-8" on the parent decode, and set PYTHONIOENCODING=utf-8 / PYTHONUTF8=1 in the child env so the CLI emits UTF-8 regardless of the host code page. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent deb1ad0 commit feb082c

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

tests/test_cli.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,40 @@
1818

1919
from __future__ import unicode_literals
2020

21+
import collections
2122
import os
23+
import subprocess
24+
import sys
2225
import unittest
2326

24-
import delegator
25-
2627
import num2words2 as num2words
2728

29+
CliResult = collections.namedtuple("CliResult", ["return_code", "out", "err"])
30+
2831

2932
class CliCaller(object):
3033
def __init__(self):
3134
self.cmd = os.path.realpath(
3235
os.path.join(os.path.dirname(__file__), "..", "bin", "num2words2")
3336
)
34-
self.cmd_list = ["python", self.cmd]
37+
self.cmd_list = [sys.executable, self.cmd]
3538

3639
def run_cmd(self, *args):
3740
cmd_list = self.cmd_list + [str(arg) for arg in args]
38-
cmd = " ".join(cmd_list)
39-
return delegator.run(cmd)
41+
env = os.environ.copy()
42+
env["PYTHONIOENCODING"] = "utf-8"
43+
env["PYTHONUTF8"] = "1"
44+
proc = subprocess.run(
45+
cmd_list,
46+
capture_output=True,
47+
encoding="utf-8",
48+
env=env,
49+
)
50+
return CliResult(
51+
return_code=proc.returncode,
52+
out=proc.stdout,
53+
err=proc.stderr,
54+
)
4055

4156

4257
class CliTestCase(unittest.TestCase):

0 commit comments

Comments
 (0)