Skip to content

Add test classes for custom __index__, __int__, __float__ and __complex__ #84310

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
serhiy-storchaka opened this issue Mar 31, 2020 · 2 comments
Labels
3.9 only security fixes tests Tests in the Lib/test dir type-feature A feature request or enhancement

Comments

@serhiy-storchaka
Copy link
Member

BPO 40129
Nosy @rhettinger, @mdickinson, @serhiy-storchaka
PRs
  • bpo-40129: Add fake number classes in test.support. #19262
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2020-04-11.08:00:46.286>
    created_at = <Date 2020-03-31.20:37:44.559>
    labels = ['type-feature', 'tests', '3.9']
    title = 'Add test classes for custom __index__, __int__, __float__ and __complex__'
    updated_at = <Date 2020-04-11.08:00:46.285>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2020-04-11.08:00:46.285>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-04-11.08:00:46.286>
    closer = 'serhiy.storchaka'
    components = ['Tests']
    creation = <Date 2020-03-31.20:37:44.559>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 40129
    keywords = ['patch']
    message_count = 2.0
    messages = ['365422', '365432']
    nosy_count = 3.0
    nosy_names = ['rhettinger', 'mark.dickinson', 'serhiy.storchaka']
    pr_nums = ['19262']
    priority = 'normal'
    resolution = 'rejected'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue40129'
    versions = ['Python 3.9']

    @serhiy-storchaka
    Copy link
    Member Author

    There are many tests for int-like objects (which implement custom __index__ or __int__ methods) in different files. There are less tests for float-like objects (with the __float__ method). There are even tests for complex-like (with the __complex__ method) in different files. To simplify maintaining old tests and adding new tests I propose to add general test classes with custom methods __index__, __int__, __float__ or __complex__ which return the specified value or raise an exception. There is already one similar general class: FakePath.

    It could be done using unittest.mock, but Mock objects are much more complex and has too much magic, so they can have different behavior than simpler classes with a single special method.

    @serhiy-storchaka serhiy-storchaka added 3.9 only security fixes tests Tests in the Lib/test dir type-feature A feature request or enhancement labels Mar 31, 2020
    @rhettinger
    Copy link
    Contributor

    I don't think this makes the world better. It just makes it more intertwined. Currently, I can read the test code in isolation and understand it. But with the proposed PR, a person now needs to know more of what is in test_support. I really like seeing the classes in-line so I know exactly what they are doing and exactly what a test is doing.

    Also, I don't like reinventing another alternative to mocks. Ideally, we want to minimize the number of things a person has to know in order to read and write our tests.

    I understand your desire to factor everything you see, but in so doing you're creating tighter coupling and increasing complexity for the everyday contributor.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes tests Tests in the Lib/test dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants