| 391 | |
| 392 | |
| 393 | def test_zip_paths(tmpdir): |
| 394 | import pydevd_file_utils |
| 395 | import sys |
| 396 | import zipfile |
| 397 | |
| 398 | for i, zip_basename in enumerate(("MY1.zip", "my2.egg!")): |
| 399 | zipfile_path = str(tmpdir.join(zip_basename)) |
| 400 | zip_file = zipfile.ZipFile(zipfile_path, "w") |
| 401 | zip_file.writestr("zipped%s/__init__.py" % (i,), "") |
| 402 | zip_file.writestr("zipped%s/zipped_contents.py" % (i,), "def call_in_zip():\n return 1") |
| 403 | zip_file.close() |
| 404 | |
| 405 | sys.path.append(zipfile_path) |
| 406 | try: |
| 407 | import importlib |
| 408 | except ImportError: |
| 409 | __import__("zipped%s" % (i,)) # Py2.6 does not have importlib |
| 410 | else: |
| 411 | importlib.import_module("zipped%s" % (i,)) # Check that it's importable. |
| 412 | |
| 413 | # Check that we can deal with the zip path. |
| 414 | assert pydevd_file_utils.exists(zipfile_path) |
| 415 | abspath, realpath, basename = pydevd_file_utils.get_abs_path_real_path_and_base_from_file(zipfile_path) |
| 416 | if IS_WINDOWS or IS_MAC: |
| 417 | assert abspath == zipfile_path |
| 418 | assert basename == zip_basename.lower() |
| 419 | else: |
| 420 | assert abspath == zipfile_path |
| 421 | assert basename == zip_basename |
| 422 | |
| 423 | # Check that we can deal with zip contents. |
| 424 | for path in [ |
| 425 | zipfile_path + "/zipped%s/__init__.py" % (i,), |
| 426 | zipfile_path + "/zipped%s/zipped_contents.py" % (i,), |
| 427 | zipfile_path + "\\zipped%s\\__init__.py" % (i,), |
| 428 | zipfile_path + "\\zipped%s\\zipped_contents.py" % (i,), |
| 429 | ]: |
| 430 | assert pydevd_file_utils.exists(path), "Expected exists to return True for path:\n%s" % (path,) |
| 431 | abspath, realpath, basename = pydevd_file_utils.get_abs_path_real_path_and_base_from_file(path) |
| 432 | assert pydevd_file_utils.exists(abspath), "Expected exists to return True for path:\n%s" % (abspath,) |
| 433 | assert pydevd_file_utils.exists(realpath), "Expected exists to return True for path:\n%s" % (realpath,) |
| 434 | |
| 435 | assert zipfile_path in pydevd_file_utils._ZIP_SEARCH_CACHE, "%s not in %s" % ( |
| 436 | zipfile_path, |
| 437 | "\n".join(sorted(pydevd_file_utils._ZIP_SEARCH_CACHE.keys())), |
| 438 | ) |
| 439 | |
| 440 | |
| 441 | def test_source_mapping(): |