-
Notifications
You must be signed in to change notification settings - Fork 184
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
Open
pietern
wants to merge
1
commit into
main
Choose a base branch
from
acc-tests-ignore-local-dev-probes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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,32 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os/exec" | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| // RequireModernJq fails the run if jq is missing or older than 1.7. Acceptance | ||
| // scripts use jq 1.7 features (the pick/1 builtin and the `.foo.[]` iteration | ||
| // syntax); an older jq compiles them as errors and produces spurious diffs | ||
| // across many tests rather than one clear failure. | ||
| func RequireModernJq(t *testing.T) { | ||
| out, err := exec.Command("jq", "--version").Output() | ||
| if err != nil { | ||
| t.Fatalf("jq not found on PATH (acceptance tests require jq >= 1.7): %v", err) | ||
| } | ||
| version := strings.TrimSpace(string(out)) | ||
| if !jqVersionOK(version) { | ||
| t.Fatalf("acceptance tests require jq >= 1.7 (found %q); install a newer jq", version) | ||
| } | ||
| } | ||
|
|
||
| // jqVersionOK reports whether `jq --version` output (e.g. "jq-1.7.1") is >= 1.7. | ||
| func jqVersionOK(version string) bool { | ||
| var major, minor int | ||
| if _, err := fmt.Sscanf(version, "jq-%d.%d", &major, &minor); err != nil { | ||
| return false | ||
| } | ||
| return major > 1 || (major == 1 && minor >= 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,17 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestJqVersionOK(t *testing.T) { | ||
| assert.True(t, jqVersionOK("jq-1.7")) | ||
| assert.True(t, jqVersionOK("jq-1.7.1")) | ||
| assert.True(t, jqVersionOK("jq-1.8.1")) | ||
| assert.True(t, jqVersionOK("jq-2.0")) | ||
| assert.False(t, jqVersionOK("jq-1.6")) | ||
| assert.False(t, jqVersionOK("jq version 1.7")) | ||
| assert.False(t, jqVersionOK("")) | ||
| } |
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,42 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "runtime" | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| // EnsureModernPython makes `python3` on PATH resolve to a Python >= 3.11, the | ||
| // version this repo's scripts target. Acceptance scripts invoke `python3` | ||
| // directly and some import stdlib modules added in 3.11 (e.g. tomllib in | ||
| // acceptance/bundle/resources/permissions/analyze_requests.py), but a host's | ||
| // default python3 may be older. uv (already required for building the | ||
| // databricks-bundles wheel) discovers or provisions a suitable interpreter; we | ||
| // symlink it as python3/python into a temp dir prepended to PATH so every | ||
| // script and build step resolves it. Fails hard if uv is missing or has no | ||
| // suitable Python. | ||
| func EnsureModernPython(t *testing.T) { | ||
| // Windows runners already ship a python3 >= 3.11, and os.Symlink needs extra | ||
| // privileges there, so don't provision: use the interpreter already on PATH. | ||
| if runtime.GOOS == "windows" { | ||
| return | ||
| } | ||
|
|
||
| out, err := exec.Command("uv", "python", "find", ">=3.11").Output() | ||
| if err != nil { | ||
| t.Fatalf("uv could not find python >= 3.11: %v", 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) | ||
| } |
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,23 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "os/exec" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestEnsureModernPython(t *testing.T) { | ||
| if _, err := exec.LookPath("uv"); err != nil { | ||
| t.Skip("uv not installed") | ||
| } | ||
|
|
||
| EnsureModernPython(t) | ||
|
|
||
| // 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,38 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os/exec" | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| // RequireModernRuff fails the run if ruff is missing or older than 0.9.1, the | ||
| // version pinned across the repo (python/pyproject.toml, Taskfile.yml). The | ||
| // pydabs check-formatting acceptance test runs `ruff format` and its golden | ||
| // output assumes that formatter behavior. | ||
| func RequireModernRuff(t *testing.T) { | ||
| out, err := exec.Command("ruff", "--version").Output() | ||
| if err != nil { | ||
| t.Fatalf("ruff not found on PATH (acceptance tests require ruff >= 0.9.1): %v", err) | ||
| } | ||
| version := strings.TrimSpace(string(out)) | ||
| if !ruffVersionOK(version) { | ||
| t.Fatalf("acceptance tests require ruff >= 0.9.1 (found %q); install a newer ruff", version) | ||
| } | ||
| } | ||
|
|
||
| // ruffVersionOK reports whether `ruff --version` output (e.g. "ruff 0.9.1") is >= 0.9.1. | ||
| func ruffVersionOK(version string) bool { | ||
| var major, minor, patch int | ||
| if _, err := fmt.Sscanf(version, "ruff %d.%d.%d", &major, &minor, &patch); err != nil { | ||
| return false | ||
| } | ||
| if major != 0 { | ||
| return major > 0 | ||
| } | ||
| if minor != 9 { | ||
| return minor > 9 | ||
| } | ||
| return patch >= 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,17 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestRuffVersionOK(t *testing.T) { | ||
| assert.True(t, ruffVersionOK("ruff 0.9.1")) | ||
| assert.True(t, ruffVersionOK("ruff 0.9.2")) | ||
| assert.True(t, ruffVersionOK("ruff 0.11.0")) | ||
| assert.True(t, ruffVersionOK("ruff 1.0.0")) | ||
| assert.False(t, ruffVersionOK("ruff 0.9.0")) | ||
| assert.False(t, ruffVersionOK("ruff 0.8.5")) | ||
| assert.False(t, ruffVersionOK("")) | ||
| } |
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,32 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os/exec" | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| // RequireModernUv fails the run if uv is missing or older than 0.4. uv builds | ||
| // the databricks-bundles wheel and provides the test interpreter via | ||
| // `uv python find` (see EnsureModernPython), which landed in the 0.3 line; 0.4 | ||
| // is a small margin above that. | ||
| func RequireModernUv(t *testing.T) { | ||
| out, err := exec.Command("uv", "--version").Output() | ||
| if err != nil { | ||
| t.Fatalf("uv not found on PATH (acceptance tests require uv >= 0.4): %v", err) | ||
| } | ||
| version := strings.TrimSpace(string(out)) | ||
| if !uvVersionOK(version) { | ||
| t.Fatalf("acceptance tests require uv >= 0.4 (found %q); install a newer uv", version) | ||
| } | ||
| } | ||
|
|
||
| // uvVersionOK reports whether `uv --version` output (e.g. "uv 0.11.22 (abc)") is >= 0.4. | ||
| func uvVersionOK(version string) bool { | ||
| var major, minor int | ||
| if _, err := fmt.Sscanf(version, "uv %d.%d", &major, &minor); err != nil { | ||
| return false | ||
| } | ||
| return major > 0 || minor >= 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package internal | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestUvVersionOK(t *testing.T) { | ||
| assert.True(t, uvVersionOK("uv 0.4.0")) | ||
| assert.True(t, uvVersionOK("uv 0.11.22 (abcdef 2025-01-01)")) | ||
| assert.True(t, uvVersionOK("uv 1.0.0")) | ||
| assert.False(t, uvVersionOK("uv 0.3.5")) | ||
| assert.False(t, uvVersionOK("0.4.0")) | ||
| assert.False(t, uvVersionOK("")) | ||
| } |
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.