()
| 295 | |
| 296 | |
| 297 | def test_proxy_numeric(): |
| 298 | class Example: |
| 299 | def __complex__(self): |
| 300 | return 1 + 2j |
| 301 | |
| 302 | def __int__(self): |
| 303 | return 1 |
| 304 | |
| 305 | def __float__(self): |
| 306 | return 2.1 |
| 307 | |
| 308 | def __round__(self, n=None): |
| 309 | if n is not None: |
| 310 | return 3.3 |
| 311 | |
| 312 | return 3 |
| 313 | |
| 314 | def __trunc__(self): |
| 315 | return 4 |
| 316 | |
| 317 | def __floor__(self): |
| 318 | return 5 |
| 319 | |
| 320 | def __ceil__(self): |
| 321 | return 6 |
| 322 | |
| 323 | def __index__(self): |
| 324 | return 2 |
| 325 | |
| 326 | _, p = _make_proxy(Example()) |
| 327 | assert complex(p) == 1 + 2j |
| 328 | assert int(p) == 1 |
| 329 | assert float(p) == 2.1 |
| 330 | assert round(p) == 3 |
| 331 | assert round(p, 2) == 3.3 |
| 332 | assert math.trunc(p) == 4 |
| 333 | assert math.floor(p) == 5 |
| 334 | assert math.ceil(p) == 6 |
| 335 | assert [1, 2, 3][p] == 3 # __index__ |
| 336 | |
| 337 | |
| 338 | @pytest.mark.parametrize( |
nothing calls this directly
no test coverage detected