Ejemplo n.º 1
0
class SubmitAtCoderTest(unittest.TestCase):
    @unittest.skipIf(not tests.utils.is_logged_in(AtCoderService()), 'login is required')
    def test_call_submit_practice_1(self):

        url = 'https://atcoder.jp/contests/practice/tasks/practice_1'
        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):
            tests.utils.run(['submit', '-y', '--no-open', url, 'main.cpp'], check=True)

    @unittest.skipIf(not tests.utils.is_logged_in(AtCoderService()), 'login is required')
    def test_call_submit_practice_2(self):

        url = 'https://atcoder.jp/contests/practice/tasks/practice_2'
        code = '''\
# Python Version: 3.x
import string
import sys
def quick_sort(s):
    if len(s) <= 1:
        return s
    pivot = s[0]
    lo, hi = '', ''
    for c in s[1 :]:
        print('?', pivot, c)
        sys.stdout.flush()
        if input() == '<':
            hi += c
        else:
            lo += c
    return quick_sort(lo) + pivot + quick_sort(hi)
n, q = map(int, input().split())
assert n == 26 and q == 1000
print('!', ''.join(quick_sort(string.ascii_uppercase[: n])))
'''
        files = [
            {
                'path': 'main.py',
                'data': code
            },
        ]

        with tests.utils.sandbox(files):
            tests.utils.run(['submit', '-y', '--no-open', url, 'main.py'], check=True)
Ejemplo n.º 2
0
 def test_from_url(self):
     self.assertIsInstance(AtCoderService.from_url('https://atcoder.jp/'),
                           AtCoderService)
     self.assertIsInstance(
         AtCoderService.from_url('https://beta.atcoder.jp/'),
         AtCoderService)
     self.assertIsInstance(
         AtCoderService.from_url('https://abc001.contest.atcoder.jp/'),
         AtCoderService)
     self.assertIsInstance(
         AtCoderService.from_url(
             'https://atcoder.jp/contests/agc001/submissions/806160'),
         AtCoderService)
     self.assertIsNone(AtCoderService.from_url('https://codeforces.com/'))
Ejemplo n.º 3
0
class LoginTest(unittest.TestCase):
    def snippet_call_login_check_failure(self, url):
        with tests.utils.sandbox(files=[]) as tempdir:
            path = 'cookie.jar'  # use dummy cookie to check in an empty state
            proc = tests.utils.run(['--cookie', path, 'login', '--check', url])
            self.assertEqual(proc.returncode, 1)

    def snippet_call_login_check_success(self, url):
        tests.utils.run(['login', '--check', url], check=True)

    def test_call_login_check_atcoder_failure(self):
        self.snippet_call_login_check_failure('https://atcoder.jp/')

    def test_call_login_check_codeforces_failure(self):
        self.snippet_call_login_check_failure('https://codeforces.com/')

    def test_call_login_check_hackerrank_failure(self):
        self.snippet_call_login_check_failure('https://www.hackerrank.com/')

    def test_call_login_check_topcoder_failure(self):
        self.snippet_call_login_check_failure(
            'https://community.topcoder.com/')

    def test_call_login_check_toph_failure(self):
        self.snippet_call_login_check_failure('https://toph.co/')

    def test_call_login_check_yukicoder_failure(self):
        self.snippet_call_login_check_failure('https://yukicoder.me/')

    @unittest.skipIf(not tests.utils.is_logged_in(AtCoderService()),
                     'login is required')
    def test_call_login_check_atcoder_success(self):
        self.snippet_call_login_check_success('https://atcoder.jp/')

    @unittest.skipIf(not tests.utils.is_logged_in(CodeforcesService()),
                     'login is required')
    def test_call_login_check_codeforces_success(self):
        self.snippet_call_login_check_success('https://codeforces.com/')

    @unittest.skipIf(not tests.utils.is_logged_in(HackerRankService()),
                     'login is required')
    def test_call_login_check_hackerrank_success(self):
        self.snippet_call_login_check_success('https://www.hackerrank.com/')

    @unittest.skipIf(not tests.utils.is_logged_in(TopcoderService()),
                     'login is required')
    def test_call_login_check_topcoder_success(self):
        self.snippet_call_login_check_success(
            'https://community.topcoder.com/')

    @unittest.skipIf(not tests.utils.is_logged_in(TophService()),
                     'login is required')
    def test_call_login_check_toph_success(self):
        self.snippet_call_login_check_success('https://toph.co/')

    @unittest.skipIf(not tests.utils.is_logged_in(YukicoderService()),
                     'login is required')
    def test_call_login_check_yukicoder_success(self):
        self.snippet_call_login_check_success('https://yukicoder.me/')
