Ejemplo n.º 1
0
def test_fix_getcwd():
    code = """
    getcwd()
    os.getcwd()
    """
    new_code = LegacyPythonTranslator(code).translate()
    assert new_code.count('getcwd(') == 0
    assert new_code.count('getcwdu(') == 2
Ejemplo n.º 2
0
def copy_for_legacy_python(src_dir, dest_dir):
    from translate_to_legacy import LegacyPythonTranslator
    # Dirs and files to explicitly not translate
    skip = ['tests/python_sample.py', 
            'tests/python_sample2.py',
            'tests/python_sample3.py']
    # Make a fresh copy of the package
    if os.path.isdir(dest_dir):
        shutil.rmtree(dest_dir)
    ignore = lambda src, names: [n for n in names if n == '__pycache__']
    shutil.copytree(src_dir, dest_dir, ignore=ignore)
    # Translate in-place
    LegacyPythonTranslator.translate_dir(dest_dir, skip=skip)
Ejemplo n.º 3
0
def copy_for_legacy_python(src_dir, dest_dir):
    from translate_to_legacy import LegacyPythonTranslator
    # Dirs and files to explicitly not translate
    skip = ['pyscript/tests/python_sample.py', 
            'pyscript/tests/python_sample2.py',
            'pyscript/tests/python_sample3.py']
    # Make a fresh copy of the flexx package
    if os.path.isdir(dest_dir):
        shutil.rmtree(dest_dir)
    ignore = lambda src, names: [n for n in names if n == '__pycache__']
    shutil.copytree(src_dir, dest_dir, ignore=ignore)
    # Translate in-place
    LegacyPythonTranslator.translate_dir(dest_dir, skip=skip)
Ejemplo n.º 4
0
def copy_for_legacy_python(src_dir, dest_dir):
    if sys.argv[1:] != ['install']:
        raise RuntimeError('Setup.py can only be used to "install" on Python 2.x')
    from translate_to_legacy import LegacyPythonTranslator
    # Dirs and files to explicitly not translate
    ignore_dirs = ['__pycache__']
    skip = ['pyscript/tests/python_sample.py', 
            'pyscript/tests/python_sample2.py',
            'pyscript/tests/python_sample3.py']
    # Make a copy of the flexx package
    if os.path.isdir(dest_dir):
        shutil.rmtree(dest_dir)
    shutil.copytree(src_dir, dest_dir,
                    ignore=lambda src, names: [n for n in names if n in ignore_dirs])
    # Translate in-place
    LegacyPythonTranslator.translate_dir(dest_dir, skip=skip)
Ejemplo n.º 5
0
def test_fix_future():
    code = """
    foo = 2
    """
    new_code = LegacyPythonTranslator(code).translate()
    assert new_code.count('from __future__ import ') == 1
    assert new_code.index('__future__') < new_code.index('foo')
    
    code = """
    # bla
    'docstring'
    foo = 2
    """
    new_code = LegacyPythonTranslator(code).translate()
    assert new_code.count('from __future__ import ') == 1
    assert new_code.index('__future__') < new_code.index('foo')
    assert new_code.index('__future__') > new_code.index('bla')
    assert new_code.index('__future__') > new_code.index('docstring')
Ejemplo n.º 6
0
def copy_for_legacy_python(src_dir, dest_dir):
    if sys.argv[1:] != ['install']:
        raise RuntimeError(
            'Setup.py can only be used to "install" on Python 2.x')
    from translate_to_legacy import LegacyPythonTranslator
    # Dirs and files to explicitly not translate
    ignore_dirs = ['__pycache__']
    skip = [
        'pyscript/tests/python_sample.py', 'pyscript/tests/python_sample2.py',
        'pyscript/tests/python_sample3.py'
    ]
    # Make a copy of the flexx package
    if os.path.isdir(dest_dir):
        shutil.rmtree(dest_dir)
    shutil.copytree(
        src_dir,
        dest_dir,
        ignore=lambda src, names: [n for n in names if n in ignore_dirs])
    # Translate in-place
    LegacyPythonTranslator.translate_dir(dest_dir, skip=skip)