-
Notifications
You must be signed in to change notification settings - Fork 186
acc: make acceptance tests work in Databricks development environments #5662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "os/exec" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "golang.org/x/mod/semver" | ||
| ) | ||
|
|
||
| // RequireJQ fails the run if jq is missing from PATH or older than minVersion | ||
| // (e.g. "1.7"). See the call site for why the minimum is what it is. | ||
| func RequireJQ(t *testing.T, minVersion string) { | ||
| out, err := exec.Command("jq", "--version").Output() | ||
| if err != nil { | ||
| t.Fatalf("jq not found on PATH (acceptance tests require jq >= %s): %v", minVersion, err) | ||
| } | ||
| version := strings.TrimSpace(string(out)) | ||
| if !jqVersionOK(version, minVersion) { | ||
| t.Fatalf("acceptance tests require jq >= %s (found %q); install a newer jq", minVersion, version) | ||
| } | ||
| } | ||
|
|
||
| // jqVersionOK reports whether `jq --version` output (e.g. "jq-1.7.1") is >= minVersion. | ||
| func jqVersionOK(versionOutput, minVersion string) bool { | ||
| got := strings.TrimPrefix(versionOutput, "jq-") | ||
| return semver.Compare("v"+got, "v"+minVersion) >= 0 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestJqVersionOK(t *testing.T) { | ||
| assert.True(t, jqVersionOK("jq-1.7", "1.7")) | ||
| assert.True(t, jqVersionOK("jq-1.7.1", "1.7")) | ||
| assert.True(t, jqVersionOK("jq-1.8.1", "1.7")) | ||
| assert.False(t, jqVersionOK("jq-1.6", "1.7")) | ||
| assert.False(t, jqVersionOK("garbage", "1.7")) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "runtime" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "golang.org/x/mod/semver" | ||
| ) | ||
|
|
||
| // EnsurePython makes `python3` on PATH resolve to a Python >= minVersion (e.g. | ||
| // "3.11"). Acceptance scripts invoke `python3` directly and some import stdlib | ||
| // modules added in newer versions, but a host's default python3 may be older. | ||
| // On non-Windows hosts uv (see RequireUV) selects a compatible interpreter, | ||
| // which we symlink as python3/python into a temp dir prepended to PATH. On | ||
| // Windows os.Symlink needs extra privileges, so we instead require that the | ||
| // python3 already on PATH satisfies the floor. | ||
| func EnsurePython(t *testing.T, minVersion string) { | ||
| if runtime.GOOS == "windows" { | ||
| out, err := exec.Command("python3", "--version").Output() | ||
| if err != nil { | ||
| t.Fatalf("python3 not found on PATH (acceptance tests require python >= %s): %v", minVersion, err) | ||
| } | ||
| version := strings.TrimSpace(string(out)) | ||
| if !pythonVersionOK(version, minVersion) { | ||
| t.Fatalf("acceptance tests require python >= %s (found %q)", minVersion, version) | ||
| } | ||
| return | ||
| } | ||
|
|
||
| out, err := exec.Command("uv", "python", "find", ">="+minVersion).Output() | ||
| if err != nil { | ||
| t.Fatalf("uv could not find python >= %s: %v", minVersion, err) | ||
| } | ||
| python := strings.TrimSpace(string(out)) | ||
|
|
||
| binDir := t.TempDir() | ||
| for _, link := range []string{"python3", "python"} { | ||
| if err := os.Symlink(python, filepath.Join(binDir, link)); err != nil { | ||
| t.Fatalf("failed to symlink %s as %s: %v", python, link, err) | ||
| } | ||
| } | ||
| t.Setenv("PATH", binDir+string(os.PathListSeparator)+os.Getenv("PATH")) //nolint:forbidigo // acceptance test harness; no ctx for libs/env | ||
| t.Logf("acceptance tests: using %s (via uv) as python3", python) | ||
| } | ||
|
|
||
| // pythonVersionOK reports whether `python3 --version` output (e.g. "Python 3.13.2") is >= minVersion. | ||
| func pythonVersionOK(versionOutput, minVersion string) bool { | ||
| fields := strings.Fields(versionOutput) | ||
| if len(fields) < 2 { | ||
| return false | ||
| } | ||
| return semver.Compare("v"+fields[1], "v"+minVersion) >= 0 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "os/exec" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestPythonVersionOK(t *testing.T) { | ||
| assert.True(t, pythonVersionOK("Python 3.11.0", "3.11")) | ||
| assert.True(t, pythonVersionOK("Python 3.13.2", "3.11")) | ||
| assert.False(t, pythonVersionOK("Python 3.10.6", "3.11")) | ||
| assert.False(t, pythonVersionOK("garbage", "3.11")) | ||
| } | ||
|
|
||
| func TestEnsurePython(t *testing.T) { | ||
| if _, err := exec.LookPath("uv"); err != nil { | ||
| t.Skip("uv not installed") | ||
| } | ||
|
|
||
| EnsurePython(t, "3.11") | ||
|
|
||
| // After setup, the python3 resolved from PATH must satisfy the floor. | ||
| out, err := exec.Command("python3", "-c", "import sys; print(sys.version_info >= (3, 11))").Output() | ||
| require.NoError(t, err) | ||
| assert.Equal(t, "True", strings.TrimSpace(string(out))) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "os/exec" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "golang.org/x/mod/semver" | ||
| ) | ||
|
|
||
| // RequireRuff fails the run if ruff is missing from PATH or older than | ||
| // minVersion (e.g. "0.9.1"). See the call site for why the minimum is what it is. | ||
| func RequireRuff(t *testing.T, minVersion string) { | ||
| out, err := exec.Command("ruff", "--version").Output() | ||
| if err != nil { | ||
| t.Fatalf("ruff not found on PATH (acceptance tests require ruff >= %s): %v", minVersion, err) | ||
| } | ||
| version := strings.TrimSpace(string(out)) | ||
| if !ruffVersionOK(version, minVersion) { | ||
| t.Fatalf("acceptance tests require ruff >= %s (found %q); install a newer ruff", minVersion, version) | ||
| } | ||
| } | ||
|
|
||
| // ruffVersionOK reports whether `ruff --version` output (e.g. "ruff 0.9.1") is >= minVersion. | ||
| func ruffVersionOK(versionOutput, minVersion string) bool { | ||
| fields := strings.Fields(versionOutput) | ||
| if len(fields) < 2 { | ||
| return false | ||
| } | ||
| return semver.Compare("v"+fields[1], "v"+minVersion) >= 0 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestRuffVersionOK(t *testing.T) { | ||
| assert.True(t, ruffVersionOK("ruff 0.9.1", "0.9.1")) | ||
| assert.True(t, ruffVersionOK("ruff 0.9.2", "0.9.1")) | ||
| assert.True(t, ruffVersionOK("ruff 0.11.0", "0.9.1")) | ||
| assert.False(t, ruffVersionOK("ruff 0.9.0", "0.9.1")) | ||
| assert.False(t, ruffVersionOK("ruff 0.8.5", "0.9.1")) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "os/exec" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "golang.org/x/mod/semver" | ||
| ) | ||
|
|
||
| // RequireUV fails the run if uv is missing from PATH or older than minVersion | ||
| // (e.g. "0.4"). See the call site for why the minimum is what it is. | ||
| func RequireUV(t *testing.T, minVersion string) { | ||
| out, err := exec.Command("uv", "--version").Output() | ||
| if err != nil { | ||
| t.Fatalf("uv not found on PATH (acceptance tests require uv >= %s): %v", minVersion, err) | ||
| } | ||
| version := strings.TrimSpace(string(out)) | ||
| if !uvVersionOK(version, minVersion) { | ||
| t.Fatalf("acceptance tests require uv >= %s (found %q); install a newer uv", minVersion, version) | ||
| } | ||
| } | ||
|
|
||
| // uvVersionOK reports whether `uv --version` output (e.g. "uv 0.11.22 (abc 2025-01-01)") is >= minVersion. | ||
| func uvVersionOK(versionOutput, minVersion string) bool { | ||
| fields := strings.Fields(versionOutput) | ||
| if len(fields) < 2 { | ||
| return false | ||
| } | ||
| return semver.Compare("v"+fields[1], "v"+minVersion) >= 0 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestUvVersionOK(t *testing.T) { | ||
| assert.True(t, uvVersionOK("uv 0.4.0", "0.4")) | ||
| assert.True(t, uvVersionOK("uv 0.11.22 (abcdef 2025-01-01)", "0.4")) | ||
| assert.True(t, uvVersionOK("uv 1.0.0", "0.4")) | ||
| assert.False(t, uvVersionOK("uv 0.3.5", "0.4")) | ||
| assert.False(t, uvVersionOK("garbage", "0.4")) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We now run
uv find pythonfrom the Taskfile instead of assuming the right version exists.This means we need to make sure uv is available before using the Taskfile.