(doc)
| 325 | |
| 326 | |
| 327 | def test_float_convert(doc): |
| 328 | class Int: |
| 329 | def __int__(self): |
| 330 | return -5 |
| 331 | |
| 332 | class Index: |
| 333 | def __index__(self) -> int: |
| 334 | return -7 |
| 335 | |
| 336 | class Float: |
| 337 | def __float__(self): |
| 338 | return 41.45 |
| 339 | |
| 340 | convert, noconvert = m.float_passthrough, m.float_passthrough_noconvert |
| 341 | assert ( |
| 342 | doc(convert) |
| 343 | == "float_passthrough(arg0: typing.SupportsFloat | typing.SupportsIndex) -> float" |
| 344 | ) |
| 345 | assert doc(noconvert) == "float_passthrough_noconvert(arg0: float) -> float" |
| 346 | |
| 347 | def requires_conversion(v): |
| 348 | pytest.raises(TypeError, noconvert, v) |
| 349 | |
| 350 | def cant_convert(v): |
| 351 | pytest.raises(TypeError, convert, v) |
| 352 | |
| 353 | requires_conversion(Float()) |
| 354 | requires_conversion(Index()) |
| 355 | assert pytest.approx(convert(Float())) == 41.45 |
| 356 | assert pytest.approx(convert(Index())) == -7.0 |
| 357 | assert isinstance(convert(Float()), float) |
| 358 | assert pytest.approx(convert(3)) == 3.0 |
| 359 | requires_conversion(3) |
| 360 | cant_convert(Int()) |
| 361 | |
| 362 | |
| 363 | def test_numpy_int_convert(): |
nothing calls this directly
no test coverage detected