Exemplo n.º 1
0
def main(pyi_config, specfile, noconfirm, ascii=False, **kw):

    from PyInstaller.config import CONF
    CONF['noconfirm'] = noconfirm

    # Some modules are included if they are detected at build-time or
    # if a command-line argument is specified. (e.g. --ascii)
    if CONF.get('hiddenimports') is None:
        CONF['hiddenimports'] = []
    # Test unicode support.
    if not ascii:
        CONF['hiddenimports'].extend(get_unicode_modules())

    # FIXME: this should be a global import, but can't due to recursive imports
    # If configuration dict is supplied - skip configuration step.
    if pyi_config is None:
        import PyInstaller.configure as configure
        CONF.update(configure.get_config(kw.get('upx_dir')))
    else:
        CONF.update(pyi_config)

    if CONF['hasUPX']:
        setupUPXFlags()

    CONF['ui_admin'] = kw.get('ui_admin', False)
    CONF['ui_access'] = kw.get('ui_uiaccess', False)

    build(specfile, kw.get('distpath'), kw.get('workpath'),
          kw.get('clean_build'))
Exemplo n.º 2
0
    def _test_building(self, args):
        """
        Run building of test script.

        :param args: additional CLI options for PyInstaller.

        Return True if build succeded False otherwise.
        """
        default_args = ['--debug', '--noupx',
                '--specpath', self._specdir,
                '--distpath', self._distdir,
                '--workpath', self._builddir,
                '--path', _MODULES_DIR]
        default_args.extend(['--debug', '--log-level=DEBUG'])

        # Choose bundle mode.
        if self._mode == 'onedir':
            default_args.append('--onedir')
        elif self._mode == 'onefile':
            default_args.append('--onefile')
        # if self._mode is None then just the spec file was supplied.

        pyi_args = [self.script] + default_args + args
        # TODO fix return code in running PyInstaller programatically
        PYI_CONFIG = configure.get_config(upx_dir=None)
        # Override CACHEDIR for PyInstaller and put it into self.tmpdir
        PYI_CONFIG['cachedir'] = self._tmpdir
        # Speed up tests by reusing copy of basic module graph object.
        PYI_CONFIG['tests_modgraph'] = copy.deepcopy(self._modgraph)

        pyi_main.run(pyi_args, PYI_CONFIG)
        retcode = 0

        return retcode == 0
Exemplo n.º 3
0
def main(pyi_config, specfile, noconfirm, ascii=False, **kw):

    from ..config import CONF
    CONF['noconfirm'] = noconfirm

    # Some modules are included if they are detected at build-time or
    # if a command-line argument is specified. (e.g. --ascii)
    if CONF.get('hiddenimports') is None:
        CONF['hiddenimports'] = []
    # Test unicode support.
    if not ascii:
        CONF['hiddenimports'].extend(get_unicode_modules())

    # FIXME: this should be a global import, but can't due to recursive imports
    # If configuration dict is supplied - skip configuration step.
    if pyi_config is None:
        import PyInstaller.configure as configure
        CONF.update(configure.get_config(kw.get('upx_dir')))
    else:
        CONF.update(pyi_config)

    if CONF['hasUPX']:
        setupUPXFlags()

    CONF['ui_admin'] = kw.get('ui_admin', False)
    CONF['ui_access'] = kw.get('ui_uiaccess', False)

    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
Exemplo n.º 4
0
    def _test_building(self, args):
        """
        Run building of test script.

        :param args: additional CLI options for PyInstaller.

        Return True if build succeded False otherwise.
        """
        default_args = [
            '--debug=bootloader', '--noupx', '--specpath', self._specdir,
            '--distpath', self._distdir, '--workpath', self._builddir,
            '--path', _MODULES_DIR, '--log-level=DEBUG'
        ]

        # Choose bundle mode.
        if self._mode == 'onedir':
            default_args.append('--onedir')
        elif self._mode == 'onefile':
            default_args.append('--onefile')
        # if self._mode is None then just the spec file was supplied.

        pyi_args = [self.script] + default_args + args
        # TODO fix return code in running PyInstaller programatically
        PYI_CONFIG = configure.get_config(upx_dir=None)
        # Override CACHEDIR for PyInstaller and put it into self.tmpdir
        PYI_CONFIG['cachedir'] = self._tmpdir
        # Speed up tests by reusing copy of basic module graph object.
        PYI_CONFIG['tests_modgraph'] = copy.deepcopy(self._modgraph)

        pyi_main.run(pyi_args, PYI_CONFIG)
        retcode = 0

        return retcode == 0
