mirror of https://github.com/databricks/cli.git
refactor: update tests to use t.TempDir(), uv, and pyproject.toml
This commit is contained in:
parent
c0cd244e22
commit
9c58b2eeaa
|
@ -13,15 +13,19 @@ import (
|
||||||
|
|
||||||
// minimalPythonProject returns a map of file paths to their contents for a minimal Python project.
|
// minimalPythonProject returns a map of file paths to their contents for a minimal Python project.
|
||||||
func minimalPythonProject() map[string]string {
|
func minimalPythonProject() map[string]string {
|
||||||
// AI TODO: switch to pyproject.toml here
|
|
||||||
return map[string]string{
|
return map[string]string{
|
||||||
// A simple setup.py that uses setuptools.
|
// pyproject.toml using modern Python packaging
|
||||||
"setup.py": `from setuptools import setup, find_packages
|
"pyproject.toml": `[project]
|
||||||
setup(
|
name = "myproj"
|
||||||
name="myproj",
|
version = "0.1.0"
|
||||||
version="0.1.0",
|
|
||||||
packages=find_packages(),
|
[build-system]
|
||||||
)`,
|
requires = ["setuptools>=61.0.0", "wheel"]
|
||||||
|
build-backend = "setuptools.build_meta"
|
||||||
|
|
||||||
|
[tool.setuptools.packages.find]
|
||||||
|
where = ["."]
|
||||||
|
`,
|
||||||
// A simple module with a __version__.
|
// A simple module with a __version__.
|
||||||
"myproj/__init__.py": `__version__ = "0.1.0"
|
"myproj/__init__.py": `__version__ = "0.1.0"
|
||||||
def hello():
|
def hello():
|
||||||
|
@ -59,13 +63,8 @@ func TestPatchWheel(t *testing.T) {
|
||||||
pythonVersions := []string{"python3.9", "python3.10", "python3.11", "python3.12"}
|
pythonVersions := []string{"python3.9", "python3.10", "python3.11", "python3.12"}
|
||||||
for _, py := range pythonVersions {
|
for _, py := range pythonVersions {
|
||||||
t.Run(py, func(t *testing.T) {
|
t.Run(py, func(t *testing.T) {
|
||||||
// Create a temporary directory for the project.
|
// Create a temporary directory for the project
|
||||||
// AI TODO: use t.TempDir() instead
|
tempDir := t.TempDir()
|
||||||
tempDir, err := ioutil.TempDir("", "myproj")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(tempDir)
|
|
||||||
|
|
||||||
// Write minimal Python project files.
|
// Write minimal Python project files.
|
||||||
projFiles := minimalPythonProject()
|
projFiles := minimalPythonProject()
|
||||||
|
@ -73,11 +72,9 @@ func TestPatchWheel(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a virtual environment.
|
// Create a virtual environment using uv
|
||||||
venvDir := filepath.Join(tempDir, "venv")
|
if out, err := runCmd(tempDir, "uv", "venv", "--python", py, "venv"); err != nil {
|
||||||
// AI TODO: use "uv init --python <python>" to create venv
|
t.Fatalf("uv venv creation failed: %v, output: %s", err, out)
|
||||||
if out, err := runCmd(tempDir, py, "-m", "venv", "venv"); err != nil {
|
|
||||||
t.Fatalf("venv creation failed: %v, output: %s", err, out)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine the pip and python paths inside the venv.
|
// Determine the pip and python paths inside the venv.
|
||||||
|
@ -85,9 +82,9 @@ func TestPatchWheel(t *testing.T) {
|
||||||
pyExec := filepath.Join(venvBin, "python")
|
pyExec := filepath.Join(venvBin, "python")
|
||||||
pipExec := filepath.Join(venvBin, "pip")
|
pipExec := filepath.Join(venvBin, "pip")
|
||||||
|
|
||||||
// Upgrade pip and install build.
|
// Install build using uv
|
||||||
if out, err := runCmd(tempDir, pipExec, "install", "--upgrade", "pip", "build"); err != nil {
|
if out, err := runCmd(tempDir, pipExec, "install", "build"); err != nil {
|
||||||
t.Fatalf("pip install failed: %v, output: %s", err, out)
|
t.Fatalf("uv pip install failed: %v, output: %s", err, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the wheel.
|
// Build the wheel.
|
||||||
|
@ -113,10 +110,9 @@ func TestPatchWheel(t *testing.T) {
|
||||||
}
|
}
|
||||||
t.Logf("origWheel=%s patchedWheel=%s", origWheel, patchedWheel)
|
t.Logf("origWheel=%s patchedWheel=%s", origWheel, patchedWheel)
|
||||||
|
|
||||||
// Install the patched wheel.
|
// Install the patched wheel using uv
|
||||||
// AI TODO: use uv
|
if out, err := runCmd(tempDir, pipExec, "install", "--reinstall", patchedWheel); err != nil {
|
||||||
if out, err := runCmd(tempDir, pipExec, "install", "--force-reinstall", patchedWheel); err != nil {
|
t.Fatalf("failed to install patched wheel with uv: %v, output: %s", err, out)
|
||||||
t.Fatalf("failed to install patched wheel: %v, output: %s", err, out)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run a small command to import the package and print its version.
|
// Run a small command to import the package and print its version.
|
||||||
|
|
Loading…
Reference in New Issue