def __init__(self, func_name, test_dir=None, with_crypto=False, run_known_fails=False): """ func_name Name of test function to create. """ if test_dir is not None: self.test_dir = test_dir self.test_name = self.test_dir + '/' + func_name self.run_known_fails = run_known_fails # Create new test fuction. This has to be done before super(). setattr(self, func_name, self._generic_test_function) super(GenericTestCase, self).__init__(func_name) # For tests current working directory has to be changed temporaly. self.curr_workdir = compat.getcwd() # Whether to enable bytecode encryption for test executable self.with_crypto = with_crypto
def __init__(self, test_name, verbose=False, report=False, with_crypto=False): # Use path separator '/' even on windows for test_name name. self.test_name = test_name.replace('\\', '/') self.verbose = verbose self.test_dir, self.test_file = os.path.split(self.test_name) runtests_basedir = compat.getenv('PYINSTALLER_RUNTESTS_WORKDIR') if runtests_basedir: runtests_basedir = os.path.join(runtests_basedir, self.test_dir) if not os.path.exists(runtests_basedir): os.makedirs(runtests_basedir) else: runtests_basedir = compat.getcwd() self._specdir = runtests_basedir self._distdir = os.path.join(runtests_basedir, 'dist') self._builddir = os.path.join(runtests_basedir, 'build') # For junit xml report some behavior is changed. # Especially redirecting sys.stdout. self.report = report # Build the test executable with bytecode encryption enabled. self.with_crypto = with_crypto
def _run_created_exe(self, prog): """ Run executable created by PyInstaller. """ # Run the test in a clean environment to make sure they're # really self-contained path = compat.getenv('PATH') compat.unsetenv('PATH') # For Windows we need to keep minimal PATH for sucessful running of some tests. if is_win: # Minimum Windows PATH is in most cases: C:\Windows\system32;C:\Windows compat.setenv('PATH', os.pathsep.join(winutils.get_system_path())) self._plain_msg("RUNNING: " + prog) old_wd = compat.getcwd() os.chdir(os.path.dirname(prog)) # Run executable. prog = os.path.join(os.curdir, os.path.basename(prog)) proc = subprocess.Popen([prog], stdout=subprocess.PIPE, stderr=subprocess.PIPE) # Prints stdout of subprocess continuously. self._msg('STDOUT %s' % self.test_name) while proc.poll() is None: # We need to read a line, not single bytes. Otherwise decoding # would ail. line = proc.stdout.readline() self._plain_msg(line.decode('utf-8'), newline=False) # Print any stdout that wasn't read before the process terminated. # See the conversation in https://github.com/pyinstaller/pyinstaller/pull/1092 # for examples of why this is necessary. self._plain_msg(proc.stdout.read().decode('utf-8'), newline=False) # Print possible stderr at the end. stderr = proc.stderr.read().decode('utf-8') self._msg('STDERR %s' % self.test_name) self._plain_msg(stderr) compat.setenv("PATH", path) # Restore current working directory os.chdir(old_wd) return proc.returncode, stderr
def main(scripts, name=None, onefile=0, console=True, debug=False, strip=0, noupx=0, comserver=0, workdir=None, pathex=[], version_file=None, icon_file=None, manifest=None, resources=[], hiddenimports=None, hookspath=None, runtime_hooks=[], **kwargs): if not name: name = os.path.splitext(os.path.basename(scripts[0]))[0] distdir = "dist" builddir = os.path.join('build', 'pyi.' + sys.platform, name) pathex = pathex[:] if workdir is None: workdir = getcwd() pathex.append(workdir) else: pathex.append(getcwd()) if workdir == HOMEPATH: workdir = os.path.join(HOMEPATH, name) if not os.path.exists(workdir): os.makedirs(workdir) exe_options = '' if version_file: exe_options = "%s, version='%s'" % (exe_options, quote_win_filepath(version_file)) if icon_file: exe_options = "%s, icon='%s'" % (exe_options, quote_win_filepath(icon_file)) if manifest: if "<" in manifest: # Assume XML string exe_options = "%s, manifest='%s'" % (exe_options, manifest.replace("'", "\\'")) else: # Assume filename exe_options = "%s, manifest='%s'" % (exe_options, quote_win_filepath(manifest)) if resources: resources = map(quote_win_filepath, resources) exe_options = "%s, resources=%s" % (exe_options, repr(resources)) hiddenimports = hiddenimports or [] scripts = map(Path, scripts) d = { 'scripts': scripts, 'pathex': pathex, 'hiddenimports': hiddenimports, 'hookspath': hookspath, 'runtime_hooks': runtime_hooks, # List with custom runtime hook files. #'exename': '', 'name': name, 'distdir': repr(distdir), 'builddir': repr(builddir), 'debug': debug, 'strip': strip, 'upx': not noupx, 'console': console or debug, 'exe_options': exe_options } if is_win or is_cygwin: d['exename'] = name + '.exe' d['dllname'] = name + '.dll' else: d['exename'] = name # only Windows and Mac OS X distinguish windowed and console apps if not is_win and not is_darwin: d['console'] = True specfnm = os.path.join(workdir, name + '.spec') specfile = open(specfnm, 'w') if onefile: specfile.write(onefiletmplt % d) if not console: specfile.write(bundleexetmplt % d) elif comserver: specfile.write(comsrvrtmplt % d) if not console: specfile.write(bundletmplt % d) else: specfile.write(onedirtmplt % d) if not console: specfile.write(bundletmplt % d) specfile.close() return specfnm
def __init__(self, path): if path == '': path = getcwd() if not os.path.isdir(path): raise OwnerError("%s is not a directory" % repr(path)) Owner.__init__(self, path)
CONFIGDIR = compat.getenv('APPDATA') if not CONFIGDIR: CONFIGDIR = os.path.expanduser('~\\Application Data') elif is_darwin: CONFIGDIR = os.path.expanduser('~/Library/Application Support') else: # According to XDG specification # http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html CONFIGDIR = compat.getenv('XDG_DATA_HOME') if not CONFIGDIR: CONFIGDIR = os.path.expanduser('~/.local/share') CONFIGDIR = os.path.join(CONFIGDIR, 'pyinstaller') ## Default values of paths where to put files created by PyInstaller. # Folder where to put created .spec file. DEFAULT_SPECPATH = compat.getcwd() # Folder where to put created .spec file. # Where to put the final app. DEFAULT_DISTPATH = os.path.join(compat.getcwd(), 'dist') # Where to put all the temporary work files, .log, .pyz and etc. DEFAULT_WORKPATH = os.path.join(compat.getcwd(), 'build') PLATFORM = compat.system() + '-' + compat.architecture() # Include machine name in path to bootloader for some machines. # e.g. 'arm' if compat.machine(): PLATFORM += '-' + compat.machine() # path extensions for module seach # FIXME this should not be a global variable __pathex__ = []
if not CONFIGDIR: CONFIGDIR = os.path.expanduser('~\\Application Data') elif is_darwin: CONFIGDIR = os.path.expanduser('~/Library/Application Support') else: # According to XDG specification # http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html CONFIGDIR = compat.getenv('XDG_DATA_HOME') if not CONFIGDIR: CONFIGDIR = os.path.expanduser('~/.local/share') CONFIGDIR = os.path.join(CONFIGDIR, 'pyinstaller') ## Default values of paths where to put files created by PyInstaller. # Folder where to put created .spec file. DEFAULT_SPECPATH = compat.getcwd() # Folder where to put created .spec file. # Where to put the final app. DEFAULT_DISTPATH = os.path.join(compat.getcwd(), 'dist') # Where to put all the temporary work files, .log, .pyz and etc. DEFAULT_WORKPATH = os.path.join(compat.getcwd(), 'build') PLATFORM = compat.system() + '-' + compat.architecture() # Include machine name in path to bootloader for some machines. # e.g. 'arm' if compat.machine(): PLATFORM += '-' + compat.machine() # path extensions for module seach
def main(scripts, name=None, onefile=0, console=True, debug=False, strip=0, noupx=0, comserver=0, workdir=None, pathex=[], version_file=None, icon_file=None, manifest=None, resources=[], hiddenimports=None, hookspath=None, runtime_hooks=[], **kwargs): if not name: name = os.path.splitext(os.path.basename(scripts[0]))[0] distdir = "dist" builddir = os.path.join('build', 'pyi.' + sys.platform, name) pathex = pathex[:] if workdir is None: workdir = getcwd() pathex.append(workdir) else: pathex.append(getcwd()) if workdir == HOMEPATH: workdir = os.path.join(HOMEPATH, name) if not os.path.exists(workdir): os.makedirs(workdir) exe_options = '' if version_file: exe_options = "%s, version='%s'" % (exe_options, quote_win_filepath(version_file)) if icon_file: exe_options = "%s, icon='%s'" % (exe_options, quote_win_filepath(icon_file)) if manifest: if "<" in manifest: # Assume XML string exe_options = "%s, manifest='%s'" % (exe_options, manifest.replace("'", "\\'")) else: # Assume filename exe_options = "%s, manifest='%s'" % (exe_options, quote_win_filepath(manifest)) if resources: resources = map(quote_win_filepath, resources) exe_options = "%s, resources=%s" % (exe_options, repr(resources)) hiddenimports = hiddenimports or [] scripts = map(Path, scripts) d = {'scripts': scripts, 'pathex': pathex, 'hiddenimports': hiddenimports, 'hookspath': hookspath, 'runtime_hooks': runtime_hooks, # List with custom runtime hook files. #'exename': '', 'name': name, 'distdir': repr(distdir), 'builddir': repr(builddir), 'debug': debug, 'strip': strip, 'upx': not noupx, 'console': console or debug, 'exe_options': exe_options} if is_win or is_cygwin: d['exename'] = name + '.exe' d['dllname'] = name + '.dll' else: d['exename'] = name # only Windows and Mac OS X distinguish windowed and console apps if not is_win and not is_darwin: d['console'] = True specfnm = os.path.join(workdir, name + '.spec') specfile = open(specfnm, 'w') if onefile: specfile.write(onefiletmplt % d) if not console: specfile.write(bundleexetmplt % d) elif comserver: specfile.write(comsrvrtmplt % d) if not console: specfile.write(bundletmplt % d) else: specfile.write(onedirtmplt % d) if not console: specfile.write(bundletmplt % d) specfile.close() return specfnm