Esempio n. 1
0
def send_to_judge(review, priority=0):
    try:
        with open(review.submit.file_path(), "rb") as submitted_file:
            submitted_source = submitted_file.read()

            submit_id = str(review.id)
            user_id = "%s-%s" % (
                submit_settings.JUDGE_INTERFACE_IDENTITY,
                str(review.submit.user.id),
            )

            original_filename = unidecode(review.submit.filename)
            task_id = review.submit.receiver.configuration.get(
                "inputs_folder_at_judge",
                import_string(
                    submit_settings.JUDGE_DEFAULT_INPUTS_FOLDER_FOR_RECEIVER)(
                        review.submit.receiver),
            )
            language = os.path.splitext(original_filename)[1][1:]

            judge_client = JudgeClient(
                submit_settings.JUDGE_INTERFACE_IDENTITY,
                submit_settings.JUDGE_ADDRESS,
                submit_settings.JUDGE_PORT,
            )
            judge_client.submit(submit_id, user_id, task_id, submitted_source,
                                language, priority)

    except:
        raise JudgeConnectionError
Esempio n. 2
0
    def test_parse_corrupted_protocol_rises(self):
        self.judge_client = JudgeClient('test', 'test', 0)

        protocol = '''<protokol><runLog>
        <test><name>0.sample.a.in</name><resultCode>1</resultCode><resultMsg>OK</resultMsg><time>28</time></test>
        <test><nam
        '''
        with self.assertRaises(ProtocolCorruptedError):
            self.judge_client.parse_protocol(protocol, 100)
Esempio n. 3
0
class ProtocolParsingTests(TestCase):
    def test_parse_protocol(self):
        self.judge_client = JudgeClient('test', 'test', 0)

        protocol = '''<protokol><runLog>
        <test><name>0.sample.a.in</name><resultCode>1</resultCode><resultMsg>OK</resultMsg><time>28</time></test>
        <test><name>0.sample.b.in</name><resultCode>1</resultCode><resultMsg>OK</resultMsg><time>28</time></test>
        <test><name>1.a.in</name><resultCode>1</resultCode><resultMsg>OK</resultMsg><time>0</time></test>
        <test><name>1.b.in</name><resultCode>1</resultCode><resultMsg>OK</resultMsg><time>0</time></test>
        <test><name>2.a.in</name><resultCode>2</resultCode><resultMsg>WA</resultMsg><time>0</time></test>
        <test><name>2.b.in</name><resultCode>2</resultCode><resultMsg>WA</resultMsg><time>0</time></test>
        <test><name>3.a.in</name><resultCode>3</resultCode><resultMsg>TLE</resultMsg><time>0</time></test>
        <test><name>3.b.in</name><resultCode>3</resultCode><resultMsg>TLE</resultMsg><time>0</time></test>
        <test><name>3.a.in</name><resultCode>7</resultCode><resultMsg>IGN</resultMsg><time>0</time></test>
        <test><name>3.b.in</name><resultCode>7</resultCode><resultMsg>IGN</resultMsg><time>0</time></test>
        <score>25</score><details>
        Score: 25
        </details><finalResult>2</finalResult><finalMessage>Wrong Answer (OK: 25 %)</finalMessage></runLog></protokol>
        '''
        parsed_protocol = self.judge_client.parse_protocol(protocol, 100)

        self.assertEqual(parsed_protocol.result, 'WA')
        self.assertEqual(parsed_protocol.points, 25)
        self.assertEqual(len(parsed_protocol.tests), 10)

    def test_parse_corrupted_protocol_rises(self):
        self.judge_client = JudgeClient('test', 'test', 0)

        protocol = '''<protokol><runLog>
        <test><name>0.sample.a.in</name><resultCode>1</resultCode><resultMsg>OK</resultMsg><time>28</time></test>
        <test><nam
        '''
        with self.assertRaises(ProtocolCorruptedError):
            self.judge_client.parse_protocol(protocol, 100)

    def test_parse_missing_score_rises(self):
        self.judge_client = JudgeClient('test', 'test', 0)

        protocol = '''<protokol><runLog>
        <test><name>0.sample.a.in</name><resultCode>1</resultCode><resultMsg>OK</resultMsg><time>28</time></test>
        <test><name>0.sample.b.in</name><resultCode>1</resultCode><resultMsg>OK</resultMsg><time>28</time></test>
        <test><name>1.a.in</name><resultCode>1</resultCode><resultMsg>OK</resultMsg><time>0</time></test>
        <test><name>1.b.in</name><resultCode>1</resultCode><resultMsg>OK</resultMsg><time>0</time></test>
        <test><name>2.a.in</name><resultCode>2</resultCode><resultMsg>WA</resultMsg><time>0</time></test>
        <test><name>2.b.in</name><resultCode>2</resultCode><resultMsg>WA</resultMsg><time>0</time></test>
        <test><name>3.a.in</name><resultCode>3</resultCode><resultMsg>TLE</resultMsg><time>0</time></test>
        <test><name>3.b.in</name><resultCode>3</resultCode><resultMsg>TLE</resultMsg><time>0</time></test>
        <test><name>3.a.in</name><resultCode>7</resultCode><resultMsg>IGN</resultMsg><time>0</time></test>
        <test><name>3.b.in</name><resultCode>7</resultCode><resultMsg>IGN</resultMsg><time>0</time></test>
        <details>
        Score: 25
        </details><finalResult>2</finalResult><finalMessage>Wrong Answer (OK: 25 %)</finalMessage></runLog></protokol>
        '''
        with self.assertRaises(ProtocolFormatError):
            self.judge_client.parse_protocol(protocol, 100)
