We need to check that we can deal with relative paths. Use cases: - Relative path of file that does not exist: Use case is a cython-generated module which is generated from a .pyx which is not distributed. In this case we need to resolve the file to a librar
(tmpdir)
| 348 | |
| 349 | |
| 350 | def test_relative_paths(tmpdir): |
| 351 | """ |
| 352 | We need to check that we can deal with relative paths. |
| 353 | |
| 354 | Use cases: |
| 355 | - Relative path of file that does not exist: |
| 356 | Use case is a cython-generated module which is generated from a .pyx which |
| 357 | is not distributed. In this case we need to resolve the file to a library path file. |
| 358 | |
| 359 | - Relative path of a file that exists but not when resolved from the working directory: |
| 360 | Use case is a cython-generated module which is generated from a .pyx which is |
| 361 | distributed. In this case we need to resolve to the real file based on the sys.path |
| 362 | entries. |
| 363 | """ |
| 364 | import pydevd_file_utils |
| 365 | import sys |
| 366 | |
| 367 | sys.path.append(str(tmpdir)) |
| 368 | try: |
| 369 | pydevd_file_utils.NORM_PATHS_AND_BASE_CONTAINER.clear() |
| 370 | pydevd_file_utils.NORM_PATHS_CONTAINER.clear() |
| 371 | abs_path = pydevd_file_utils.get_abs_path_real_path_and_base_from_file("my_dir/my_file.pyx")[0] |
| 372 | assert "site-packages" in abs_path |
| 373 | assert os.path.normcase(str(tmpdir)) not in abs_path |
| 374 | assert not pydevd_file_utils.exists("my_dir/my_file.pyx") |
| 375 | |
| 376 | # If the relative file exists when joined with some entry in the PYTHONPATH we'll consider |
| 377 | # that the relative path points to that absolute path. |
| 378 | target_dir = os.path.join(str(tmpdir), "my_dir") |
| 379 | os.makedirs(target_dir) |
| 380 | with open(os.path.join(target_dir, "my_file.pyx"), "w") as stream: |
| 381 | stream.write("empty") |
| 382 | |
| 383 | pydevd_file_utils.NORM_PATHS_AND_BASE_CONTAINER.clear() |
| 384 | pydevd_file_utils.NORM_PATHS_CONTAINER.clear() |
| 385 | abs_path = pydevd_file_utils.get_abs_path_real_path_and_base_from_file("my_dir/my_file.pyx")[0] |
| 386 | assert "site-packages" not in abs_path |
| 387 | assert str(tmpdir) in abs_path |
| 388 | assert pydevd_file_utils.exists("my_dir/my_file.pyx") |
| 389 | finally: |
| 390 | sys.path.remove(str(tmpdir)) |
| 391 | |
| 392 | |
| 393 | def test_zip_paths(tmpdir): |