Skip to content

bpo-40129: Add fake number classes in test.support. #19262

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

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Mar 31, 2020

@serhiy-storchaka serhiy-storchaka force-pushed the test-support-fake-numbers branch from 7ccc57f to cac62dd Compare March 31, 2020 21:24
Copy link
Member

@pganssle pganssle left a comment

Choose a reason for hiding this comment

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

Thanks for doing this. The idea seems sound and the datetime implementation seems right.

One suggestion: you should add documentation for this. There is documentation for test.support, but even a block comment before Fake would be helpful to give some additional context to future maintainers and devs about why it's there and when and where you should use it.

__complex__ = Fake._return

class FakePath(Fake):
"""Simple implementing of the path protocol.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"""Simple implementing of the path protocol.
"""Simple implementation of the path protocol.


class FakePath(Fake):
"""Simple implementing of the path protocol.
"""
Copy link
Member

Choose a reason for hiding this comment

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

Should this be on the previous line? Looks weird to have it sitting on its own following a short one-line docstring like this.

def f(): return 7

values = [INT(9), IDX(9),
values = [FakeInt(9), FakeIndex(9),
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't quite understand the name, there's nothing really fake about these classes. Also, it's nice to see what the classes do without leaving the file.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with both points here.

When scanning through the PR on GitHub and seeing FakeInt(10.9), my first thought is that I don't know what that means without guessing, so I want to quickly find the FakeInt definition. That's harder when that definition is in another file. (And yes, if you have a decent editor open and set up properly, the definition should be just a click or keystroke away, but not everyone has that setup available all of the time.)

The problem could potentially be mitigated with a name that more clearly describes what the class is doing (HasDunderIntReturning(3.2)?), but as you can tell I'm having trouble coming up with a name that's going to be immediately unambiguous for people reading the code without also being unwieldy.

@skrah
Copy link
Contributor

skrah commented Apr 1, 2020

IMO tests should be primitive and locally understandable. If they get too fancy, it's easy to lose track of what is being tested.

So I'm not sure if much is gained here.

@serhiy-storchaka
Copy link
Member Author

The main purpose is to make easier to test that the specified function supports an object that implements __index__, not just int. There are a lot of such tests in different files, and we can add more tests, but it is tiring to reimplement such class in every file. It would also help if all test classes used for this purpose have a standardized and well-recognized name, so you don't even need to search its definition.

I used name FakeIndex because we already have FakePath for similar purposes (used in 11 different files), and when it was introduced it looked a good name. We also have more specialized classes like FakeSocket. Do you have to propose better name? MockIndex, IndexLike or just Index?

@serhiy-storchaka serhiy-storchaka deleted the test-support-fake-numbers branch April 11, 2020 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants