Commit b4b8f6bc by kimth

Use with open(file) structure

parent 2919389d
...@@ -323,7 +323,8 @@ class CodeResponseTest(unittest.TestCase): ...@@ -323,7 +323,8 @@ class CodeResponseTest(unittest.TestCase):
Test whether LoncapaProblem.update_score can deliver queued result to the right subproblem Test whether LoncapaProblem.update_score can deliver queued result to the right subproblem
''' '''
problem_file = os.path.join(os.path.dirname(__file__), "test_files/coderesponse.xml") problem_file = os.path.join(os.path.dirname(__file__), "test_files/coderesponse.xml")
test_lcp = lcp.LoncapaProblem(open(problem_file).read(), '1', system=i4xs) with open(problem_file) as input_file:
test_lcp = lcp.LoncapaProblem(input_file.read(), '1', system=i4xs)
answer_ids = sorted(test_lcp.get_question_answers().keys()) answer_ids = sorted(test_lcp.get_question_answers().keys())
num_answers = len(answer_ids) num_answers = len(answer_ids)
...@@ -379,7 +380,8 @@ class CodeResponseTest(unittest.TestCase): ...@@ -379,7 +380,8 @@ class CodeResponseTest(unittest.TestCase):
Test whether the LoncapaProblem knows about the time of queue requests Test whether the LoncapaProblem knows about the time of queue requests
''' '''
problem_file = os.path.join(os.path.dirname(__file__), "test_files/coderesponse.xml") problem_file = os.path.join(os.path.dirname(__file__), "test_files/coderesponse.xml")
test_lcp = lcp.LoncapaProblem(open(problem_file).read(), '1', system=i4xs) with open(problem_file) as input_file:
test_lcp = lcp.LoncapaProblem(input_file.read(), '1', system=i4xs)
answer_ids = sorted(test_lcp.get_question_answers().keys()) answer_ids = sorted(test_lcp.get_question_answers().keys())
num_answers = len(answer_ids) num_answers = len(answer_ids)
...@@ -413,7 +415,7 @@ class CodeResponseTest(unittest.TestCase): ...@@ -413,7 +415,7 @@ class CodeResponseTest(unittest.TestCase):
Test whether file objects are converted to filenames without altering other structures Test whether file objects are converted to filenames without altering other structures
''' '''
problem_file = os.path.join(os.path.dirname(__file__), "test_files/coderesponse.xml") problem_file = os.path.join(os.path.dirname(__file__), "test_files/coderesponse.xml")
fp = open(problem_file) with open(problem_file) as fp:
answers_with_file = {'1_2_1': 'String-based answer', answers_with_file = {'1_2_1': 'String-based answer',
'1_3_1': ['answer1', 'answer2', 'answer3'], '1_3_1': ['answer1', 'answer2', 'answer3'],
'1_4_1': [fp, fp]} '1_4_1': [fp, fp]}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment