()
| 439 | |
| 440 | |
| 441 | def test_source_mapping(): |
| 442 | from _pydevd_bundle.pydevd_source_mapping import SourceMapping, SourceMappingEntry |
| 443 | from _pydevd_bundle import pydevd_api |
| 444 | |
| 445 | class _DummyPyDB(object): |
| 446 | source_mapping = SourceMapping() |
| 447 | api_received_breakpoints = {} |
| 448 | file_to_id_to_line_breakpoint = {} |
| 449 | file_to_id_to_plugin_breakpoint = {} |
| 450 | breakpoints = {} |
| 451 | |
| 452 | source_mapping = _DummyPyDB.source_mapping |
| 453 | |
| 454 | mapping = [ |
| 455 | SourceMappingEntry(line=3, end_line=6, runtime_line=5, runtime_source="<cell1>"), |
| 456 | SourceMappingEntry(line=10, end_line=11, runtime_line=1, runtime_source="<cell2>"), |
| 457 | ] |
| 458 | |
| 459 | api = pydevd_api.PyDevdAPI() |
| 460 | py_db = _DummyPyDB() |
| 461 | filename = "c:\\temp\\bar.py" if IS_WINDOWS else "/temp/bar.py" |
| 462 | api.set_source_mapping(py_db, filename, mapping) |
| 463 | |
| 464 | # Map to server |
| 465 | assert source_mapping.map_to_server(filename, 1) == (filename, 1, False) |
| 466 | assert source_mapping.map_to_server(filename, 2) == (filename, 2, False) |
| 467 | |
| 468 | assert source_mapping.map_to_server(filename, 3) == ("<cell1>", 5, True) |
| 469 | assert source_mapping.map_to_server(filename, 4) == ("<cell1>", 6, True) |
| 470 | assert source_mapping.map_to_server(filename, 5) == ("<cell1>", 7, True) |
| 471 | assert source_mapping.map_to_server(filename, 6) == ("<cell1>", 8, True) |
| 472 | |
| 473 | assert source_mapping.map_to_server(filename, 7) == (filename, 7, False) |
| 474 | |
| 475 | assert source_mapping.map_to_server(filename, 10) == ("<cell2>", 1, True) |
| 476 | assert source_mapping.map_to_server(filename, 11) == ("<cell2>", 2, True) |
| 477 | |
| 478 | assert source_mapping.map_to_server(filename, 12) == (filename, 12, False) |
| 479 | |
| 480 | # Map to client |
| 481 | assert source_mapping.map_to_client(filename, 1) == (filename, 1, False) |
| 482 | assert source_mapping.map_to_client(filename, 2) == (filename, 2, False) |
| 483 | |
| 484 | assert source_mapping.map_to_client("<cell1>", 5) == (filename, 3, True) |
| 485 | assert source_mapping.map_to_client("<cell1>", 6) == (filename, 4, True) |
| 486 | assert source_mapping.map_to_client("<cell1>", 7) == (filename, 5, True) |
| 487 | assert source_mapping.map_to_client("<cell1>", 8) == (filename, 6, True) |
| 488 | |
| 489 | assert source_mapping.map_to_client(filename, 7) == (filename, 7, False) |
| 490 | |
| 491 | assert source_mapping.map_to_client("<cell2>", 1) == (filename, 10, True) |
| 492 | assert source_mapping.map_to_client("<cell2>", 2) == (filename, 11, True) |
| 493 | |
| 494 | assert source_mapping.map_to_client(filename, 12) == (filename, 12, False) |
| 495 | |
| 496 | |
| 497 | @pytest.mark.skipif(IS_WINDOWS, reason="Linux/Mac-only test") |
nothing calls this directly
no test coverage detected