mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Fix pyc test for python3
To import pyc modules, we must move them out of the __pycache__ directory and rename them to remove ".cpython-%s%d". This should still faild with python3 (UnicodeDecodeError)
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
"""
|
||||
Test completions from *.pyc files:
|
||||
|
||||
- generated a dummy python module
|
||||
- generate a dummy python module
|
||||
- compile the dummy module to generate a *.pyc
|
||||
- delete the pure python dummy module
|
||||
- try jedi on the generated *.pyc
|
||||
"""
|
||||
import os
|
||||
import compileall
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
import jedi
|
||||
|
||||
|
||||
SRC = """class Foo:
|
||||
pass
|
||||
|
||||
@@ -24,6 +28,15 @@ def generate_pyc():
|
||||
compileall.compile_file("dummy.py")
|
||||
os.remove("dummy.py")
|
||||
|
||||
if sys.version_info[0] == 3:
|
||||
# Python3 specific:
|
||||
# To import pyc modules, we must move them out of the __pycache__
|
||||
# directory and rename them to remove ".cpython-%s%d"
|
||||
# see: http://stackoverflow.com/questions/11648440/python-does-not-detect-pyc-files
|
||||
for f in os.listdir("__pycache__"):
|
||||
dst = f.replace('.cpython-%s%s' % sys.version_info[:2], "")
|
||||
shutil.copy(os.path.join("__pycache__", f), dst)
|
||||
|
||||
|
||||
def test_pyc():
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user