(msg)
| 349 | |
| 350 | |
| 351 | def test_overload_resolution(msg): |
| 352 | # Exact overload matches: |
| 353 | assert m.overloaded(np.array([1], dtype="float64")) == "double" |
| 354 | assert m.overloaded(np.array([1], dtype="float32")) == "float" |
| 355 | assert m.overloaded(np.array([1], dtype="ushort")) == "unsigned short" |
| 356 | assert m.overloaded(np.array([1], dtype="intc")) == "int" |
| 357 | assert m.overloaded(np.array([1], dtype="longlong")) == "long long" |
| 358 | assert m.overloaded(np.array([1], dtype="complex")) == "double complex" |
| 359 | assert m.overloaded(np.array([1], dtype="csingle")) == "float complex" |
| 360 | |
| 361 | # No exact match, should call first convertible version: |
| 362 | assert m.overloaded(np.array([1], dtype="uint8")) == "double" |
| 363 | |
| 364 | with pytest.raises(TypeError) as excinfo: |
| 365 | m.overloaded("not an array") |
| 366 | assert ( |
| 367 | msg(excinfo.value) |
| 368 | == """ |
| 369 | overloaded(): incompatible function arguments. The following argument types are supported: |
| 370 | 1. (arg0: typing.Annotated[numpy.typing.ArrayLike, numpy.float64]) -> str |
| 371 | 2. (arg0: typing.Annotated[numpy.typing.ArrayLike, numpy.float32]) -> str |
| 372 | 3. (arg0: typing.Annotated[numpy.typing.ArrayLike, numpy.int32]) -> str |
| 373 | 4. (arg0: typing.Annotated[numpy.typing.ArrayLike, numpy.uint16]) -> str |
| 374 | 5. (arg0: typing.Annotated[numpy.typing.ArrayLike, numpy.int64]) -> str |
| 375 | 6. (arg0: typing.Annotated[numpy.typing.ArrayLike, numpy.complex128]) -> str |
| 376 | 7. (arg0: typing.Annotated[numpy.typing.ArrayLike, numpy.complex64]) -> str |
| 377 | |
| 378 | Invoked with: 'not an array' |
| 379 | """ |
| 380 | ) |
| 381 | |
| 382 | assert m.overloaded2(np.array([1], dtype="float64")) == "double" |
| 383 | assert m.overloaded2(np.array([1], dtype="float32")) == "float" |
| 384 | assert m.overloaded2(np.array([1], dtype="complex64")) == "float complex" |
| 385 | assert m.overloaded2(np.array([1], dtype="complex128")) == "double complex" |
| 386 | assert m.overloaded2(np.array([1], dtype="float32")) == "float" |
| 387 | |
| 388 | assert m.overloaded3(np.array([1], dtype="float64")) == "double" |
| 389 | assert m.overloaded3(np.array([1], dtype="intc")) == "int" |
| 390 | expected_exc = """ |
| 391 | overloaded3(): incompatible function arguments. The following argument types are supported: |
| 392 | 1. (arg0: numpy.typing.NDArray[numpy.int32]) -> str |
| 393 | 2. (arg0: numpy.typing.NDArray[numpy.float64]) -> str |
| 394 | |
| 395 | Invoked with: """ |
| 396 | |
| 397 | with pytest.raises(TypeError) as excinfo: |
| 398 | m.overloaded3(np.array([1], dtype="uintc")) |
| 399 | assert msg(excinfo.value) == expected_exc + repr(np.array([1], dtype="uint32")) |
| 400 | with pytest.raises(TypeError) as excinfo: |
| 401 | m.overloaded3(np.array([1], dtype="float32")) |
| 402 | assert msg(excinfo.value) == expected_exc + repr(np.array([1.0], dtype="float32")) |
| 403 | with pytest.raises(TypeError) as excinfo: |
| 404 | m.overloaded3(np.array([1], dtype="complex")) |
| 405 | assert msg(excinfo.value) == expected_exc + repr(np.array([1.0 + 0.0j])) |
| 406 | |
| 407 | # Exact matches: |
| 408 | assert m.overloaded4(np.array([1], dtype="double")) == "double" |
nothing calls this directly
no test coverage detected