コード例 #1
0
ファイル: command_download.py プロジェクト: ryo-n/oj
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)
コード例 #2
0
    def test_call_submit_atcoder_invalid_url(self):

        url = 'https://atcoder.jp/contests/practice/tasks/practice_111'
        code = '''\
        #include <bits/stdc++.h>
        using namespace std;
        int main() {
            int a; cin >> a;
            int b, c; cin >> b >> c;
            string s; cin >> s;
            cout << a + b + c << ' ' << s << endl;
            return 0;
        }
        '''
        files = [
            {
                'path': 'main.cpp',
                'data': code
            },
        ]

        with tests.utils.sandbox(files):
            with self.assertRaises(requests.exceptions.HTTPError):
                args = ["submit", '-y', '--no-open', url, 'main.cpp']
                args = get_parser().parse_args(args=args)
                submit(args)
コード例 #3
0
def snippet_call_download_failure(self, 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)
    self.assertFalse(subcommand_download.run(args))
コード例 #4
0
ファイル: command_download.py プロジェクト: ryo-n/oj
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)