Esempio n. 4
0
    def setUp(self):
        self.port = get_free_port_number()

        def run_fake_server(test):
            with closing(socket.socket()) as server_sock:
                server_sock.bind((test.TESTER_URL, self.port))
                server_sock.listen(0)
                conn, addr = server_sock.accept()
                raw = conn.recv(2048)
                data = conn.recv(2048)
                test.received = raw + data
                time.sleep(100.0 / 1000.0)

        self.judge_client = JudgeClient(self.TESTER_ID, self.TESTER_URL,
                                        self.port)
        self.server_thread = threading.Thread(target=run_fake_server,
                                              args=(self, ))
        self.server_thread.start()
        time.sleep(50.0 /
                   1000.0)  # 50ms should be enough for the server to bind
Esempio n. 5
0
    def test_parse_missing_score_rises(self):
        self.judge_client = JudgeClient('test', 'test', 0)

        protocol = '''<protokol><runLog>
        <test><name>0.sample.a.in</name><resultCode>1</resultCode><resultMsg>OK</resultMsg><time>28</time></test>
        <test><name>0.sample.b.in</name><resultCode>1</resultCode><resultMsg>OK</resultMsg><time>28</time></test>
        <test><name>1.a.in</name><resultCode>1</resultCode><resultMsg>OK</resultMsg><time>0</time></test>
        <test><name>1.b.in</name><resultCode>1</resultCode><resultMsg>OK</resultMsg><time>0</time></test>
        <test><name>2.a.in</name><resultCode>2</resultCode><resultMsg>WA</resultMsg><time>0</time></test>
        <test><name>2.b.in</name><resultCode>2</resultCode><resultMsg>WA</resultMsg><time>0</time></test>
        <test><name>3.a.in</name><resultCode>3</resultCode><resultMsg>TLE</resultMsg><time>0</time></test>
        <test><name>3.b.in</name><resultCode>3</resultCode><resultMsg>TLE</resultMsg><time>0</time></test>
        <test><name>3.a.in</name><resultCode>7</resultCode><resultMsg>IGN</resultMsg><time>0</time></test>
        <test><name>3.b.in</name><resultCode>7</resultCode><resultMsg>IGN</resultMsg><time>0</time></test>
        <details>
        Score: 25
        </details><finalResult>2</finalResult><finalMessage>Wrong Answer (OK: 25 %)</finalMessage></runLog></protokol>
        '''
        with self.assertRaises(ProtocolFormatError):
            self.judge_client.parse_protocol(protocol, 100)
