[issue35656] More matchers in unittest.mock

2019-01-25 Thread Yash Aggarwal
Yash Aggarwal added the comment: > due to floating-point inexactness +1 Its not easy to predict when calculated value will not be equal to expected theoretical value. for example math.cos(radians(90)) is something like 6e-17 rather than 0. Testing for this exact value would be just awkward.

[issue35656] More matchers in unittest.mock

2019-01-11 Thread Petter S
Petter S added the comment: I am of the opposite opinion. :-) > if I know roughly what the float should be why would I not want to test it > for exactness? When testing algorithms, it is often the case that the answer should be mathematically exactly 2, but due to floating-point

[issue35656] More matchers in unittest.mock

2019-01-10 Thread Lisa Roach
Lisa Roach added the comment: APPROXIMATE feels like it might lead to code smell to me, if I know roughly what the float should be why would I not want to test it for exactness? It could end up hiding inconsistencies the tests should be catching. -- nosy: +lisroach

[issue35656] More matchers in unittest.mock

2019-01-09 Thread Petter S
Petter S added the comment: Agreed! The code above was a quick example. There are also functions in the standard library for approximate float matching that the "real" code would use. -- ___ Python tracker

[issue35656] More matchers in unittest.mock

2019-01-08 Thread Yash Aggarwal
Yash Aggarwal added the comment: I feel it would be better to have tolerance as an argument. -- nosy: +FR4NKESTI3N ___ Python tracker ___

[issue35656] More matchers in unittest.mock

2019-01-08 Thread Petter S
Petter S added the comment: Yes, something like this: class APPROXIMATE: """Takes a floating point number and implements approximate equality.""" def __init__(self, value): self.value = value def __eq__(self, other): return abs(self.value

[issue35656] More matchers in unittest.mock

2019-01-07 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: Looking at the code ANY is simply implemented with __eq__ always returning True at https://github.com/python/cpython/blob/e61cc481e02b758c8d8289163102c236d0658a55/Lib/unittest/mock.py#L1957 . I am not sure how APPROXIMATE can be implemented in

[issue35656] More matchers in unittest.mock

2019-01-04 Thread Petter S
New submission from Petter S : The ``ANY`` object in ``unittest.mock`` is also pretty useful when verifying dicts in tests: self.assertEqual(result, { "message": "Hi!", "code": 0, "id": mock.ANY }) Then it does not matter what the (presumably randomly