def test_step4b(self):
     self.data[
         "DC_CODE"] = "df = pd.DataFrame(data=[1, 2, 3], columns=['b'])"
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertEqual('columnsincorrect', sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 43, 47)
예제 #2
0
 def test_fail_8(self):
     self.data[
         "DC_CODE"] = "[key + str(val) for key,val in x.items() if isinstance(key, str) if isinstance(key, str)]"
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertEqual("incorrect2", sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 80, 82)
예제 #3
0
 def test_step4(self):
     self.data["DC_CODE"] = "x.center(50, 'c')"
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertIn('Did you call <code>x.center()</code> with the correct arguments?', sct_payload['message'])
     self.assertFalse('The argument you specified for <code>fillchar</code> seems to be incorrect.' in sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 14, 16)
예제 #4
0
 def test_step3(self):
     self.data["DC_CODE"] = "x.center(50)"
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertIn('Have you specified all required arguments inside <code>x.center()</code>?', sct_payload['message'])
     self.assertFalse('You didn\'t specify <code>fillchar</code>.' in sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 1, 12)
예제 #5
0
 def test_fail_for(self):
     self.data["DC_SCT"] = 'test_object("e")'
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertEqual(sct_payload['message'],
                      "The contents of <code>e</code> aren't correct.")
     helper.test_lines(self, sct_payload, 15, 15, 5, 9)
    def test_Fail1(self):
        self.data["DC_SCT"] = '''
test_function_definition('shout')
        '''
        sct_payload = helper.run(self.data)
        self.assertFalse(sct_payload['correct'])
        helper.test_lines(self, sct_payload, 2, 2, 13, 16)
예제 #7
0
 def test_fail_try_finally_2(self):
     self.data["DC_SCT"] = 'test_object("h")'
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertEqual(sct_payload['message'],
                      "The contents of <code>h</code> aren't correct.")
     helper.test_lines(self, sct_payload, 28, 28, 5, 9)
 def test_Pass(self):
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertEqual(
         sct_payload['message'],
         'Check your definition of <code>shout()</code>. test')
     helper.test_lines(self, sct_payload, 3, 3, 5, 41)
    def test_Fail1(self):
        self.data["DC_SCT"] = '''
test_function_definition('shout')
        '''
        sct_payload = helper.run(self.data)
        self.assertFalse(sct_payload['correct'])
        helper.test_lines(self, sct_payload, 2, 2, 13, 16)
예제 #10
0
 def test_fail_7(self):
     self.data[
         "DC_CODE"] = "[key + str(val) for key,val in x.items() if isinstance(key, str) if hasattr(key, 'test')]"
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertEqual("notcalled2", sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 69, 88)
예제 #11
0
 def test_step_2(self):
     self.data["DC_CODE"] = "x = 500"
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertEqual(sct_payload['message'],
                      "The contents of <code>x</code> aren't correct.")
     helper.test_lines(self, sct_payload, 1, 1, 1, 7)
예제 #12
0
 def test_fail_4(self):
     self.data[
         "DC_CODE"] = "[key + '_' + str(val) for key,val in x.items()]"
     sct_payload = helper.run(self.data)
     self.assertIn("Check the body of the first list comprehension.",
                   sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 2, 21)
