Skip to content

Improve stub testing to cover all of typeshed #5051

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

Merged
merged 9 commits into from
Jul 20, 2018

Conversation

emmatyping
Copy link
Member

This will fail until typeshed is synced with python/typeshed#2130 and python/typeshed#2121

Previously, we were only checking 2and3, 3.3-3.5 and 3. This checks 3.6, 3.7 and 2.

@JelleZijlstra
Copy link
Member

Would it be possible to replace this by an invocation of tests/mypy_test.py in the typeshed submodule using mypy from the current repository? That way we don't have to maintain two slightly different versions of the same logic.

This was referenced May 16, 2018
@emmatyping
Copy link
Member Author

@JelleZijlstra IIRC you now want to do the opposite, replace the check in typeshed with this one? Is that right? Once this is merged it should be easy to just invoke this from typeshed.

@JelleZijlstra
Copy link
Member

I don't feel very strongly about this, but apparently this uncovered bugs in typeshed that typeshed's own tests didn't find, so it would be better to run this test in typeshed itself.

@ilevkivskyi
Copy link
Member

What is the status of this PR? runtests.py is going to be removed soon, so I am wondering if this is still relevant.

@emmatyping
Copy link
Member Author

test_stubs has moved in #5142, I think we should still change the tests to cover all of typeshed. I will modify this to change the pytest test instead of what is in runtests.py

@emmatyping
Copy link
Member Author

Okay this now targets the pytest test. I decided to split each version into its own test so pytest can parrallelize them.

Copy link
Collaborator

@Michael0x2a Michael0x2a left a comment

Choose a reason for hiding this comment

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

FWIW, this PR looks good to me, apart from a few minor nits.

Unless there are any objections, I think I'm going to just merge this in once Ethan has a chance to look through my feedback?

def check_stubs(self, version: str, name: Optional[str] = None) -> None:
if name is None:
name = version
seen = {'__builtin__', }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a short comment explaining why we start by adding __builtin__ to the set?

Also, minor nit: I think just doing seen = {'__builtin__'} (without the comma) works.

if name is None:
name = version
seen = {'__builtin__', }
modules = ['__builtin__']
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can just have this list start by being empty -- that would let us remove the call to modules.remove('__builtin__') down below.


def test_2and3_3(self) -> None:
sys_ver_str = '.'.join(map(str, sys.version_info[:2]))
self.check_stubs(sys_ver_str, name="2and3")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rather then checking the "2and3" directory in only these two cases, would it maybe make sense to pass in a list of directories we want to check into check_stubs?

E.g. we could do self.check_stubs(["2.7", "2and3"]) inside test_2, do self.check_stubs(["2and3", "3", "3.5"]) inside test_35...

I think this would probably make our tests more thorough, though the tradeoff is that each individual test would take longer.

(This is just an idea though -- maybe the tradeoff isn't worth it?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Part of the reason I did this was we already run tests in a matrix of options on Travis, so we'd end up testing all the versions of Python we support if we use the system version info. I collapsed the 2/2and3 and 3/2and3 tests together, but I think otherwise, there isn't a point in adding 3/2and3 to each test.

@Michael0x2a Michael0x2a merged commit 3bcc8bf into python:master Jul 20, 2018
@emmatyping emmatyping deleted the morestubchk branch July 22, 2018 02:52
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.

4 participants