classification
Title: Add test classes for custom __index__, __int__, __float__ and __complex__
Type: enhancement Stage: resolved
Components: Tests Versions: Python 3.9
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: mark.dickinson, rhettinger, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2020-03-31 20:37 by serhiy.storchaka, last changed 2020-04-11 08:00 by serhiy.storchaka. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 19262 closed serhiy.storchaka, 2020-03-31 20:43
Messages (2)
msg365422 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-03-31 20:37
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.
msg365432 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-03-31 22:33
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.
History
Date User Action Args
2020-04-11 08:00:46serhiy.storchakasetstatus: open -> closed
resolution: rejected
stage: patch review -> resolved
2020-03-31 22:33:29rhettingersetnosy: + rhettinger
messages: + msg365432
2020-03-31 20:43:10serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request18618
2020-03-31 20:37:44serhiy.storchakacreate