예제 #13
0
 def test_do_eval_none_fail3(self):
     self.data = {"DC_PEC": '',
          "DC_SOLUTION": "round(123.123, 2)", # args = [0, 1]
          "DC_CODE": "round(123.123)", # student_args is len 1
          "DC_SCT": "test_function('round', do_eval = None)"}
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     helper.test_lines(self, sct_payload, 1, 1, 1, 14)
예제 #14
0
 def test_do_eval_none_fail1(self):
     self.data = {"DC_PEC": '',
          "DC_SOLUTION": "round(123.123, ndigits = 2)",
          "DC_CODE": "round(123.123)",
          "DC_SCT": "test_function('round', do_eval = None)"}
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     helper.test_lines(self, sct_payload, 1, 1, 1, 14)
예제 #15
0
 def test_line_numbers(self):
     self.data = {"DC_PEC": '',
                  "DC_SOLUTION": "round(1.23456, ndigits = 1)",
                  "DC_CODE": "round(1.23456, ndigits = 3)",
                  "DC_SCT": "test_function('round', index = 1)"}
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     helper.test_lines(self, sct_payload, 1, 1, 16, 26)
예제 #16
0
 def test_fail_4(self):
     self.data[
         "DC_CODE"] = "(key + '_' + str(val) for key,val in x.items())"
     sct_payload = helper.run(self.data)
     self.assertIn(
         "Check your code in the body of the first generator expression.",
         sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 2, 21)
예제 #17
0
 def test_fail_2(self):
     self.data["DC_CODE"] = "(key for key in x.keys())"
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertIn(
         "Check the iterable part of the first generator expression.",
         sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 17, 24)
예제 #18
0
 def test_fail_5(self):
     self.data["DC_CODE"] = "{ el:str(el) for el in lst }"
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertIn(
         "Check the value part of the first dictionary comprehension.",
         sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 6, 12)
예제 #19
0
 def test_fail_3(self):
     self.data["DC_CODE"] = "{ a:a for a in lst }"
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertEqual(
         "Have you used the correct iterator variables in the first dictionary comprehension? Be sure to use the correct names.",
         sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 11, 11)
예제 #20
0
 def test_fail_2(self):
     self.data["DC_CODE"] = "{ a:a for a in lst[1:2] }"
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertIn(
         "Check the iterable part of the first dictionary comprehension",
         sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 16, 23)
예제 #21
0
 def test_fail_2(self):
     self.data["DC_CODE"] = "[key for key in x.keys()]"
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertIn(
         "Check the first list comprehension. Did you correctly specify the iterable part?",
         sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 17, 24)
예제 #22
0
 def test_fail_4(self):
     self.data["DC_CODE"] = "{ el + 'a':str(el) for el in lst }"
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertIn(
         "Check your code in the key part of the first dictionary comprehension.",
         sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 3, 10)
 def test_step2(self):
     self.data["DC_CODE"] = "x.center(width = 50)"
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertIn(
         'Something went wrong in figuring out how you specified the arguments for <code>x.center()</code>',
         sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 1, 20)
 def test_multiple_4(self):
     self.data["DC_CODE"] = 'print("acb")\nprint(1234)\nprint([1, 2, 3])'
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertIn(
         "Did you call <code>print()</code> with the correct arguments?",
         sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 7, 11)
예제 #25
0
 def test_nested_arg2(self):
     self.data = {"DC_PEC": '',
                  "DC_SOLUTION": "print(type([1, 2, 3]))",
                  "DC_CODE": "print(type([1, 2, 4]))",
                  "DC_SCT": "test_function('type', highlight=True)"}
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     helper.test_lines(self, sct_payload, 1, 1, 12, 20)
예제 #26
0
 def test_nested_keyw2(self):
     self.data = {"DC_PEC": '',
                  "DC_SOLUTION": "round(1.1234, ndigits = max([1, 2, 3]))",
                  "DC_CODE": "round(1.1234, ndigits = max([1, 2]))",
                  "DC_SCT": "test_function('max', highlight=True)"}
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     helper.test_lines(self, sct_payload, 1, 1, 29, 34)
 def test_multiple_6(self):
     self.data["DC_CODE"] = 'print("abc")\nprint(123)\nprint([1, 2, 3, 4])'
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertIn(
         "Did you call <code>print()</code> with the correct arguments? The first argument seems to be incorrect.",
         sct_payload['message'])
     helper.test_lines(self, sct_payload, 3, 3, 7, 18)
 def test_step3(self):
     self.data["DC_CODE"] = "df = pd.DataFrame(data=[1, 2, 3])"
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertIn(
         'Have you specified all required arguments inside <code>pd.DataFrame()</code>? You didn\'t specify <code>columns</code>.',
         sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 6, 33)
