"""'마이크 다시 연결' 이 관리자 PowerShell 에 넘기는 인자가 공백 · 한글 · 작은따옴표 · 드라이브 루트 경로에서도 깨지지 않는지.""" import os import sys import tempfile import unittest from pathlib import Path, PureWindowsPath sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "app")) os.environ.setdefault("VC_ROOT", tempfile.mkdtemp()) try: import tkinter # noqa: F401 (voice_changer 가 불러옴) except ImportError: tkinter = None def split_windows_args(s: str) -> list: """CommandLineToArgvW 규칙 (백슬래시 + 따옴표 처리 포함).""" args, cur, i, quoted, has = [], [], 0, False, False while i < len(s): c = s[i] if c == "\\": n = 0 while i < len(s) and s[i] == "\\": n += 1 i += 1 if i < len(s) and s[i] == '"': cur.append("\\" * (n // 2)) if n % 2: cur.append('"') i += 1 has = True continue cur.append("\\" * n) has = True continue if c == '"': quoted = not quoted has = True elif c in " \t" and not quoted: if has: args.append("".join(cur)) cur, has = [], False else: cur.append(c) has = True i += 1 if has: args.append("".join(cur)) return args @unittest.skipUnless(tkinter, "tkinter 없음") class ReconnectParamsTest(unittest.TestCase): def test_korean_space_quote_path(self): from voice_changer import reconnect_params root = PureWindowsPath(r"C:\음성 변환기 테스트\it's here") args = split_windows_args(reconnect_params(root)) self.assertEqual(args, ["-NoProfile", "-ExecutionPolicy", "Bypass", "-File", r"C:\음성 변환기 테스트\it's here\scripts\mic-apo.ps1", "-Install", "-Root", r"C:\음성 변환기 테스트\it's here"]) def test_drive_root(self): from voice_changer import reconnect_params args = split_windows_args(reconnect_params(PureWindowsPath("D:\\"))) self.assertEqual(args[4], r"D:\scripts\mic-apo.ps1") self.assertEqual(args[-1], "D:\\.") # 닫는 따옴표가 \ 에 먹히지 않음 if __name__ == "__main__": unittest.main()