示例#1
0
    def test_killing_process_revives_it(self):
        # Given
        testdata = {
            'metadata': {
                'user_answer': 'import sys; sys.exit()',
                'language': 'python',
                'partial_grading': False
            },
            'test_case_data': [{
                'test_case': '',
                'test_case_type': 'standardtestcase',
                'weight': 0.0
            }]
        }

        # When
        submit(self.url, '0', json.dumps(testdata), '')
        result = get_result(self.url, '0', block=True)

        # Then
        data = json.loads(result.get('result'))
        self.assertFalse(data['success'])
        self.assertTrue('Process ended with exit code' in data['error'][0])

        # Now check the server status to see if the right number
        # processes are running.
        url = "http://localhost:%s/" % SERVER_POOL_PORT

        # When
        response = urllib.request.urlopen(url)
        data = response.read().decode('utf-8')

        # Then
        expect = '5 processes, 0 running, 0 queued'
        self.assertTrue(expect in data)
示例#2
0
    def test_infinite_loop(self):
        # Given
        testdata = {
            'metadata': {
                'user_answer': 'while True: pass',
                'language': 'python',
                'partial_grading': False
            },
            'test_case_data': [{
                'test_case': 'assert 1==2',
                'test_case_type': 'standardtestcase',
                'weight': 0.0
            }]
        }

        # When
        submit(self.url, '0', json.dumps(testdata), '')
        result = get_result(self.url, '0')

        # Then
        self.assertTrue(result.get('status') in ['running', 'not started'])

        # When
        result = get_result(self.url, '0', block=True)

        # Then
        data = json.loads(result.get('result'))
        self.assertFalse(data['success'])
        self.assertTrue('infinite loop' in data['error'][0]['message'])
示例#3
0
 def run_code(uid):
     """Run an infinite loop."""
     testdata = {
         'metadata': {
             'user_answer': 'while True: pass',
             'language': 'python',
             'partial_grading': False
         },
         'test_case_data': [{
             'test_case': 'assert 1==2',
             'test_case_type': 'standardtestcase',
             'weight': 0.0
         }]
     }
     submit(self.url, uid, json.dumps(testdata), '')
     result = get_result(self.url, uid, block=True)
     results.put(json.loads(result.get('result')))
示例#4
0
    def test_correct_answer(self):
        # Given
        testdata = {
            'metadata': {
                'user_answer': 'def f(): return 1',
                'language': 'python',
                'partial_grading': False
            },
            'test_case_data': [{
                'test_case': 'assert f() == 1',
                'test_case_type': 'standardtestcase',
                'weight': 0.0
            }]
        }

        # When
        submit(self.url, '0', json.dumps(testdata), '')
        result = get_result(self.url, '0', block=True)

        # Then
        data = json.loads(result.get('result'))
        self.assertTrue(data['success'])