예제 #29
0
 def test_nested_keyw2(self):
     self.data = {"DC_PEC": '',
                  "DC_SOLUTION": "round(1.1234, ndigits = max([1, 2, 3]))",
                  "DC_CODE": "round(1.1234, ndigits = max([1, 2]))",
                  "DC_SCT": "test_function('max', highlight=True)"}
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     helper.test_lines(self, sct_payload, 1, 1, 29, 34)
예제 #30
0
 def test_nested_arg2(self):
     self.data = {"DC_PEC": '',
                  "DC_SOLUTION": "print(type([1, 2, 3]))",
                  "DC_CODE": "print(type([1, 2, 4]))",
                  "DC_SCT": "test_function('type', highlight=True)"}
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     helper.test_lines(self, sct_payload, 1, 1, 12, 20)
 def test_step2(self):
     self.data["DC_CODE"] = "df = pd.DataFrame(x=[1, 2, 3])"
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertIn(
         'Something went wrong in figuring out how you specified the arguments for <code>pd.DataFrame()</code>',
         sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 6, 30)
예제 #32
0
 def test_line_numbers(self):
     self.data = {"DC_PEC": '',
                  "DC_SOLUTION": "round(1.23456, ndigits = 1)",
                  "DC_CODE": "round(1.23456, ndigits = 3)",
                  "DC_SCT": "test_function('round', index = 1, highlight=True)"}
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertIn("Did you call <code>round()</code> with the correct arguments? Keyword <code>ndigits</code> seems to be incorrect.", sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 26, 26)
예제 #33
0
    def test_Fail2(self):
        self.data["DC_SCT"] = '''
test_with(2, context_vals=True)
success_msg("Nice work!")
        '''
        sct_payload = helper.run(self.data)
        self.assertFalse(sct_payload['correct'])
        self.assertEqual(sct_payload['message'], "In your second <code>with</code> statement, make sure to use the correct context variable names. Was expecting <code>file</code> but got <code>not_file</code>.")
        helper.test_lines(self, sct_payload, 12, 15, 1, 22)
예제 #34
0
 def test_fail_if_cond_if_exp(self):
     self.data["DC_SOLUTION"] = self.IF_EXP_SOLUTION
     self.data[
         "DC_CODE"] = "x = 5 if offset > 9 else 7 if offset > 5 else round(9)"
     self.data["DC_SCT"] = helper.replace_test_if(self.data["DC_SCT"])
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertIn("Expected <code>", sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 10, 19)
예제 #35
0
 def test_do_eval_none_fail3(self):
     self.data = {"DC_PEC": '',
          "DC_SOLUTION": "round(123.123, 2)", # args = [0, 1]
          "DC_CODE": "round(123.123)", # student_args is len 1
          "DC_SCT": "test_function('round', do_eval = None, highlight=True)"}
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertEqual("Have you specified all required arguments inside <code>round()</code>?", sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 1, 14)
예제 #36
0
 def test_line_numbers(self):
     self.data = {"DC_PEC": '',
                  "DC_SOLUTION": "round(1.23456, ndigits = 1)",
                  "DC_CODE": "round(1.23456, ndigits = 3)",
                  "DC_SCT": "test_function('round', index = 1, highlight=True)"}
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertIn("Did you call <code>round()</code> with the correct arguments? Keyword <code>ndigits</code> seems to be incorrect.", sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 26, 26)
 def test_step4(self):
     self.data[
         "DC_CODE"] = "df = pd.DataFrame(data=[1, 2, 3], columns=['b'])"
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertIn(
         'Did you call <code>pd.DataFrame()</code> with the correct arguments? The argument you specified for <code>columns</code> seems to be incorrect.',
         sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 43, 47)
