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