Skip to content

Commit 8f8f24c

Browse files
authored
Convert python wheel tests to acceptance (#2396)
## Changes Rewrite bundle/tests/python_wheel_test.go into acceptance tests. The same configs are used, but the test now runs 'bundle deploy' and in addition to checking the files on the file system, also checks that the files were uploaded and records jobs/create request. There is a new test helper bin/find.py which filters out paths based on regex, asserts on number of expected results. I've added it because 'find' on Windows behaves differently, so this helps avoid cross-platform differences.
1 parent 03e4bb2 commit 8f8f24c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+484
-155
lines changed

acceptance/bin/find.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Usage: find.py <regex>
4+
Finds all files within current directory matching regex. The output is sorted and slashes are always forward.
5+
6+
If --expect N is provided, the number of matches must be N or error is printed.
7+
"""
8+
9+
import sys
10+
import os
11+
import re
12+
import argparse
13+
14+
15+
parser = argparse.ArgumentParser()
16+
parser.add_argument("regex")
17+
parser.add_argument("--expect", type=int)
18+
args = parser.parse_args()
19+
20+
regex = re.compile(args.regex)
21+
result = []
22+
23+
for root, dirs, files in os.walk("."):
24+
for filename in files:
25+
path = os.path.join(root, filename).lstrip("./\\").replace("\\", "/")
26+
if regex.search(path):
27+
result.append(path)
28+
29+
result.sort()
30+
for item in result:
31+
print(item)
32+
sys.stdout.flush()
33+
34+
if args.expect is not None:
35+
if args.expect != len(result):
36+
sys.exit(f"Expected {args.expect}, got {len(result)}")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
RecordRequests = false
2+
13
[[Repls]]
24
Old = '\\'
35
New = '/'
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export PYTHONDONTWRITEBYTECODE=1
2+
3+
uv venv -q --python 3.12 .venv
4+
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]]; then
5+
source .venv/Scripts/activate
6+
else
7+
source .venv/bin/activate
8+
fi
9+
uv pip install -q setuptools
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Cloud = false
2+
RecordRequests = true
3+
Ignore = [
4+
'.venv',
5+
'dist',
6+
'build',
7+
'*egg-info',
8+
'.databricks',
9+
]
10+
11+
[[Server]]
12+
Pattern = "GET /api/2.1/clusters/get"
13+
Response.Body = '''
14+
{
15+
"cluster_id": "0717-132531-5opeqon1",
16+
"spark_version": "13.3.x-scala2.12"
17+
}
18+
'''

acceptance/bundle/artifacts/unique_name_libraries/test.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Cloud = false
1+
RecordRequests = false
22

33
# The order in which files are uploaded can be different, so we just replace the name
44
[[Repls]]

bundle/tests/python_wheel/python_wheel_dbfs_lib/bundle.yml renamed to acceptance/bundle/artifacts/whl_dbfs/databricks.yml

File renamed without changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
>>> [CLI] bundle deploy
3+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/python-wheel/default/files...
4+
Deploying resources...
5+
Updating deployment state...
6+
Deployment complete!
7+
8+
=== Expecting to find no wheels
9+
>>> errcode find.py --expect 0 whl
10+
11+
=== Expecting 1 wheel in libraries section in /jobs/create
12+
>>> jq -s .[] | select(.path=="/api/2.1/jobs/create") | .body.tasks out.requests.txt
13+
[
14+
{
15+
"existing_cluster_id": "0717-132531-5opeqon1",
16+
"libraries": [
17+
{
18+
"whl": "dbfs:/path/to/dist/mywheel.whl"
19+
}
20+
],
21+
"python_wheel_task": {
22+
"entry_point": "run",
23+
"package_name": "my_test_code"
24+
},
25+
"task_key": "TestTask"
26+
}
27+
]
28+
29+
=== Expecting no wheels to be uploaded
30+
>>> errcode sh -c jq .path < out.requests.txt | grep import | grep whl
31+
32+
Exit code: 1
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
trace $CLI bundle deploy
2+
3+
title "Expecting to find no wheels"
4+
trace errcode find.py --expect 0 whl
5+
6+
title "Expecting 1 wheel in libraries section in /jobs/create"
7+
trace jq -s '.[] | select(.path=="/api/2.1/jobs/create") | .body.tasks' out.requests.txt
8+
9+
title "Expecting no wheels to be uploaded"
10+
trace errcode sh -c 'jq .path < out.requests.txt | grep import | grep whl'
11+
12+
rm out.requests.txt
File renamed without changes.

bundle/tests/python_wheel/python_wheel/bundle.yml renamed to acceptance/bundle/artifacts/whl_explicit/databricks.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ artifacts:
55
my_test_code:
66
type: whl
77
path: "./my_test_code"
8-
build: "python3 setup.py bdist_wheel"
8+
# using 'python' there because 'python3' does not exist in virtualenv on windows
9+
build: python setup.py bdist_wheel
910

1011
resources:
1112
jobs:

0 commit comments

Comments
 (0)