def test_install_latest_version(self): tmp_dir = self.make_temp_dir() options = pip_project_options(root_dir = tmp_dir, python_exe = python_testing._PYTHONS.ANY_PYTHON3, debug = self.DEBUG) project = pip_project(options = options) project.install('pyinstaller') rv = project.call_program([ 'pyinstaller', '--version' ]) self.assertEqual( 0, rv.exit_code )
def test_install_invalid_package(self): tmp_dir = self.make_temp_dir() options = pip_project_options(root_dir = tmp_dir, python_exe = python_testing._PYTHONS.ANY_PYTHON3, debug = self.DEBUG) project = pip_project(options = options) with self.assertRaises(pip_error) as ctx: project.install('somethingthatdoesntexistshaha') self.assertTrue( 'no matching distribution found for somethingthatdoesntexistshaha' in str(ctx.exception).lower() )
def test_install_invalid_version(self): tmp_dir = self.make_temp_dir() options = pip_project_options(root_dir = tmp_dir, python_exe = python_testing._PYTHONS.ANY_PYTHON3, debug = self.DEBUG) project = pip_project(options = options) with self.assertRaises(pip_error) as ctx: project.install('pyinstaller', version = '666.666.666.666.666') print('ex={}'.format(str(ctx.exception).lower())) self.assertTrue( 'no matching distribution found for pyinstaller==666.666.666.666.666' in str(ctx.exception).lower() )
def _make_pip_project(self, version): infos = python_exe.find_all_exes_info(key_by_version=True) assert version in infos info = infos[version] pp_root_dir = self._dir_for_version(version) pp_options = pip_project_options(debug=self._options.debug, verbose=self._options.verbose, blurber=self._options.blurber, root_dir=pp_root_dir, python_exe=info.exe) return pip_project(pp_options)
def test_install_specific_version(self): tmp_dir = self.make_temp_dir() options = pip_project_options(root_dir = tmp_dir, python_exe = python_testing._PYTHONS.ANY_PYTHON3, debug = self.DEBUG) project = pip_project(options = options) project.install('pyinstaller', version = '3.5') rv = project.call_program([ 'pyinstaller', '--version' ]) self.assertEqual( '3.5', rv.stdout.strip() ) self.assertEqual( '3.5', project.version('pyinstaller') ) self.assertTrue( project.needs_upgrade('pyinstaller') )
def test_persistence(self): tmp_dir = self.make_temp_dir() options = pip_project_options(root_dir = tmp_dir, python_exe = python_testing._PYTHONS.ANY_PYTHON3, debug = self.DEBUG) p1 = pip_project(options = options) p1.install('pyinstaller', version = '3.5') rv = p1.call_program([ 'pyinstaller', '--version' ]) self.assertEqual( '3.5', p1.version('pyinstaller') ) p2 = pip_project(options = options) p2.install('pyinstaller', version = '3.5') rv = p2.call_program([ 'pyinstaller', '--version' ]) self.assertEqual( '3.5', p2.version('pyinstaller') )
def test_upgrade(self): tmp_dir = self.make_temp_dir() options = pip_project_options(root_dir = tmp_dir, python_exe = python_testing._PYTHONS.ANY_PYTHON3, debug = self.DEBUG) project = pip_project(options = options) project.install('pyinstaller', version = '3.5') rv = project.call_program([ 'pyinstaller', '--version' ]) old_version = semantic_version(project.version('pyinstaller')) self.assertEqual( '3.5', old_version ) project.upgrade('pyinstaller') new_version = semantic_version(project.version('pyinstaller')) self.assertTrue( new_version > old_version )
def __init__(self, options = None): check.check_pipenv_project_options(options, allow_none = True) self._options = options or pipenv_project_options() pp_options = pip_project_options(debug = self._options.debug, verbose = self._options.verbose, blurber = self._options.blurber, root_dir = self._options.root_dir, python_version = self._options.python_version) self._pip_project = pip_project(pp_options) self._pipenv_cache_dir = path.join(self._pip_project.droppings_dir, 'pipenv-cache') extra_env = { 'WORKON_HOME': self._pip_project.root_dir, 'PIPENV_VENV_IN_PROJECT': '1', 'PIPENV_CACHE_DIR': self._pipenv_cache_dir, } self._pip_project.extra_env = extra_env self._ensure_installed()
def test_make_from_address(self): tmp_dir = self.make_temp_dir(suffix='.test_make_from_address', ) venvs_dir = path.join(tmp_dir, 'venvs') pp_options = pip_project_options( root_dir=venvs_dir, python_exe=python_testing._PYTHONS.ANY_PYTHON3, debug=self.DEBUG) project = pip_project(options=pp_options) for p in project.PYTHONPATH: sys.path.insert(0, p) options = egg_options(setup_filename='setup.py', version_filename='lib/bes/ver.py', verbose=self.DEBUG, debug=self.DEBUG) result = egg.make_from_address( 'https://github.com/reconstruir/bes.git', '1.2.62', options=options, python_exe=project.python_exe) print('result={}'.format(result))
def test_build(self): tmp_dir = self.make_temp_dir(suffix='.test_pyinstaller_build', ) venvs_dir = path.join(tmp_dir, 'venvs') options = pip_project_options( root_dir=venvs_dir, python_exe=python_testing._PYTHONS.ANY_PYTHON3, debug=self.DEBUG) project = pip_project(options=options) project.install('pyinstaller', version='4.8') program_content = r''' #!/usr/bin/env python3 import sys def test_re(): 'Test that re works' import re C = re.compile('^foo.*$') sys.stdout.write('test_re:') def test_threading(): 'Test that threading works' import threading def worker(): sys.stdout.write('test_threading:') return t = threading.Thread(target = worker) t.start() t.join() def test_subprocess(): 'Test that subprocess works' import subprocess import platform if platform.system() == 'Windows': args = [ 'cmd', '/c', 'echo test_subprocess:' ] else: args = [ 'echo', 'test_subprocess:' ] p = subprocess.check_output(args) sys.stdout.write(p.decode('utf8').strip()) def test_subprocess_with_shell(): 'Test that subprocess with shell = True works' import subprocess p = subprocess.check_output('echo test_subprocess_with_shell:', shell = True) sys.stdout.write(p.decode('utf8').strip()) def test_json_hidden(): 'Test that using a stdlib module like json works by importing it hidden (not explicit)' exec('import json', locals(), globals()) s = json.dumps({'foo': 'hi'}) sys.stdout.write('test_json_hidden:') def test_fakelib1(): 'Test that we can use something in a custom import.' from fakelib1 import fakelib1 sys.stdout.write(fakelib1().something) def test_fakelib2_hidden(): 'Test that using a personal module like fakelib works by importing it hidden (not explicit)' exec('from fakelib2 import fakelib2', locals(), globals()) sys.stdout.write(fakelib2().something) tests = [ test_re, test_threading, test_subprocess, test_subprocess_with_shell, test_json_hidden, test_fakelib1, test_fakelib2_hidden, ] for test in tests: test() #import json #from fakelib.foo import foo #f = foo() #sys.stdout.write(f.something) sys.stdout.write('\n') sys.stdout.flush() raise SystemExit() ''' program_source = file_util.save(path.join(tmp_dir, 'program', 'program.py'), content=program_content) fakelib1_content = r''' class fakelib1(object): def __init__(self): self.something = 'test_fakelib1:' ''' fakelib2_content = r''' class fakelib2(object): def __init__(self): self.something = 'test_fakelib2_hidden:' ''' file_util.save(path.join(tmp_dir, 'program', 'fakelib1.py'), content=fakelib1_content) file_util.save(path.join(tmp_dir, 'program', 'fakelib2.py'), content=fakelib2_content) for p in project.PYTHONPATH: sys.path.insert(0, p) from bes.pyinstaller.pyinstaller_build import pyinstaller_build from bes.pyinstaller.pyinstaller_options import pyinstaller_options build_dir = path.join(tmp_dir, 'BUILD') options = pyinstaller_options( verbose=True, log_level='INFO', hidden_imports=['json', 'fakelib1', 'fakelib2'], build_dir=build_dir, replace_env=project.env) build_result = pyinstaller_build.build(program_source, options=options) self.assertTrue(path.exists(build_result.output_exe)) rv = execute.execute(build_result.output_exe, raise_error=False) self.assertEqual(0, rv.exit_code) expected = 'test_re:test_threading:test_subprocess:test_subprocess_with_shell:test_json_hidden:test_fakelib1:test_fakelib2_hidden:' self.assertEqual(expected, rv.stdout.strip())