Esempio n. 1
0
def run_program(args: argparse.Namespace,
                parser: argparse.ArgumentParser) -> None:
    if args.version:
        print('online-judge-tools {}'.format(onlinejudge.__version__))
        sys.exit(0)
    if args.verbose:
        log.setLevel(log.logging.DEBUG)
    log.debug('args: %s', str(args))

    if args.subcommand in ['download', 'd', 'dl']:
        download(args)
    elif args.subcommand in ['login', 'l']:
        login(args)
    elif args.subcommand in ['submit', 's']:
        submit(args)
    elif args.subcommand in ['test', 't']:
        test(args)
    elif args.subcommand in ['test-reactive', 't/r']:
        test_reactive(args)
    elif args.subcommand in ['generate-output', 'g/o']:
        generate_output(args)
    elif args.subcommand in ['generate-input', 'g/i']:
        generate_input(args)
    else:
        parser.print_help(file=sys.stderr)
        sys.exit(1)
def snippet_call_download_raises(self, expected_exception, url, is_system=False, is_silent=False):
    args = ["download", url]
    if is_system:
        args.append("--system")
    if is_silent:
        args.append("--silent")
    args = get_parser().parse_args(args=args)
    with self.assertRaises(expected_exception):
        download(args)
def snippet_call_download_twice(self,
                                url1,
                                url2,
                                files,
                                is_system=False,
                                is_silent=False,
                                type='files'):
    assert type in 'files' or 'json'
    if type == 'json':
        files = get_files_from_json(files)

    with tests.utils.sandbox([]):
        args = ['download', url1]
        if is_system:
            args += ['--system']
        if is_silent:
            args += ['--silent']
        args = get_parser().parse_args(args=args)
        download(args)

        args = ['download', url2]
        if is_system:
            args += ['--system']
        if is_silent:
            args += ['--silent']
        args = get_parser().parse_args(args=args)
        # download from url2 should be aborted.
        with self.assertRaises(FileExistsError):
            download(args)

        # check download from url1 is not overwritten
        result = {}
        if os.path.exists('test'):
            for name in os.listdir('test'):
                with open(os.path.join('test', name)) as fh:
                    result[name] = hashlib.md5(fh.buffer.read()).hexdigest()
        self.assertEqual(files, result)