def main():
    capabilities = ['GENERIC']
    platform_capabilities = {
        'linux2': 'X11',
        'win32': 'WIN',
        'cygwin': 'WIN',
        'darwin': 'OSX'
    }
    if sys.platform in platform_capabilities:
        capabilities.append(platform_capabilities[sys.platform])

    script_root = os.path.dirname(__file__)
    plan_filename = os.path.normpath(os.path.join(script_root, 'plan.txt'))
    test_root = script_root
 
    op = optparse.OptionParser()
    op.usage = 'test.py [options] [components]'
    op.add_option('--plan', help='test plan file', default=plan_filename)
    op.add_option('--test-root', default=script_root,
        help='directory containing test cases')
    op.add_option('--capabilities', help='selected test capabilities',
        default=','.join(capabilities))
    op.add_option('--log-level', help='verbosity of logging',
        default=10, type='int')
    op.add_option('--log-file', help='log to FILE', metavar='FILE', 
        default='pyglet.%d.log')
    op.add_option('--regression-path', metavar='DIR', default=regressions_path,
        help='locate regression images in DIR')
    op.add_option('--regression-tolerance', type='int', default=2,
        help='tolerance for comparing regression images')
    op.add_option('--regression-check', action='store_true',
        help='enable image regression checks')
    op.add_option('--regression-capture', action='store_true',
        help='enable image regression capture')
    op.add_option('--no-interactive', action='store_false', default=True,
        dest='interactive', help='disable interactive prompting')
    op.add_option('--developer', action='store_true',
        help='add DEVELOPER capability')
    op.add_option('--pretend', action='store_true',
        help='print selected test cases only')

    options, args = op.parse_args()

    options.capabilities = set(options.capabilities.split(','))
    if options.developer:
        options.capabilities.add('DEVELOPER')

    if options.regression_capture:
        try:
            os.makedirs(regressions_path)
        except __HOLE__:
            pass

    if '%d' in options.log_file: 
        i = 1
        while os.path.exists(options.log_file % i):
            i += 1
        options.log_file = options.log_file % i

    logging.basicConfig(filename=options.log_file, level=options.log_level)
    options.log = logging.getLogger()

    options.log.info('Beginning test at %s', time.ctime())
    options.log.info('Capabilities are: %s', ', '.join(options.capabilities))
    options.log.info('sys.platform = %s', sys.platform)
    options.log.info('Reading test plan from %s', options.plan)
    plan = TestPlan.from_file(options.plan)

    errors = False
    if args:
        components = []
        for arg in args:
            try:
                component = plan.names[arg]
                components.append(component)
            except KeyError:
                options.log.error('Unknown test case or section "%s"', arg)
                errors = True
    else:
        components = [plan.root]

    if not errors:
        print '-' * 78
        for component in components:
            component.test(options)
        print '-' * 78
dataset/ETHPy150Open ardekantur/pyglet/tests/test.py/main