You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add test classes for custom __index__, __int__, __float__ and __complex__ #84310
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=Noneclosed_at=<Date2020-04-11.08:00:46.286>created_at=<Date2020-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=<Date2020-04-11.08:00:46.285>user='https://github.com/serhiy-storchaka'
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.
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.
Activity
serhiy-storchaka commentedon Mar 31, 2020
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.
rhettinger commentedon Mar 31, 2020
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.