-
Notifications
You must be signed in to change notification settings - Fork 121
Add tests for default-python template on different Python versions #2025
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
20 commits
Select commit
Hold shift + click to select a range
727dc79
Add integration test for default Python bundle initialization
denik e7b77eb
Ignore all under /workspace/current_user
denik 755b8de
pass --python to "uv pip install"
denik 8e1c38a
ensure correct newlines for testdata
denik bc3120f
split code
denik 94ca277
rename golden to testdiff
denik 3dec4ea
fix test
denik 1ac4001
rename AssertEqualJSONs to AssertEqualJQ
denik 004d0df
fix test - add missing Chdir
denik b972bcd
fix comparison on Windows: ignore slash difference, ignore terraform …
denik c8beeb2
clean ups; update NOTICE
denik f6e8f26
Remove orderedmap; use slice wrapped in struct
denik 8945ee3
switch to testutil.TestingT interface
denik b91e7fb
re-order replacement
denik b645c47
disable $DATABRICKS_AUTH_TYPE and add a comment
denik e685482
update NOTICE; fix formatting
denik 90b7413
restore "go 1.23" line
denik 1e242cb
rename RequireOutput to AssertOutput
denik 418564a
get rid of "_, filename, _, _ := runtime.Caller(1)"
denik 7434589
Comment on TestData
denik 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,132 @@ | ||
| package bundle_test | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/databricks/cli/integration/internal/acc" | ||
| "github.com/databricks/cli/internal/testcli" | ||
| "github.com/databricks/cli/internal/testutil" | ||
| "github.com/databricks/cli/libs/python/pythontest" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| var pythonVersions = []string{ | ||
| "3.8", | ||
| "3.9", | ||
| "3.10", | ||
| "3.11", | ||
| "3.12", | ||
| "3.13", | ||
| } | ||
|
|
||
| var pythonVersionsShort = []string{ | ||
| "3.9", | ||
| "3.12", | ||
| } | ||
|
|
||
| var extraInstalls = map[string][]string{ | ||
| "3.12": {"setuptools"}, | ||
| "3.13": {"setuptools"}, | ||
| } | ||
|
|
||
| func TestDefaultPython(t *testing.T) { | ||
| versions := pythonVersions | ||
| if testing.Short() { | ||
| versions = pythonVersionsShort | ||
| } | ||
|
|
||
| for _, pythonVersion := range versions { | ||
| t.Run(pythonVersion, func(t *testing.T) { | ||
| testDefaultPython(t, pythonVersion) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func testDefaultPython(t *testing.T, pythonVersion string) { | ||
| ctx, wt := acc.WorkspaceTest(t) | ||
|
|
||
| uniqueProjectId := testutil.RandomName("") | ||
| ctx, replacements := testcli.WithReplacementsMap(ctx) | ||
| replacements.Set(uniqueProjectId, "$UNIQUE_PRJ") | ||
|
|
||
| user, err := wt.W.CurrentUser.Me(ctx) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, user) | ||
| testcli.PrepareReplacementsUser(t, replacements, *user) | ||
| testcli.PrepareReplacements(t, replacements, wt.W) | ||
|
|
||
| tmpDir := t.TempDir() | ||
| testutil.Chdir(t, tmpDir) | ||
|
|
||
| opts := pythontest.VenvOpts{ | ||
| PythonVersion: pythonVersion, | ||
| Dir: tmpDir, | ||
| } | ||
|
|
||
| pythontest.RequireActivatedPythonEnv(t, ctx, &opts) | ||
| extras, ok := extraInstalls[pythonVersion] | ||
| if ok { | ||
| args := append([]string{"pip", "install", "--python", opts.PythonExe}, extras...) | ||
| cmd := exec.Command("uv", args...) | ||
| require.NoError(t, cmd.Run()) | ||
| } | ||
|
|
||
| projectName := "project_name_" + uniqueProjectId | ||
|
|
||
| initConfig := map[string]string{ | ||
| "project_name": projectName, | ||
| "include_notebook": "yes", | ||
| "include_python": "yes", | ||
| "include_dlt": "yes", | ||
| } | ||
| b, err := json.Marshal(initConfig) | ||
| require.NoError(t, err) | ||
| err = os.WriteFile(filepath.Join(tmpDir, "config.json"), b, 0o644) | ||
| require.NoError(t, err) | ||
|
|
||
| testcli.AssertOutput( | ||
| t, | ||
| ctx, | ||
| []string{"bundle", "init", "default-python", "--config-file", "config.json"}, | ||
| testutil.TestData("testdata/default_python/bundle_init.txt"), | ||
| ) | ||
| testutil.Chdir(t, projectName) | ||
|
|
||
| t.Cleanup(func() { | ||
denik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Delete the stack | ||
| testcli.RequireSuccessfulRun(t, ctx, "bundle", "destroy", "--auto-approve") | ||
| }) | ||
|
|
||
| testcli.AssertOutput( | ||
| t, | ||
| ctx, | ||
| []string{"bundle", "validate"}, | ||
| testutil.TestData("testdata/default_python/bundle_validate.txt"), | ||
| ) | ||
| testcli.AssertOutput( | ||
| t, | ||
| ctx, | ||
| []string{"bundle", "deploy"}, | ||
| testutil.TestData("testdata/default_python/bundle_deploy.txt"), | ||
| ) | ||
|
|
||
| testcli.AssertOutputJQ( | ||
| t, | ||
| ctx, | ||
| []string{"bundle", "summary", "--output", "json"}, | ||
| testutil.TestData("testdata/default_python/bundle_summary.txt"), | ||
| []string{ | ||
| "/bundle/terraform/exec_path", | ||
| "/resources/jobs/project_name_$UNIQUE_PRJ_job/email_notifications", | ||
| "/resources/jobs/project_name_$UNIQUE_PRJ_job/job_clusters/0/new_cluster/node_type_id", | ||
| "/resources/jobs/project_name_$UNIQUE_PRJ_job/url", | ||
| "/resources/pipelines/project_name_$UNIQUE_PRJ_pipeline/catalog", | ||
| "/resources/pipelines/project_name_$UNIQUE_PRJ_pipeline/url", | ||
| "/workspace/current_user", | ||
| }, | ||
| ) | ||
| } | ||
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,6 @@ | ||
| Building project_name_$UNIQUE_PRJ... | ||
denik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Uploading project_name_$UNIQUE_PRJ-0.0.1+<NUMID>.<NUMID>-py3-none-any.whl... | ||
| Uploading bundle files to /Workspace/Users/$USERNAME/.bundle/project_name_$UNIQUE_PRJ/dev/files... | ||
| Deploying resources... | ||
| Updating deployment state... | ||
| Deployment complete! | ||
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,8 @@ | ||
|
|
||
| Welcome to the default Python template for Databricks Asset Bundles! | ||
| Workspace to use (auto-detected, edit in 'project_name_$UNIQUE_PRJ/databricks.yml'): https://$DATABRICKS_HOST | ||
|
|
||
| ✨ Your new project has been created in the 'project_name_$UNIQUE_PRJ' directory! | ||
|
|
||
| Please refer to the README.md file for "getting started" instructions. | ||
| See also the documentation at https://docs.databricks.com/dev-tools/bundles/index.html. |
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.
Uh oh!
There was an error while loading. Please reload this page.