Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
ebb26247
Commit
ebb26247
authored
Feb 19, 2013
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make jailpy tests more convenient and informative.
parent
7c498be6
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
6 deletions
+14
-6
common/lib/codejail/codejail/tests/test_jailpy.py
+14
-6
No files found.
common/lib/codejail/codejail/tests/test_jailpy.py
View file @
ebb26247
...
@@ -8,10 +8,17 @@ from codejail.jailpy import jailpy
...
@@ -8,10 +8,17 @@ from codejail.jailpy import jailpy
dedent
=
textwrap
.
dedent
dedent
=
textwrap
.
dedent
class
TestFeatures
(
unittest
.
TestCase
):
class
JailPyHelpers
(
object
):
"""Assert helpers for jailpy tests."""
def
assertResultOk
(
self
,
res
):
self
.
assertEqual
(
res
.
stderr
,
""
)
self
.
assertEqual
(
res
.
status
,
0
)
class
TestFeatures
(
JailPyHelpers
,
unittest
.
TestCase
):
def
test_hello_world
(
self
):
def
test_hello_world
(
self
):
res
=
jailpy
(
"print 'Hello, world!'"
)
res
=
jailpy
(
"print 'Hello, world!'"
)
self
.
assert
Equal
(
res
.
status
,
0
)
self
.
assert
ResultOk
(
res
)
self
.
assertEqual
(
res
.
stdout
,
'Hello, world!
\n
'
)
self
.
assertEqual
(
res
.
stdout
,
'Hello, world!
\n
'
)
def
test_argv
(
self
):
def
test_argv
(
self
):
...
@@ -19,7 +26,7 @@ class TestFeatures(unittest.TestCase):
...
@@ -19,7 +26,7 @@ class TestFeatures(unittest.TestCase):
"import sys; print ':'.join(sys.argv[1:])"
,
"import sys; print ':'.join(sys.argv[1:])"
,
argv
=
[
"Hello"
,
"world"
,
"-x"
]
argv
=
[
"Hello"
,
"world"
,
"-x"
]
)
)
self
.
assert
Equal
(
res
.
status
,
0
)
self
.
assert
ResultOk
(
res
)
self
.
assertEqual
(
res
.
stdout
,
"Hello:world:-x
\n
"
)
self
.
assertEqual
(
res
.
stdout
,
"Hello:world:-x
\n
"
)
def
test_ends_with_exception
(
self
):
def
test_ends_with_exception
(
self
):
...
@@ -38,10 +45,11 @@ class TestFeatures(unittest.TestCase):
...
@@ -38,10 +45,11 @@ class TestFeatures(unittest.TestCase):
"import json,sys; print sum(json.load(sys.stdin))"
,
"import json,sys; print sum(json.load(sys.stdin))"
,
stdin
=
"[1, 2.5, 33]"
stdin
=
"[1, 2.5, 33]"
)
)
self
.
assertResultOk
(
res
)
self
.
assertEqual
(
res
.
stdout
.
strip
(),
"36.5"
)
self
.
assertEqual
(
res
.
stdout
.
strip
(),
"36.5"
)
class
TestLimits
(
unittest
.
TestCase
):
class
TestLimits
(
JailPyHelpers
,
unittest
.
TestCase
):
def
test_cant_use_too_much_memory
(
self
):
def
test_cant_use_too_much_memory
(
self
):
res
=
jailpy
(
"print sum(range(100000000))"
)
res
=
jailpy
(
"print sum(range(100000000))"
)
self
.
assertNotEqual
(
res
.
status
,
0
)
self
.
assertNotEqual
(
res
.
status
,
0
)
...
@@ -78,7 +86,7 @@ class TestLimits(unittest.TestCase):
...
@@ -78,7 +86,7 @@ class TestLimits(unittest.TestCase):
# TODO: read network
# TODO: read network
# TODO: fork
# TODO: fork
class
TestMalware
(
unittest
.
TestCase
):
class
TestMalware
(
JailPyHelpers
,
unittest
.
TestCase
):
def
test_crash_cpython
(
self
):
def
test_crash_cpython
(
self
):
# http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html
# http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html
res
=
jailpy
(
dedent
(
"""
\
res
=
jailpy
(
dedent
(
"""
\
...
@@ -119,5 +127,5 @@ class TestMalware(unittest.TestCase):
...
@@ -119,5 +127,5 @@ class TestMalware(unittest.TestCase):
print "Files in
%
r:
%
r"
%
(place, files)
print "Files in
%
r:
%
r"
%
(place, files)
print "Done."
print "Done."
"""
))
"""
))
self
.
assert
Equal
(
res
.
status
,
0
)
self
.
assert
ResultOk
(
res
)
self
.
assertEqual
(
res
.
stdout
,
"Done.
\n
"
)
self
.
assertEqual
(
res
.
stdout
,
"Done.
\n
"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment