Skip to content

How to update test files

Boris Verkhovskiy edited this page Apr 4, 2023 · 5 revisions

If you are looking for how to create a new test file, see How to contribute to RustPython using CPython's unit tests

Because we have many # TODO: RUSTPYTHON marks in the test code, updating is not trivial but still straightforward with a few tricks.

I am going to reproduce #3448 again to show the process.

Checkout CPython source code

We prefer to use version-tagged CPython source code than untagged one.

In the CPython repository,

$ git checkout v3.11.2

Copy CPython source code to RustPython

$ cp ../cpython/Lib/test/test_math.py Lib/test/test_math.py

Partial update

image

This is the current state. Because we replaced the whole file with a new CPython one, we have the updated parts of the file but we've also lost our original edits.

Don't worry. Just run git add -p.

Type y to accept any updates from CPython

image

We have 31 parts for this file. Keep going until you hit the original RustPython-specific edits.

image

Here, we're finally on one of the original edits. Press s to split it.

image

And n to reject our original edit to be lost.

image

And y to accept CPython update again.

image

Keep going. Basically, n for any lines with TODO: RUSTPYTHON and y for everything else.

Commit and reset

Now git diff shows only TODO: RUSTPYTHON related changes

image

Commit it

$ git commit -m "Update test_math.py from CPython v3.10.0"

And reset to restore our original edits.

$ git reset --hard

Now the test file is updated, but we don't know if it passes yet - because there are newly added tests now.

Run the tests again

$ cargo run Lib/test/test_math.py 

If there are failing tests, follow the instructions from How to contribute to RustPython using CPython's unit tests for the newly failing tests.

Done!

Please create a Pull Request with these changes. Thank you!