def test_RecursionError_prints_message(tmpdir, large_import_chain,
                                       monkeypatch):
    """
    modulegraph is recursive and thus triggers RecursionError if
    nesting of imported modules is to deep. Ensure a respective
    informative message is printed if recursion error occurs.
    """
    if is_py37 and is_win:
        pytest.xfail("worker is know to crash for Py 3.7, 3.8 on Windows")
    path, script = large_import_chain

    default_args = [
        '--specpath',
        str(tmpdir),
        '--distpath',
        str(tmpdir.join("dist")),
        '--workpath',
        str(tmpdir.join("build")),
        '--path',
        str(tmpdir),
    ]

    pyi_args = [script] + default_args
    PYI_CONFIG = configure.get_config(upx_dir=None)
    PYI_CONFIG['cachedir'] = str(tmpdir)

    with pytest.raises(SystemExit) as execinfo:
        pyi_main.run(pyi_args, PYI_CONFIG)
    assert "sys.setrecursionlimit" in str(execinfo.value)
Exemplo n.º 6
0
    def _test_building(self, args):
        """
        Run building of test script.

        :param args: additional CLI options for PyInstaller.

        Return True if build succeded False otherwise.
        """
        default_args = [
            '--debug=bootloader',
            '--noupx',
            '--specpath', self._specdir,
            '--distpath', self._distdir,
            '--workpath', self._builddir,
            '--path', _get_modules_dir(self._request),
            '--log-level=INFO',
        ]   # yapf: disable

        # Choose bundle mode.
        if self._mode == 'onedir':
            default_args.append('--onedir')
        elif self._mode == 'onefile':
            default_args.append('--onefile')
        # if self._mode is None then just the spec file was supplied.

        pyi_args = [self.script] + default_args + args
        # TODO: fix return code in running PyInstaller programatically.
        PYI_CONFIG = configure.get_config(upx_dir=None)
        # Override CACHEDIR for PyInstaller and put it into self.tmpdir
        PYI_CONFIG['cachedir'] = str(self._tmpdir)

        pyi_main.run(pyi_args, PYI_CONFIG)
        retcode = 0

        return retcode == 0
