Skip to content

Run CPython's test_bool.py via unittest #824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 23 commits into from

Conversation

BenLewis-Seequent
Copy link

I have managed to run the test_bool.py using unittest on RustPython.

I have copied the unittest package and its standard library dependencies over from CPython, and the pure python version of itertools.py from https://github.com/beeware/ouroboros.

Again I had to make changes to some of the standard library files to make unittest work. I had to make quite significant changes to unittest itself, but apart from disabling printing of tracebacks, none of the changes should affect the functionality of the library much. Note only limited functionality of unittest actually works at this stage.

In addition to some of my recent PR I have made the following changes to RustPython itself:

  • Ability to do an absolute import of a non-top-level module. i.e. import unittest.case. This isn't implemented properly but is a hack to get importing of those to happen.
  • Add function.__call__
  • Add io.IOBase.flush
  • Add skeleton _thread module
  • Expose types.MethodType
  • Add fake sys.intern and sys.warnoptions
  • Make classmethod have a dict by default.

This PR includes #817.

@codecov-io
Copy link

codecov-io commented Apr 13, 2019

Codecov Report

Merging #824 into master will decrease coverage by 0.05%.
The diff coverage is 33.87%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #824      +/-   ##
==========================================
- Coverage   63.17%   63.12%   -0.06%     
==========================================
  Files          84       85       +1     
  Lines       13894    13919      +25     
  Branches     3077     3078       +1     
==========================================
+ Hits         8778     8786       +8     
- Misses       3112     3127      +15     
- Partials     2004     2006       +2
Impacted Files Coverage Δ
vm/src/obj/objclassmethod.rs 90% <ø> (ø) ⬆️
vm/src/obj/objsuper.rs 49.29% <0%> (+0.68%) ⬆️
vm/src/stdlib/types.rs 0% <0%> (ø) ⬆️
src/main.rs 20.53% <0%> (+0.53%) ⬆️
vm/src/vm.rs 71.4% <0%> (-0.49%) ⬇️
vm/src/eval.rs 64.28% <0%> (+8.03%) ⬆️
vm/src/stdlib/thread.rs 0% <0%> (ø)
vm/src/pyobject.rs 80.34% <0%> (ø) ⬆️
vm/src/function.rs 50.49% <100%> (ø) ⬆️
vm/src/obj/objbytes.rs 70.23% <100%> (ø) ⬆️
... and 10 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5676568...e42b2d6. Read the comment docs.

Copy link
Member

@coolreader18 coolreader18 left a comment

Choose a reason for hiding this comment

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

Looks great! I assume the copy lib files are fine, especially given that the tests are passing (!). Great job!

@BenLewis-Seequent
Copy link
Author

Only 13 of the 28 tests in test_bool.py actually pass, but that is good for this stage.

@BenLewis-Seequent
Copy link
Author

I have added a Python script that displays the diff between the files that we have copied over from CPython, and the original files within the CPython source repository. Hopefully, this will allow us to keep track of the changes we make to them to ensure we don't diverge too much.

@cthulahoops
Copy link
Collaborator

This is awesome work, thank you!

I think there's a bit too much in here for a single PR though, making it a bit hard to review. Could we get some of this split up a bit: rustpython fixes, addition of cpython library code, creation of test harness.

I'm quite scared about copying code from cpython, especially when we then go on to patch the code. Is there an alternative to maintaining a fork of the cpython stdlib? Are we preferring it to ouroboros / maintaining a fork of parts of both? Is it possible to work off a checkout of one 0or the other? (I've been mostly staying out of the stdlib side of things so not sure exactly where this is going.)

@adrian17
Copy link
Contributor

Yeah, this is way too huge. Looks like it has quite a lot of hacks and commented code sprinkled in, that'd be hard to sort out later. Mixing library code from CPython and ouroboros will get really messy really fast too.
Also, the commit list seems to include changes from other PRs?

Anyway, I actually was also experimenting with moving test_bool.py several weeks ago - if that's the main goal, it was quite easy to do with a very basic self-implemented unittest mock and without adding any other libraries.

@windelbouwman
Copy link
Contributor

This is a great step! Nice job! I propose splitting this work up into sizeable pieces, and merge the work one by one, as adrian suggested. I consider this PR as a proof of concept from which we can draw.

Another note, I feel we should seperate tests using the standard library in a different folder than the test snippets. This way, we can run the test snippets without any standard library what so ever. What do you say?

@windelbouwman
Copy link
Contributor

Another question, should we consider creating a new attempt along the same lines of ouroboros?

@BenLewis-Seequent
Copy link
Author

Ok, I will split this PR up more.

I approached this as more of a proof of concept to see where our shortcomings are. Over time once we fix these shortcomings we could move to use CPython standard library directly. But until then we need a place to make changes to the standard library to work around issues. But any ideas are welcome to how to make this work short and long term.

@windelbouwman Possibly, but one of the issues I discovered was our import machinery was lacking. Fortunately, importlib package inside the standard library contains a pure python implementation of the import system. But that would mean we would require a bit of the standard library to be able to do anything. Is this a problem?

tests/cpython_tests/, and their respective files in the CPython source
repo. Also reverted a couple of changes in standard library files that
are no longer needed.
@windelbouwman
Copy link
Contributor

I don't think having some logic for importing in importlib would be a problem. In fact, I think it is probably good to implement some specifics in python itself. As I understood, a lot of how python works, is actually implemented in python itself. Notable examples of this are the importing scheme and the REPL.

@coolreader18
Copy link
Member

Do you think this could be closed now @Skinny121? I think now we have a clearer view of what we want to do in order to run unittest, and we're almost there at this point.

@BenLewis-Seequent
Copy link
Author

Yes, agree, we are making good progress towards being able to run unittest without modifications, although there is still a bit of work to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants