Skip to content

Commit ebaf314

Browse files
committed
test(e2e): 固定解释器的运行测试按解析链接后的路径比较 sys.prefix
Homebrew 的框架版 Python 从 Cellar 目录启动时,sys.prefix 仍经过 /opt/homebrew/opt 链接打印。测试固定的是解析过链接的 Cellar 路径, 直接比较字符串会失败,主分支 CI 在 0.8.9 兼容子集上一直是红的。 现在逐行解析链接后再比较。
1 parent cde45b9 commit ebaf314

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

‎e2e/host/desktop/internal/workbench/python_current_file_run_e2e_test.go‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func checkPythonCurrentFileRun(t *testing.T, interpreter pythonRunInterpreter) {
152152
run := awaitProcessRun(t, h, p, "main.py", nil)
153153
checkOutput := func(output string) {
154154
t.Helper()
155-
if !strings.Contains(output, "current file ran") || !strings.Contains(output, wantPrefix) {
155+
if !strings.Contains(output, "current file ran") || !printsPrefix(output, wantPrefix) {
156156
t.Fatalf("expected the program to run with sys.prefix %q:\n%s", wantPrefix, output)
157157
}
158158
}
@@ -187,3 +187,24 @@ func checkPythonCurrentFileRun(t *testing.T, interpreter pythonRunInterpreter) {
187187
}
188188
t.Fatal("the build model no longer exposes the main.py target")
189189
}
190+
191+
// printsPrefix reports whether a line of output names the directory prefix
192+
// once links are resolved. A framework build of Python, such as Homebrew's,
193+
// prints its sys.prefix through the opt link even when it starts from the
194+
// Cellar directory the test resolved and pinned.
195+
func printsPrefix(output, prefix string) bool {
196+
want, err := filepath.EvalSymlinks(prefix)
197+
if err != nil {
198+
return false
199+
}
200+
for _, line := range strings.Split(output, "\n") {
201+
line = strings.TrimSpace(line)
202+
if line == "" {
203+
continue
204+
}
205+
if got, err := filepath.EvalSymlinks(line); err == nil && got == want {
206+
return true
207+
}
208+
}
209+
return false
210+
}

0 commit comments

Comments
 (0)