예제 #38
0
 def test_do_eval_none_fail1(self):
     self.data = {"DC_PEC": '',
          "DC_SOLUTION": "round(123.123, ndigits = 2)",
          "DC_CODE": "round(123.123)",
          "DC_SCT": "test_function_v2('round', params=['number', 'ndigits'], do_eval = None, highlight=True)"}
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertEqual("Have you specified all required arguments inside <code>round()</code>? You didn\'t specify <code>ndigits</code>.", sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 1, 14)
예제 #39
0
 def test_do_eval_false_fail(self):
     self.data = {"DC_PEC": '',
                  "DC_SOLUTION": "y = 2.12309123; round(y, ndigits = 4)",
                  "DC_CODE": "x = 2.123450; round(x, ndigits = 4)",
                  "DC_SCT": "test_function_v2('round', params=['number', 'ndigits'], do_eval = False, highlight=True)"}
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertEqual("Did you call <code>round()</code> with the correct arguments? The argument you specified for <code>number</code> seems to be incorrect.", sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 21, 21)
예제 #40
0
    def test_Fail1_spec2(self):
        self.data["DC_SCT"] = '''
Ex().check_with(0).check_body().with_context([test_function('print', index = i+1, highlight=True) for i in range(3)])
        '''
        sct_payload = helper.run(self.data)
        self.assertFalse(sct_payload['correct'])
        self.assertIn("Check your code in the body of the first <code>with</code> statement.", sct_payload['message'])
        # line info should be specific to test_function
        helper.test_lines(self, sct_payload, 6, 6, 11, 16)
    def test_Fail1(self):
        self.data["DC_SCT"] = '''
test_function_definition("shout")
success_msg("Nice work!")
        '''
        sct_payload = helper.run(self.data)
        self.assertFalse(sct_payload['correct'])
        self.assertEqual(sct_payload['message'], 'You should define <code>shout()</code> with 3 arguments, instead got 2.')
        helper.test_lines(self, sct_payload, 2, 6, 1, 20)
예제 #42
0
 def test_do_eval_none_fail3(self):
     self.data = {"DC_PEC": '',
          "DC_SOLUTION": "round(123.123, 2)", # args = [0, 1]
          "DC_CODE": "round(123.123)", # student_args is len 1
          "DC_SCT": "test_function('round', do_eval = None, highlight=True)"}
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertEqual("Have you specified all required arguments inside <code>round()</code>?", sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 1, 14)
예제 #43
0
    def test_Fail1(self):
        self.data["DC_SCT"] = '''
test_with(1, context_vals=True)
success_msg("Nice work!")
        '''
        sct_payload = helper.run(self.data)
        self.assertFalse(sct_payload['correct'])
        self.assertEqual(sct_payload['message'], "In your first <code>with</code> statement, make sure to use the correct number of context variables. It seems you defined too many.")
        helper.test_lines(self, sct_payload, 3, 6, 1, 17)
예제 #44
0
 def test_do_eval_true_fail(self):
     self.data = {"DC_PEC": '',
                  "DC_SOLUTION": "round(2.1234, ndigits = 4)",
                  "DC_CODE": "round(2.123456, ndigits = 4)",
                  "DC_SCT": "test_function_v2('round', params=['number', 'ndigits'], do_eval = True, highlight=True)"}
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertIn("Did you call <code>round()</code> with the correct arguments?", sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 7, 14)
    def test_Fail2(self):
        self.data["DC_CODE"] = '''
def shout():
    shout_word = 'congratulations' + '!!'
        '''
        sct_payload = helper.run(self.data)
        self.assertFalse(sct_payload['correct'])
        self.assertEqual(sct_payload['message'], 'Check your definition of <code>shout()</code>. Are you sure you assigned the correct value to <code>shout_word</code>?')
        # line info specific to test_object_after_expression!
        helper.test_lines(self, sct_payload, 3, 3, 5, 41)
    def test_Fail(self):
        self.data["DC_SCT"] = '''
test_function_definition("shout", body = lambda: test_expression_output(context_vals = ['help'], incorrect_msg = 'make sure to output the correct string.'))
success_msg("Nice work!")
        '''
        sct_payload = helper.run(self.data)
        self.assertFalse(sct_payload['correct'])
        self.assertEqual(sct_payload['message'], "You should define <code>shout()</code> with 2 arguments, instead got 1.")

        helper.test_lines(self, sct_payload, 2, 4, 1, 23)
