summaryrefslogtreecommitdiff
path: root/yaksh/evaluator_tests/test_bash_evaluation.py
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh/evaluator_tests/test_bash_evaluation.py')
-rw-r--r--[-rwxr-xr-x]yaksh/evaluator_tests/test_bash_evaluation.py27
1 files changed, 19 insertions, 8 deletions
diff --git a/yaksh/evaluator_tests/test_bash_evaluation.py b/yaksh/evaluator_tests/test_bash_evaluation.py
index 084e5e4..66ade19 100755..100644
--- a/yaksh/evaluator_tests/test_bash_evaluation.py
+++ b/yaksh/evaluator_tests/test_bash_evaluation.py
@@ -1,5 +1,8 @@
+from __future__ import unicode_literals
import unittest
import os
+import shutil
+import tempfile
from yaksh.bash_code_evaluator import BashCodeEvaluator
from yaksh.bash_stdio_evaluator import BashStdioEvaluator
from yaksh.settings import SERVER_TIMEOUT
@@ -8,15 +11,23 @@ from textwrap import dedent
class BashAssertionEvaluationTestCases(unittest.TestCase):
def setUp(self):
+ with open('/tmp/test.txt', 'wb') as f:
+ f.write('2'.encode('ascii'))
+ tmp_in_dir_path = tempfile.mkdtemp()
self.test_case_data = [
{"test_case": "bash_files/sample.sh,bash_files/sample.args"}
]
- self.in_dir = os.getcwd()
+ tmp_in_dir_path = tempfile.mkdtemp()
+ self.in_dir = tmp_in_dir_path
self.timeout_msg = ("Code took more than {0} seconds to run. "
"You probably have an infinite loop in your"
" code.").format(SERVER_TIMEOUT)
self.file_paths = None
+ def tearDown(self):
+ os.remove('/tmp/test.txt')
+ shutil.rmtree(self.in_dir)
+
def test_correct_answer(self):
user_answer = ("#!/bin/bash\n[[ $# -eq 2 ]]"
" && echo $(( $1 + $2 )) && exit $(( $1 + $2 ))"
@@ -28,7 +39,7 @@ class BashAssertionEvaluationTestCases(unittest.TestCase):
}
result = get_class.evaluate(**kwargs)
self.assertTrue(result.get('success'))
- self.assertEquals(result.get('error'), "Correct answer")
+ self.assertEqual(result.get('error'), "Correct answer")
def test_error(self):
user_answer = ("#!/bin/bash\n[[ $# -eq 2 ]] "
@@ -52,10 +63,10 @@ class BashAssertionEvaluationTestCases(unittest.TestCase):
}
result = get_class.evaluate(**kwargs)
self.assertFalse(result.get("success"))
- self.assertEquals(result.get("error"), self.timeout_msg)
+ self.assertEqual(result.get("error"), self.timeout_msg)
def test_file_based_assert(self):
- self.file_paths = [(os.getcwd()+"/yaksh/test.txt", False)]
+ self.file_paths = [('/tmp/test.txt', False)]
self.test_case_data = [
{"test_case": "bash_files/sample1.sh,bash_files/sample1.args"}
]
@@ -67,7 +78,7 @@ class BashAssertionEvaluationTestCases(unittest.TestCase):
}
result = get_class.evaluate(**kwargs)
self.assertTrue(result.get("success"))
- self.assertEquals(result.get("error"), "Correct answer")
+ self.assertEqual(result.get("error"), "Correct answer")
class BashStdioEvaluationTestCases(unittest.TestCase):
def setUp(self):
@@ -88,7 +99,7 @@ class BashStdioEvaluationTestCases(unittest.TestCase):
"test_case_data": test_case_data
}
result = get_class.evaluate(**kwargs)
- self.assertEquals(result.get('error'), "Correct answer")
+ self.assertEqual(result.get('error'), "Correct answer")
self.assertTrue(result.get('success'))
def test_array_input(self):
@@ -108,7 +119,7 @@ class BashStdioEvaluationTestCases(unittest.TestCase):
"test_case_data": test_case_data
}
result = get_class.evaluate(**kwargs)
- self.assertEquals(result.get('error'), "Correct answer")
+ self.assertEqual(result.get('error'), "Correct answer")
self.assertTrue(result.get('success'))
def test_incorrect_answer(self):
@@ -142,7 +153,7 @@ class BashStdioEvaluationTestCases(unittest.TestCase):
"test_case_data": test_case_data
}
result = get_class.evaluate(**kwargs)
- self.assertEquals(result.get('error'), "Correct answer")
+ self.assertEqual(result.get('error'), "Correct answer")
self.assertTrue(result.get('success'))
if __name__ == '__main__':