-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for default-python template on different Python versions (#…
…2025) ## Changes Add new type of test helpers that run the command and compare full output (golden files approach). In case of JSON, there is also an option to ignore certain paths. Add test for different versions of Python to go through bundle init default-python / validate / deploy / summary. ## Tests New integration tests.
- Loading branch information
Showing
13 changed files
with
724 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -97,3 +97,11 @@ License - https://github.com/stretchr/testify/blob/master/LICENSE | |
whilp/git-urls - https://github.com/whilp/git-urls | ||
Copyright (c) 2020 Will Maier | ||
License - https://github.com/whilp/git-urls/blob/master/LICENSE | ||
|
||
github.com/wI2L/jsondiff v0.6.1 | ||
Copyright (c) 2020-2024 William Poussier <[email protected]> | ||
License - https://github.com/wI2L/jsondiff/blob/master/LICENSE | ||
|
||
https://github.com/hexops/gotextdiff | ||
Copyright (c) 2009 The Go Authors. All rights reserved. | ||
License - https://github.com/hexops/gotextdiff/blob/main/LICENSE |
This file contains 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 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() { | ||
// 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 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... | ||
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 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.