예제 #47
0
 def test_method_builtin_fail(self):
     self.data = {
         "DC_PEC": "arr = [1, 2, 3, 4]",
         "DC_SOLUTION": "arr.append(5)",
         "DC_CODE": "arr.append(5123)",
         "DC_SCT": "test_function_v2('arr.append', params = ['object'], highlight=True)"
     }
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     helper.test_lines(self, sct_payload, 1, 1, 12, 15)
예제 #48
0
 def test_builtin_fail(self):
     self.data = {
         "DC_PEC": "",
         "DC_SOLUTION": "print('test')",
         "DC_CODE": "print('testing')",
         "DC_SCT": "test_function_v2('print', params = ['value'], highlight=True)"
     }
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     helper.test_lines(self, sct_payload, 1, 1, 7, 15)
예제 #49
0
    def test_Fail2_no_lam(self):
        self.data["DC_SCT"] = '''
test_with(1, body = [test_function('print', index = i + 1, highlight=True) for i in range(3)], expand_message = False)
success_msg("Nice work!")
        '''
        sct_payload = helper.run(self.data)
        self.assertFalse(sct_payload['correct'])
        self.assertNotIn("Check the body of the first <code>with</code>.", sct_payload['message'])
        # line info should be specific to test_function
        helper.test_lines(self, sct_payload, 6, 6, 11, 16)
    def test_Pass2(self):
        self.data["DC_SCT"] = '''
# Test the value of shout_word
test_function_definition("shout", arg_names = False, body = lambda: test_object_after_expression("shout_word", undefined_msg = "have you defined `shout_word`?"))
success_msg("Nice work!")
        '''
        sct_payload = helper.run(self.data)
        self.assertFalse(sct_payload['correct'])
        self.assertEqual(sct_payload['message'], 'Check your definition of <code>shout()</code>. Are you sure you assigned the correct value to <code>shout_word</code>?')
        helper.test_lines(self, sct_payload, 3, 3, 5, 41)
예제 #51
0
    def test_Fail(self):
        self.data["DC_CODE"] = '''
areas = [11.25, 18.0, 20.0, 10.75, 9.50]
for test in enumerate(areas) :
    print("roomrettektetetet" + str(test[0]) + ": " + str(test[1]))
        '''
        sct_payload = helper.run(self.data)
        self.assertFalse(sct_payload['correct'])
        self.assertIn("Check your code in the body of the first for loop", sct_payload['message'])
        self.assertIn("blabla", sct_payload['message'])
        helper.test_lines(self, sct_payload, 4, 4, 5, 67)
