Visitar URL original
Added a test updater tool by terryluan12 · Pull Request #6709 · RustPython/RustPython · GitHub
Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updated update_tests.sh
* Added usage instructions
* Added basic usability (debugging + automatic adding expectedFailure)
  • Loading branch information
terryluan12 committed Jan 11, 2026
commit 0fe8ac2e9b60d7987a8de39e04e5f0278f13a898
95 changes: 71 additions & 24 deletions scripts/update_tests.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
#!/bin/bash

usage() { echo "Usage: $0 [-c <cpython path>] [-r <rustpython path>] [-u <copy untracked test>]" 1>&2; exit 1; }
usage() {
cat >&2 <<EOF
Usage: $0 [OPTIONS]

Copy tests from CPython to RustPython.
Optionally copy untracked tests, and dynamic annotation of failures.

Options:
-c/--cpython-path <path> Path to the CPython source tree (older version)
-r/--rpython-path <path> Path to the RustPython source tree (newer version)
-u/--copy-untracked Copy untracked tests only
-a/--annotate While copying tests, run them and annotate failures dynamically
-h/--help Show this help message and exit

Example Usage: $0 -c ~/cpython -r .
EOF
exit 1
}

if [[ $# -eq 0 ]]; then
usage
exit 1
fi


cpython_path=""
rpython_path=""
copy_untracked=false
annotate=false
libraries=()

while [[ $# -gt 0 ]]; do
Expand All @@ -22,6 +45,14 @@ while [[ $# -gt 0 ]]; do
copy_untracked=true
shift
;;
-h|--help)
usage
return
;;
-a|--annotate)
annotate=true
shift
;;
*)
libraries+=("$1")
shift
Expand All @@ -32,35 +63,49 @@ done
cpython_path="$cpython_path/Lib/test"
rpython_path="$rpython_path/Lib/test"

update_libraries() {
if [[ ${#libraries[@]} -eq 0 ]]; then
libraries=$(find ${cpython_path} -type f -printf "%P\n")
fi
Comment on lines +132 to +138

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Missing error handling and variable quoting.

  1. No error handling if lib_updater.py fails - the script continues silently.
  2. Variables passed to annotate_lib should be quoted to handle paths with spaces.
  3. The boolean check $annotate works but [[ $annotate == true ]] is clearer.
Suggested improvements
     else
         echo "Using lib_updater to update $lib"
-        ./scripts/lib_updater.py --from $clib_path --to $rlib_path -o $rlib_path
+        if ! ./scripts/lib_updater.py --from "$clib_path" --to "$rlib_path" -o "$rlib_path"; then
+            echo "Warning: lib_updater.py failed for $lib" >&2
+        fi
     fi


-    if [[ $annotate && -f "$rlib_path" && $(basename -- "$rlib_path") == test_*.py ]]; then
-        annotate_lib $lib $rlib_path
+    if [[ $annotate == true && -f "$rlib_path" && $(basename -- "$rlib_path") == test_*.py ]]; then
+        annotate_lib "$lib" "$rlib_path"
     fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
./scripts/lib_updater.py --from $clib_path --to $rlib_path -o $rlib_path
fi
if [[ $annotate && -f "$rlib_path" && $(basename -- "$rlib_path") == test_*.py ]]; then
annotate_lib $lib $rlib_path
fi
if ! ./scripts/lib_updater.py --from "$clib_path" --to "$rlib_path" -o "$rlib_path"; then
echo "Warning: lib_updater.py failed for $lib" >&2
fi
fi
if [[ $annotate == true && -f "$rlib_path" && $(basename -- "$rlib_path") == test_*.py ]]; then
annotate_lib "$lib" "$rlib_path"
fi
🤖 Prompt for AI Agents
In @scripts/update_tests.sh around lines 132 - 138, The block calling
lib_updater.py should check its exit status and fail fast: after running
./scripts/lib_updater.py --from $clib_path --to $rlib_path -o $rlib_path, test
the command's return code and log/exit (e.g., non-zero -> echo error and exit 1)
instead of continuing silently; also change the annotate conditional to
explicitly test [[ $annotate == true ]] and quote variables when calling
annotate_lib (use annotate_lib "$lib" "$rlib_path") so paths with spaces are
handled safely.


if [[ ${#libraries[@]} -eq 0 ]]; then
libraries=$(find ${cpython_path} -type f -printf "%P\n")
fi
echo "libraries is ${libraries}"

for lib in "${arr[@]}"
do
cpython_file="$cpython_path/$lib"
rpython_file="$rpython_path/$lib"
for lib in "${libraries[@]}"
do
cpython_file="$cpython_path/$lib"
rpython_file="$rpython_path/$lib"

filename=${lib##*/}
basename=${filename%.py}

if [[ $files_equal $cpython_file $rpython_file -eq 0 ]]; then
continue
fi
if files_equal "$cpython_file" "$rpython_file"; then
echo "No changes in $lib. Skipping..."
continue
fi

if [[ ! -f $cpython_file ]]; then
if $copy_untracked then
echo "Test file $lib missing. Copying..."
cp "$cpython_file" "$rpython_file"
if [[ ! -f "$rpython_file" ]]; then
echo "Test file $lib missing."
if $copy_untracked; then
echo "Copying..."
cp "$cpython_file" "$rpython_file"
fi
else
./scripts/lib_updater.py --from $cpython_file --to $rpython_file -o $rpython_file
fi
else
echo "Updating $lib..."
./scripts/lib_updater.py --from ${rpython_path}/Lib/test/$lib --to ${rpython_path}/Lib/test/$lib
fi


cargo run
done
if $annotate; then
output=$(cargo run --release --features encodings,sqlite -- -m test -j 1 -u all --slowest --fail-env-changed -v $lib 2>&1)
failed_tests=$(echo "$output" | grep '^FAIL: ' | awk '{print $2}')
errored_tests=$(echo "$output" | grep '^ERROR ' | awk '{print $2}')
failed_tests=$(echo "$failed_tests" | sort -u)

for test in "${failed_tests[@]}"
do
sed -i "s/^\([[:space:]]*\)def $test(/\1@unittest.expectedFailure # TODO: RUSTPYTHON\n\1def $test(/" "$rpython_file"
done
output=$(cargo run --release --features encodings,sqlite -- -m test -j 1 -u all --slowest --fail-env-changed -v $lib 2>&1)
echo "$failed_tests"
fi
done
}



Expand All @@ -71,3 +116,5 @@ files_equal() {
return $files_equal
}


update_libraries