Ejemplo n.º 4
0
 def test_iterate_contests(self):
     contests = list(AtCoderService().iterate_contests())
     contest_ids = [contest.contest_id for contest in contests]
     self.assertIn('arc001', contest_ids)
     self.assertIn('abc100', contest_ids)
     self.assertIn('kupc2012', contest_ids)
     contest, = [contest for contest in contests if contest.contest_id == 'utpc2013']
     self.assertEqual(contest.get_start_time().year, 2014)
     self.assertEqual(contest.get_start_time().month, 3)
     self.assertEqual(contest.get_start_time().day, 2)
     self.assertEqual(contest.get_contest_name(), '東京大学プログラミングコンテスト2013')
     self.assertEqual(contest.get_duration().total_seconds(), 5 * 60 * 60)
     self.assertEqual(contest.get_rated_range(), 'All')
Ejemplo n.º 5
0
 def test_iterate_contests(self):
     contests = list(AtCoderService().iterate_contests())
     contest_ids = [contest.contest_id for contest in contests]
     self.assertIn('arc001', contest_ids)
     self.assertIn('abc100', contest_ids)
     self.assertIn('kupc2012', contest_ids)
     contest, = [contest for contest in contests if contest.contest_id == 'utpc2013']
     data = contest.download_data()
     self.assertEqual(data.start_time.year, 2014)
     self.assertEqual(data.start_time.month, 3)
     self.assertEqual(data.start_time.day, 2)
     self.assertEqual(data.name, '東京大学プログラミングコンテスト2013')
     self.assertEqual(data.duration.total_seconds(), 5 * 60 * 60)
     self.assertEqual(data.rated_range, '-')
Ejemplo n.º 6
0
class SubmitArgumentsTest(unittest.TestCase):
    @unittest.skipIf(not tests.utils.is_logged_in(AtCoderService()),
                     'login is required')
    def test_call_submit_atcoder_practice_2_with_history_simple(self):

        url = 'https://atcoder.jp/contests/practice/tasks/practice_2'
        files = [
            {
                'path': 'a.cpp',
                'data': 'compile error'
            },
        ]
        with tests.utils.sandbox(files):
            tests.utils.run(['dl', url], check=False)
            tests.utils.run(['s', '-y', '--no-open', url, 'a.cpp'], check=True)

    @unittest.skipIf(not tests.utils.is_logged_in(AtCoderService()),
                     'login is required')
    def test_call_submit_atcoder_practice_2_with_history_remove(self):

        url = 'https://atcoder.jp/contests/practice/tasks/practice_2'
        files = [
            {
                'path': 'a.cpp',
                'data': 'compile error'
            },
        ]
        with tests.utils.sandbox(files):
            tests.utils.run(
                ['dl', 'https://atcoder.jp/contests/abc099/tasks/abc099_a'],
                check=True)
            shutil.rmtree('test/')
            tests.utils.run(['dl', url], check=False)
            tests.utils.run(['s', '-y', '--no-open', url, 'a.cpp'], check=True)

    @unittest.skipIf(os.name == 'nt', "shell script doesn't work on Windows")
    @unittest.skipIf(not tests.utils.is_logged_in(AtCoderService()),
                     'login is required')
    def test_call_submit_atcoder_practice_1_with_open(self):

        url = 'https://atcoder.jp/contests/practice/tasks/practice_1'
        files = [
            {
                'path': 'a.pl',
                'data': 'print<>+(<>=~$",$`+$\'),$",<>'
            },
            {
                'path': 'browse.sh',
                'data': '#!/bin/sh\necho "$@" > url.txt\n',
                'executable': True,
            },
        ]
        with tests.utils.sandbox(files) as tempdir:
            env = dict(os.environ)
            env['BROWSER'] = os.path.join(tempdir, 'browse.sh')

            tests.utils.run(['s', '-y', '--open', url, 'a.pl'],
                            env=env,
                            check=True)
            with open('url.txt') as fh:
                url = fh.read().strip()
            self.assertTrue(
                url.startswith(
                    'https://atcoder.jp/contests/practice/submissions/'))

    @unittest.skipIf(not tests.utils.is_logged_in(AtCoderService()),
                     'login is required')
    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)
Ejemplo n.º 7
0
 def get_service(self) -> AtCoderService:
     return AtCoderService()