Beispiel #1
0
    def create_suite(self, test_types):
        """
        Create test suite and add test cases to it.

        test_types      Test classes to create test cases from.

        Return test suite with tests.
        """
        suite = unittest.TestSuite()

        for _type in test_types:
            tests = self._detect_tests(_type.test_dir)
            # Create test cases for a specific type.
            for test_name in tests:
                suite.addTest(_type(test_name))

        return suite
Beispiel #2
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()

    global VERBOSE, REPORT
    VERBOSE = opts.verbose
    REPORT = opts.junitxml is not None

    # 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)

    # Run created test suite.
    clean()
    run_tests(suite, opts.junitxml)
Beispiel #3
0
def one_test():
    suite = unittest.TestSuite()
    suite.addTest(TestCollectSubmodules('test_4'))
    unittest.TextTestRunner().run(suite)
Beispiel #4
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)))
Beispiel #5
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()

    global VERBOSE
    VERBOSE = opts.verbose

    # Do only cleanup.
    if opts.clean:
        clean()
        raise SystemExit()

    # Run only single specified tests.
    if args:
        if opts.interactive_tests:
            parser.error(
                'Must not specify -i/--interactive-tests when passing test names.'
            )
        test_dir = os.path.dirname(args[0])
        test_script = os.path.basename(os.path.splitext(args[0])[0])
        suite = unittest.TestSuite()
        suite.addTest(GenericTestCase(test_dir, test_script))
        print 'Running single 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)

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