feat: support Clash Verge global script on Windows
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path, PurePosixPath
|
||||
|
||||
@@ -10,10 +13,59 @@ ROOT = Path(__file__).resolve().parents[1]
|
||||
SPEC_PATH = ROOT / "MODULE_SPEC.yaml"
|
||||
sys.path.insert(0, str(ROOT / "scripts"))
|
||||
|
||||
from gen_clash_verge_script import load_payload, to_rule # noqa: E402
|
||||
from gen_clash_verge_script import ( # noqa: E402
|
||||
default_output_path,
|
||||
load_payload,
|
||||
to_rule,
|
||||
)
|
||||
|
||||
|
||||
class ModuleSpecTests(unittest.TestCase):
|
||||
def test_clash_verge_default_output_path_is_platform_aware(self) -> None:
|
||||
home = Path("C:/Users/example")
|
||||
appdata = Path("C:/Users/example/AppData/Roaming")
|
||||
|
||||
self.assertEqual(
|
||||
default_output_path("win32", home=home, appdata=appdata),
|
||||
appdata
|
||||
/ "io.github.clash-verge-rev.clash-verge-rev"
|
||||
/ "profiles"
|
||||
/ "Script.js",
|
||||
)
|
||||
self.assertEqual(
|
||||
default_output_path("darwin", home=home),
|
||||
home
|
||||
/ "Library/Application Support"
|
||||
/ "io.github.clash-verge-rev.clash-verge-rev"
|
||||
/ "profiles"
|
||||
/ "Script.js",
|
||||
)
|
||||
|
||||
def test_clash_verge_generator_supports_windows_gbk_console(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
output = Path(temp_dir) / "Script.js"
|
||||
env = os.environ.copy()
|
||||
env["PYTHONIOENCODING"] = "gbk"
|
||||
result = subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
str(ROOT / "scripts/gen_clash_verge_script.py"),
|
||||
"--out",
|
||||
str(output),
|
||||
],
|
||||
cwd=ROOT,
|
||||
env=env,
|
||||
capture_output=True,
|
||||
check=False,
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
result.returncode,
|
||||
0,
|
||||
result.stderr.decode("gbk", errors="replace"),
|
||||
)
|
||||
self.assertTrue(output.is_file())
|
||||
|
||||
def test_module_spec_declares_rule_authority_and_safe_context(self) -> None:
|
||||
spec = json.loads(SPEC_PATH.read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user