Skip to content
This repository was archived by the owner on Jul 22, 2022. It is now read-only.

Commit 15f50fb

Browse files
committed
Add PyPy support
1 parent 60043d8 commit 15f50fb

File tree

5 files changed

+62
-3
lines changed

5 files changed

+62
-3
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ install:
2222
- docker pull golang:1 # For go
2323
- docker pull python:3 # For python3
2424
- docker pull python:2 # For python2
25+
- docker pull pypy:3 # For pypy3
26+
- docker pull pypy:2 # For pypy2
2527
- docker pull node:12 # For node
2628
- docker pull openjdk # For javac and java
2729
- docker pull clangbuiltlinux/ubuntu:llvm10-latest # For clang-10 & clang++-10

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
- [`node`](https://nodejs.org/en/download/)
3232
- [Python](https://www.python.org/)
3333
- [CPython](https://www.python.org/downloads/)
34+
- [PyPy](https://www.pypy.org/)
3435

3536

3637
## Installation
@@ -241,14 +242,22 @@ sudo make install # python3 setup.py install
241242
b''
242243
]
243244
>>>
244-
>>> judge(Python(3), b"print('Hello, world!')", [(b'', b'Hello, world!')]) # Python
245+
>>> judge(Python(3), b"print('Hello, world!')", [(b'', b'Hello, world!')]) # Python 3
245246
[
246247
[
247248
(<Status.AC: 'Accepted'>, (b'Hello, world!\n', b''), 0.05)
248249
],
249250
b"Listing '.'...\n"
250251
b"Compiling './__init__.py'...\n"
251252
]
253+
>>> judge(PyPy(), b"print('Hello, world!')", [(b'', b'Hello, world!')]) # PyPy 3
254+
[
255+
[
256+
(<Status.AC: 'Accepted'>, (b'Hello, world!\n', b''), 0.075)
257+
],
258+
b"Listing '.'...\n"
259+
b"Compiling './__init__.py'...\n"
260+
]
252261
>>>
253262
>>> judge(Node(12), b'console.log("Hello World")', [(b'', b'Hello World')]) # Node.js
254263
[

README.zh_Hans_CN.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
- [`node`](https://nodejs.org/zh-cn/download/)
3232
- [Python](https://www.python.org/)
3333
- [CPython](https://www.python.org/downloads/)
34+
- [PyPy](https://www.pypy.org/)
3435

3536

3637
## 安装
@@ -241,14 +242,22 @@ sudo make install # python3 setup.py install
241242
b''
242243
]
243244
>>>
244-
>>> judge(Python(3), b"print('Hello, world!')", [(b'', b'Hello, world!')]) # Python
245+
>>> judge(Python(3), b"print('Hello, world!')", [(b'', b'Hello, world!')]) # Python 3
245246
[
246247
[
247248
(<Status.AC: 'Accepted'>, (b'Hello, world!\n', b''), 0.05)
248249
],
249250
b"Listing '.'...\n"
250251
b"Compiling './__init__.py'...\n"
251252
]
253+
>>> judge(PyPy(), b"print('Hello, world!')", [(b'', b'Hello, world!')]) # PyPy 3
254+
[
255+
[
256+
(<Status.AC: 'Accepted'>, (b'Hello, world!\n', b''), 0.075)
257+
],
258+
b"Listing '.'...\n"
259+
b"Compiling './__init__.py'...\n"
260+
]
252261
>>>
253262
>>> judge(Node(12), b'console.log("Hello World")', [(b'', b'Hello World')]) # Node.js
254263
[

dockerjudge/processor.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,18 @@ def __init__(self, version=None):
147147
self.judge = 'java Main'
148148

149149

150+
class PyPy(Processor):
151+
'PyPy'
152+
153+
def __init__(self, version=None):
154+
pypy = 'pypy' if str(version).startswith('2') else 'pypy3'
155+
156+
self.image = self._get_image_with_tag('pypy', version)
157+
self.source = '__init__.py'
158+
self.compile = [pypy, '-m', 'compileall', '.']
159+
self.judge = f'{pypy} {self.source}'
160+
161+
150162
class Python(Processor):
151163
'CPython'
152164

test_dockerjudge.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import unittest
66

77
from dockerjudge import judge
8-
from dockerjudge.processor import Clang, GCC, Go, Node, OpenJDK, Python, Bash
8+
from dockerjudge.processor import (Bash, Clang, GCC, Go, Node, OpenJDK,
9+
PyPy, Python)
910
from dockerjudge.status import Status
1011

1112

@@ -31,6 +32,10 @@ def test_Go(self):
3132
self.assertEqual(Go(None, {'src': 'golang.go'}).source, 'golang.go')
3233
self.assertEqual(Go(None, {'bin': 'golang'}).judge, './golang')
3334

35+
def test_PyPy(self):
36+
self.assertEqual(PyPy().compile, PyPy(3).compile)
37+
self.assertEqual(PyPy().judge, PyPy(3).judge)
38+
3439

3540
class TestDockerJudge(unittest.TestCase):
3641

@@ -275,6 +280,28 @@ def test_CE(self):
275280
self.assertFalse(result[0][1][1][0])
276281
self.assertFalse(result[0][1][1][1])
277282

283+
def test_pypy(self):
284+
result = judge(
285+
PyPy(2),
286+
b'a, b = [int(i) for i in raw_input().split()]; print a / b',
287+
[(b'1 1', b'1'), (b'1 2', b'0.5'), (b'0 0', b'')]
288+
)
289+
self.assertEqual(result[0][0][0], Status.AC)
290+
self.assertEqual(result[0][1][0], Status.WA)
291+
self.assertEqual(result[0][2][0], Status.RE)
292+
self.assertTrue(result[0][2][1][1])
293+
294+
def test_pypy3(self):
295+
result = judge(
296+
PyPy(3),
297+
b'a, b = [int(i) for i in input().split()]; print(a / b)',
298+
[(b'1 1', b'1'), (b'1 2', b'0.5'), (b'0 0', b'')]
299+
)
300+
self.assertEqual(result[0][0][0], Status.WA)
301+
self.assertEqual(result[0][1][0], Status.AC)
302+
self.assertEqual(result[0][2][0], Status.RE)
303+
self.assertTrue(result[0][2][1][1])
304+
278305

279306
class TestGoLang(unittest.TestCase):
280307

0 commit comments

Comments
 (0)