MCPcopy Create free account
hub / github.com/fabioz/PyDev.Debugger / test_relative_paths

Function test_relative_paths

tests_python/test_convert_utilities.py:350–390  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

348
349
350def 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
393def test_zip_paths(tmpdir):

Callers

nothing calls this directly

Calls 5

appendMethod · 0.45
clearMethod · 0.45
joinMethod · 0.45
writeMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected