summaryrefslogtreecommitdiff
path: root/testapp/test_server.py
diff options
context:
space:
mode:
Diffstat (limited to 'testapp/test_server.py')
-rw-r--r--testapp/test_server.py73
1 files changed, 58 insertions, 15 deletions
diff --git a/testapp/test_server.py b/testapp/test_server.py
index 2a17739..d22a022 100644
--- a/testapp/test_server.py
+++ b/testapp/test_server.py
@@ -16,7 +16,6 @@ def check_result(result, check='correct answer'):
assert result[0], result[1]
assert check in result[1].lower(), result[1]
-
def test_python():
"""Test if server runs Python code as expected."""
src = 'while True: pass'
@@ -24,16 +23,16 @@ def test_python():
check_result(result, 'more than ')
src = 'x = 1'
result = code_server.run_code(src, 'assert x == 1', '/tmp',
- language="python")
+ language="python")
check_result(result, 'correct answer')
result = code_server.run_code(src, 'assert x == 0', '/tmp',
- language="python")
+ language="python")
check_result(result, 'assertionerror')
src = 'abracadabra'
result = code_server.run_code(src, 'assert x == 0', '/tmp',
- language="python")
+ language="python")
check_result(result, 'nameerror')
@@ -202,12 +201,55 @@ def test_java():
int square_num(int a)
{
return a+b
-
"""
result = code_server.run_code(src, 'java_files/main_square.java',
'/tmp', language="java")
check_result(result, 'error')
+def test_scilab():
+ """Test if server runs scilab code as expected."""
+ src = """
+ funcprot(0)
+function[c]=add(a,b)
+ c=a+b;
+endfunction
+ """
+ result = code_server.run_code(src, 'scilab_files/test_add.sce',
+ '/tmp', language="scilab")
+ check_result(result, 'correct answer')
+
+ src = """
+ funcprot(0)
+function[c]=add(a,b)
+ c=a-b;
+endfunction
+ """
+ result = code_server.run_code(src, 'scilab_files/test_add.sce',
+ '/tmp', language="scilab")
+ check_result(result, 'correct answer')
+
+ src = """
+ funcprot(0)
+function[c]=add(a,b)
+ c=a+b;
+dis(
+endfunction
+ """
+ result = code_server.run_code(src, 'scilab_files/test_add.sce',
+ '/tmp', language="scilab")
+ check_result(result, 'error')
+
+ src = """
+ funcprot(0)
+function[c]=add(a,b)
+ c=a
+ while(1==1)
+ end
+endfunction
+ """
+ result = code_server.run_code(src, 'scilab_files/test_add.sce',
+ '/tmp', language="scilab")
+ check_result(result, 'error')
def test_bash():
"""Test if server runs Bash code as expected."""
@@ -215,40 +257,40 @@ def test_bash():
#!/bin/bash
[[ $# -eq 2 ]] && echo $(( $1 + $2 )) && exit $(( $1 + $2 ))
"""
- result = code_server.run_code(src,
- 'docs/sample.sh\ndocs/sample.args', '/tmp', language="bash")
+ result = code_server.run_code(src, 'docs/sample.sh\ndocs/sample.args',
+ '/tmp', language="bash")
check_result(result)
src = """
#!/bin/bash
[[ $# -eq 2 ]] && echo $(( $1 - $2 )) && exit $(( $1 - $2 ))
"""
- result = code_server.run_code(src,
- 'docs/sample.sh\ndocs/sample.args', '/tmp', language="bash")
+ result = code_server.run_code(src, 'docs/sample.sh\ndocs/sample.args',
+ '/tmp', language="bash")
check_result(result, 'error')
src = """\
#!/bin/bash
while [ 1 ] ; do echo "" > /dev/null ; done
"""
- result = code_server.run_code(src,
- 'docs/sample.sh\ndocs/sample.args', '/tmp', language="bash")
+ result = code_server.run_code(src, 'docs/sample.sh\ndocs/sample.args',
+ '/tmp', language="bash")
check_result(result, 'more than ')
src = '''
#!/bin/bash
while [ 1 ] ; do echo "" > /dev/null
'''
- result = code_server.run_code(src,
- 'docs/sample.sh\ndocs/sample.args', '/tmp', language="bash")
+ result = code_server.run_code(src, 'docs/sample.sh\ndocs/sample.args',
+ '/tmp', language="bash")
check_result(result, 'error')
src = '''# Enter your code here.
#!/bin/bash
while [ 1 ] ; do echo "" > /dev/null
'''
- result = code_server.run_code(src,
- 'docs/sample.sh\ndocs/sample.args', '/tmp', language="bash")
+ result = code_server.run_code(src, 'docs/sample.sh\ndocs/sample.args',
+ '/tmp', language="bash")
check_result(result, 'oserror')
if __name__ == '__main__':
@@ -257,3 +299,4 @@ if __name__ == '__main__':
test_c()
test_cpp()
test_java()
+ test_scilab()