Exemplo n.º 7
0
def main():
    try:
        parser = optparse.OptionParser(usage='%prog [options] [TEST-NAME ...]',
              epilog='TEST-NAME can be the name of the .py-file, '
              'the .spec-file or only the basename.')
    except TypeError:
        parser = optparse.OptionParser(usage='%prog [options] [TEST-NAME ...]')

    parser.add_option('-a', '--all-with-crypto', action='store_true',
                      help='Run the whole test suite with bytecode encryption enabled.')
    parser.add_option('-c', '--clean', action='store_true',
                      help='Clean up generated files')
    parser.add_option('-i', '--interactive-tests', action='store_true',
                      help='Run interactive tests (default: run normal tests)')
    parser.add_option('-v', '--verbose',
                      action='store_true',
                      default=False,
                      help='Verbose mode (default: %default)')
    parser.add_option('--known-fails', action='store_true',
                      dest='run_known_fails',
                      help='Run tests known to fail, too.')

    opts, args = parser.parse_args()

    # Do only cleanup.
    if opts.clean:
        clean()
        raise SystemExit()  # Exit code is 0 in this case.

    # Run only specified tests.
    if args:
        if opts.interactive_tests:
            parser.error('Must not specify -i/--interactive-tests when passing test names.')
        suite = unittest.TestSuite()
        for arg in args:
            test_list = glob.glob(arg)
            if not test_list:
                test_list = [arg]
            else:
                test_list = [x for x in test_list
                             if os.path.splitext(x)[1] in (".py", ".spec")]
            # Sort tests aplhabetically. For example test
            # basic/test_nested_launch1 depends on the executable from
            # basic/test_nested_launch0, which it runs.
            test_list.sort()
            for t in test_list:
                test_dir = os.path.dirname(t)
                test_script = os.path.basename(os.path.splitext(t)[0])
                suite.addTest(GenericTestCase(test_script, test_dir=test_dir,
                        run_known_fails=opts.run_known_fails))
                print('Running test: ', (test_dir + '/' + test_script))

    # Run all tests or all interactive tests.
    else:
        if opts.interactive_tests:
            print('Running interactive tests...')
            test_classes = [InteractiveTestCase]
        elif opts.all_with_crypto:
            print('Running normal tests with bytecode encryption...')
            # Make sure to exclude CryptoTestCase here since we are building
            # everything else with crypto enabled.
            test_classes = [BasicTestCase, ImportTestCase,
                    LibrariesTestCase, MultipackageTestCase]
        else:
            print('Running normal tests (-i for interactive tests)...')
            test_classes = [BasicTestCase, CryptoTestCase, ImportTestCase,
                    LibrariesTestCase, MultipackageTestCase]

        # Create test suite.
        generator = TestCaseGenerator()
        suite = generator.create_suite(test_classes, opts.all_with_crypto,
                                       opts.run_known_fails)

    # Set global options
    global VERBOSE, REPORT, PYI_CONFIG
    VERBOSE = opts.verbose
    # The function called by configure.get_config uses logging. So, we need to
    # set a logging level now, in addition to passing it as a "log-level=XXXX"
    # option in test_building (see the OPTS dict), in order for the logging
    # level to be consistent. Otherwise, the default logging level of INFO will
    # produce messages, then be overriden by runtest's default (when the -v /
    # --verbose option isn't specificed on runtest's command line) of ERROR
    # (again, see the OPTS dict in test_building).
    if VERBOSE:
        # logging's default of INFO is fine.
        pass
    else:
        # Set the logging level to ERROR.
        logger = logging.getLogger('PyInstaller')
        logger.setLevel(logging.ERROR)
    PYI_CONFIG = configure.get_config(upx_dir=None)  # Run configure phase only once.


    # Run created test suite.
    clean()

    result = run_tests(suite)

    sys.exit(int(bool(result.failures or result.errors)))
Exemplo n.º 8
0
def main():
    try:
        parser = optparse.OptionParser(
            usage='%prog [options] [TEST-NAME ...]',
            epilog='TEST-NAME can be the name of the .py-file, '
            'the .spec-file or only the basename.')
    except TypeError:
        parser = optparse.OptionParser(usage='%prog [options] [TEST-NAME ...]')

    parser.add_option(
        '-a',
        '--all-with-crypto',
        action='store_true',
        help='Run the whole test suite with bytecode encryption enabled.')
    parser.add_option('-c',
                      '--clean',
                      action='store_true',
                      help='Clean up generated files')
    parser.add_option('-i',
                      '--interactive-tests',
                      action='store_true',
                      help='Run interactive tests (default: run normal tests)')
    parser.add_option('-v',
                      '--verbose',
                      action='store_true',
                      default=False,
                      help='Verbose mode (default: %default)')
    parser.add_option('--junitxml',
                      action='store',
                      default=None,
                      metavar='FILE',
                      help='Create junit-xml style test report file')

    opts, args = parser.parse_args()

    # Do only cleanup.
    if opts.clean:
        clean()
        raise SystemExit()  # Exit code is 0 in this case.

    # Run only specified tests.
    if args:
        if opts.interactive_tests:
            parser.error(
                'Must not specify -i/--interactive-tests when passing test names.'
            )
        suite = unittest.TestSuite()
        for arg in args:
            test_list = glob.glob(arg)
            if not test_list:
                test_list = [arg]
            else:
                test_list = [
                    x for x in test_list
                    if os.path.splitext(x)[1] in (".py", ".spec")
                ]
            # Sort tests aplhabetically. For example test
            # basic/test_nested_launch1 depends on basic/test_nested_launch0.
            # Otherwise it would fail.
            test_list.sort()
            for t in test_list:
                test_dir = os.path.dirname(t)
                test_script = os.path.basename(os.path.splitext(t)[0])
                suite.addTest(GenericTestCase(test_dir, test_script))
                print('Running test: ', (test_dir + '/' + test_script))

    # Run all tests or all interactive tests.
    else:
        if opts.interactive_tests:
            print('Running interactive tests...')
            test_classes = [InteractiveTestCase]
        elif opts.all_with_crypto:
            print('Running normal tests with bytecode encryption...')
            # Make sure to exclude CryptoTestCase here since we are building
            # everything else with crypto enabled.
            test_classes = [
                BasicTestCase, ImportTestCase, LibrariesTestCase,
                MultipackageTestCase
            ]
        else:
            print('Running normal tests (-i for interactive tests)...')
            test_classes = [
                BasicTestCase, CryptoTestCase, ImportTestCase,
                LibrariesTestCase, MultipackageTestCase
            ]

        # Create test suite.
        generator = TestCaseGenerator()
        suite = generator.create_suite(test_classes, opts.all_with_crypto)

    # Set global options
    global VERBOSE, REPORT, PYI_CONFIG
    VERBOSE = opts.verbose
    REPORT = opts.junitxml is not None
    PYI_CONFIG = configure.get_config(
        upx_dir=None)  # Run configure phase only once.

    # Run created test suite.
    clean()

    result = run_tests(suite, opts.junitxml)

    sys.exit(int(bool(result.failures or result.errors)))