예제 #52
0
 def test_package_fun_fail(self):
     self.data = {
         "DC_PEC": "import pandas as pd",
         "DC_SOLUTION": "df = pd.DataFrame({'a': [1, 2, 3]})",
         "DC_CODE": "df = pd.DataFrame({'a': [1, 2, 312]})",
         "DC_SCT": "test_function_v2('pandas.DataFrame', params = ['data'], highlight=True)"
     }
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertIn('The argument you specified for <code>data</code> seems to be incorrect.', sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 19, 36)
예제 #53
0
 def test_fun_wrong_call_student(self):
     self.data = {
         "DC_PEC": "def my_fun(a):\n    pass",
         "DC_SOLUTION": "my_fun(1)",
         "DC_CODE": "my_fun(b = 1)",
         "DC_SCT": "test_function_v2('my_fun', params = ['a'], highlight=True)"
     }
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertIn('Something went wrong in figuring out how', sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 1, 13)
예제 #54
0
    def test_Fail(self):
        self.data["DC_CODE"] = '''
offset = 8
while offset != 4 :
    offset = offset - 1
        '''
        sct_payload = helper.run(self.data)
        self.assertFalse(sct_payload['correct'])
        self.assertIn("Check your code in the condition of the first while loop", sct_payload['message'])
        self.assertIn("Unexpected expression", sct_payload['message'])
        helper.test_lines(self, sct_payload, 3, 3, 7, 17)
예제 #55
0
    def test_Fail2(self):
        self.data["DC_CODE"] = '''
offset = 8
while offset != 0 :
    offset = offset - 2
        '''
        sct_payload = helper.run(self.data)
        self.assertFalse(sct_payload['correct'])
        self.assertIn("Check your code in the body of the first while loop", sct_payload['message'])
        self.assertIn("Are you sure you assigned the correct value to <code>offset</code>", sct_payload['message'])
        helper.test_lines(self, sct_payload, 4, 4, 5, 23)
예제 #56
0
    def test_Fail2(self):
        self.data["DC_SCT"] = '''
test_with(2, context_tests=[
    lambda: test_function('open', highlight=True),
    lambda: test_function('open', highlight=True)])
success_msg("Nice work!")
        '''
        sct_payload = helper.run(self.data)
        self.assertFalse(sct_payload['correct'])
        self.assertEqual(sct_payload['message'], "Check the second context of the second <code>with</code> statement. Did you call <code>open()</code> with the correct arguments? The first argument seems to be incorrect.")
        helper.test_lines(self, sct_payload, 12, 12, 46, 60)
예제 #57
0
    def test_allOperations(self):
        self.data[
            "DC_SCT"
        ] = """
test_operator(1)
success_msg("Well done!")
        """
        sct_payload = helper.run(self.data)
        self.assertFalse(sct_payload["correct"])
        self.assertEqual(sct_payload["message"], "The highlighted operation is missing a <code>*</code> operation.")
        helper.test_lines(self, sct_payload, 1, 1, 7, 11)
예제 #58
0
 def test_fun_fail(self):
     self.data = {
         "DC_PEC": "def my_fun(a):\n    pass",
         "DC_SOLUTION": "my_fun(2)",
         "DC_CODE": "my_fun(1)",
         "DC_SCT": "test_function_v2('my_fun', params = ['a'], highlight=True)"
     }
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertIn('The argument you specified for <code>a</code> seems to be incorrect.', sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 8, 8)
    def test_Fail(self):
        self.data["DC_CODE"] = '''
def shout ( word ):
    shout_word = word + '!!!'
    print( shout_word + "!!" )
shout( 'help' )
        '''
        sct_payload = helper.run(self.data)
        self.assertFalse(sct_payload['correct'])
        self.assertEqual(sct_payload['message'], "Check your definition of <code>shout()</code>. Make sure to output the correct string.")
        helper.test_lines(self, sct_payload, 3, 4, 5, 30)
예제 #60
0
 def test_package_builtin_fail(self):
     self.data = {
         "DC_PEC": "import numpy as np",
         "DC_SOLUTION": "arr = np.array([1, 2, 3])",
         "DC_CODE": "arr = np.array([1, 2, 123])",
         "DC_SCT": "test_function_v2('numpy.array', params = ['object'], highlight=True)"
     }
     sct_payload = helper.run(self.data)
     self.assertFalse(sct_payload['correct'])
     self.assertIn('The argument you specified for <code>object</code> seems to be incorrect.', sct_payload['message'])
     helper.test_lines(self, sct_payload, 1, 1, 16, 26)