Esempio n. 6
0
    def test_parse_protocol(self):
        self.judge_client = JudgeClient('test', 'test', 0)

        protocol = '''<protokol><runLog>
        <test><name>0.sample.a.in</name><resultCode>1</resultCode><resultMsg>OK</resultMsg><time>28</time></test>
        <test><name>0.sample.b.in</name><resultCode>1</resultCode><resultMsg>OK</resultMsg><time>28</time></test>
        <test><name>1.a.in</name><resultCode>1</resultCode><resultMsg>OK</resultMsg><time>0</time></test>
        <test><name>1.b.in</name><resultCode>1</resultCode><resultMsg>OK</resultMsg><time>0</time></test>
        <test><name>2.a.in</name><resultCode>2</resultCode><resultMsg>WA</resultMsg><time>0</time></test>
        <test><name>2.b.in</name><resultCode>2</resultCode><resultMsg>WA</resultMsg><time>0</time></test>
        <test><name>3.a.in</name><resultCode>3</resultCode><resultMsg>TLE</resultMsg><time>0</time></test>
        <test><name>3.b.in</name><resultCode>3</resultCode><resultMsg>TLE</resultMsg><time>0</time></test>
        <test><name>3.a.in</name><resultCode>7</resultCode><resultMsg>IGN</resultMsg><time>0</time></test>
        <test><name>3.b.in</name><resultCode>7</resultCode><resultMsg>IGN</resultMsg><time>0</time></test>
        <score>25</score><details>
        Score: 25
        </details><finalResult>2</finalResult><finalMessage>Wrong Answer (OK: 25 %)</finalMessage></runLog></protokol>
        '''
        parsed_protocol = self.judge_client.parse_protocol(protocol, 100)

        self.assertEqual(parsed_protocol.result, 'WA')
        self.assertEqual(parsed_protocol.points, 25)
        self.assertEqual(len(parsed_protocol.tests), 10)
Esempio n. 7
0
class JudgeClientTests(TestCase):
    TESTER_URL = '127.0.0.1'
    TESTER_ID = 'TEST'

    def setUp(self):
        self.port = get_free_port_number()

        def run_fake_server(test):
            with closing(socket.socket()) as server_sock:
                server_sock.bind((test.TESTER_URL, self.port))
                server_sock.listen(0)
                conn, addr = server_sock.accept()
                raw = conn.recv(2048)
                data = conn.recv(2048)
                test.received = raw + data
                time.sleep(100.0 / 1000.0)

        self.judge_client = JudgeClient(self.TESTER_ID, self.TESTER_URL,
                                        self.port)
        self.server_thread = threading.Thread(target=run_fake_server,
                                              args=(self, ))
        self.server_thread.start()
        time.sleep(50.0 /
                   1000.0)  # 50ms should be enough for the server to bind

    def test_submit(self):
        self.judge_client.submit('test_id', 'test_user', 'test_task',
                                 'test_submission ščť', 'py')
        self.server_thread.join()

        request_parts = self.received.split(b'\n')
        # Header
        self.assertEqual(request_parts[0], b'submit1.3')
        self.assertEqual(request_parts[1], b'TEST')
        self.assertEqual(request_parts[2], b'test_id')
        self.assertEqual(request_parts[3], b'test_user')
        self.assertEqual(request_parts[4], b'test_task')
        self.assertEqual(request_parts[5], b'py')
        self.assertEqual(request_parts[6], b'0')
        self.assertEqual(request_parts[7], b'magic_footer')
        # Submission
        self.assertEqual(request_parts[8].decode('utf-8'),
                         'test_submission ščť')

    def test_submit_with_priority(self):
        self.judge_client.submit('test_id', 'test_user', 'test_task',
                                 'test_submission', 'py', 1)
        self.server_thread.join()

        request_parts = self.received.split(b'\n')
        # Header
        self.assertEqual(request_parts[0], b'submit1.3')
        self.assertEqual(request_parts[1], b'TEST')
        self.assertEqual(request_parts[2], b'test_id')
        self.assertEqual(request_parts[3], b'test_user')
        self.assertEqual(request_parts[4], b'test_task')
        self.assertEqual(request_parts[5], b'py')
        self.assertEqual(request_parts[6], b'1')
        self.assertEqual(request_parts[7], b'magic_footer')
        # Submission
        self.assertEqual(request_parts[8], b'test_submission')