()
| 345 | |
| 346 | |
| 347 | def test_getfslineno() -> None: |
| 348 | def f(x) -> None: |
| 349 | raise NotImplementedError() |
| 350 | |
| 351 | fspath, lineno = getfslineno(f) |
| 352 | |
| 353 | assert isinstance(fspath, Path) |
| 354 | assert fspath.name == "test_source.py" |
| 355 | assert lineno == f.__code__.co_firstlineno - 1 # see findsource |
| 356 | |
| 357 | class A: |
| 358 | pass |
| 359 | |
| 360 | fspath, lineno = getfslineno(A) |
| 361 | |
| 362 | _, A_lineno = inspect.findsource(A) |
| 363 | assert isinstance(fspath, Path) |
| 364 | assert fspath.name == "test_source.py" |
| 365 | assert lineno == A_lineno |
| 366 | |
| 367 | assert getfslineno(3) == ("", -1) |
| 368 | |
| 369 | class B: |
| 370 | pass |
| 371 | |
| 372 | B.__name__ = B.__qualname__ = "B2" |
| 373 | # Since Python 3.13 this started working. |
| 374 | if sys.version_info >= (3, 13): |
| 375 | assert getfslineno(B)[1] != -1 |
| 376 | else: |
| 377 | assert getfslineno(B)[1] == -1 |
| 378 | |
| 379 | |
| 380 | def test_code_of_object_instance_with_call() -> None: |
nothing calls this directly
no test coverage detected