import os
import compileall
import jedi

SRC = """class Foo:
    pass

class Bar:
    pass
"""


def generate_pyc():
    with open("dummy.py", 'w') as f:
        f.write(SRC)
    compileall.compile_file("dummy.py")
    os.remove("dummy.py")


def test_pyc():
    """
    The list of completion must be greater than 2.
    """
    generate_pyc()
    s = jedi.Script("import dummy; dummy.")
    assert len(s.completions()) >= 2


if __name__ == "__main__":
    test_pyc()

import compileall
import os
import shutil
import sys

import jedi


SRC = """class Foo:
    pass

class Bar:
    pass
"""


def generate_pyc():
    with open("dummy.py", 'w') as f:
        f.write(SRC)
    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():
    """
    The list of completion must be greater than 2.
    """
    generate_pyc()
    s = jedi.Script("import dummy; dummy.")
    assert len(s.completions()) >= 2


if __name__ == "__main__":
    test_pyc()

Fix pyc test for python3
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)

+ import compileall
  import os
- import compileall
+ import shutil
+ import sys
+ 
  import jedi
+ 
  
  SRC = """class Foo:
      pass
  
  class Bar:
      pass
  """
  
  
  def generate_pyc():
      with open("dummy.py", 'w') as f:
          f.write(SRC)
      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():
      """
      The list of completion must be greater than 2.
      """
      generate_pyc()
      s = jedi.Script("import dummy; dummy.")
      assert len(s.completions()) >= 2
  
  
  if __name__ == "__main__":
      test_pyc()
  
Fix pyc test for python3
## Code Before:
import os
import compileall
import jedi

SRC = """class Foo:
    pass

class Bar:
    pass
"""


def generate_pyc():
    with open("dummy.py", 'w') as f:
        f.write(SRC)
    compileall.compile_file("dummy.py")
    os.remove("dummy.py")


def test_pyc():
    """
    The list of completion must be greater than 2.
    """
    generate_pyc()
    s = jedi.Script("import dummy; dummy.")
    assert len(s.completions()) >= 2


if __name__ == "__main__":
    test_pyc()

## Instruction:
Fix pyc test for python3
## Code After:
import compileall
import os
import shutil
import sys

import jedi


SRC = """class Foo:
    pass

class Bar:
    pass
"""


def generate_pyc():
    with open("dummy.py", 'w') as f:
        f.write(SRC)
    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():
    """
    The list of completion must be greater than 2.
    """
    generate_pyc()
    s = jedi.Script("import dummy; dummy.")
    assert len(s.completions()) >= 2


if __name__ == "__main__":
    test_pyc()