Exemplo n.º 9
0
def main():
    try:
        parser = optparse.OptionParser(usage='%prog [options] [TEST-NAME ...]',
              epilog='TEST-NAME can be the name of the .py-file, '
              'the .spec-file or only the basename.')
    except TypeError:
        parser = optparse.OptionParser(usage='%prog [options] [TEST-NAME ...]')

    parser.add_option('-c', '--clean', action='store_true',
                      help='Clean up generated files')
    parser.add_option('-i', '--interactive-tests', action='store_true',
                      help='Run interactive tests (default: run normal tests)')
    parser.add_option('-v', '--verbose',
                      action='store_true',
                      default=False,
                      help='Verbose mode (default: %default)')
    parser.add_option('--junitxml', action='store', default=None,
            metavar='FILE', help='Create junit-xml style test report file')

    opts, args = parser.parse_args()

    # Do only cleanup.
    if opts.clean:
        clean()
        raise SystemExit()  # Exit code is 0 in this case.

    # Run only specified tests.
    if args:
        if opts.interactive_tests:
            parser.error('Must not specify -i/--interactive-tests when passing test names.')
        suite = unittest.TestSuite()
        for arg in args:
            test_list = glob.glob(arg)
            if not test_list:
                test_list = [arg]
            else:
                test_list = [x for x in test_list if os.path.splitext(x)[1] == ".py"]
            # Sort tests aplhabetically. For example test
            # basic/test_nested_launch1 depends on basic/test_nested_launch0.
            # Otherwise it would fail.
            test_list.sort()
            for t in test_list:
                test_dir = os.path.dirname(t)
                test_script = os.path.basename(os.path.splitext(t)[0])
                suite.addTest(GenericTestCase(test_dir, test_script))
                print 'Running test:  %s' % (test_dir + '/' + test_script)

    # Run all tests or all interactive tests.
    else:
        if opts.interactive_tests:
            print 'Running interactive tests...'
            test_classes = [InteractiveTestCase]
        else:
            print 'Running normal tests (-i for interactive tests)...'
            test_classes = [BasicTestCase, ImportTestCase,
                    LibrariesTestCase, MultipackageTestCase]

        # Create test suite.
        generator = TestCaseGenerator()
        suite = generator.create_suite(test_classes)

    # Set global options
    global VERBOSE, REPORT, PYI_CONFIG
    VERBOSE = opts.verbose
    REPORT = opts.junitxml is not None
    PYI_CONFIG = configure.get_config(upx_dir=None)  # Run configure phase only once.


    # Run created test suite.
    clean()
    run_tests(suite, opts.junitxml)