Exemplo n.º 1
0
def run(data):
    exercise = Exercise(data)
    output = exercise.runInit()
    if 'backend-error' in str(output):
        print(output)
        raise (ValueError("Backend error"))
    output = exercise.runSubmit(data)
    return (get_sct_payload(output))
Exemplo n.º 2
0
def run(data):
    exercise = Exercise(data)
    output = exercise.runInit()
    if 'backend-error' in str(output):
        print(output)
        raise(ValueError("Backend error"))
    output = exercise.runSubmit(data)
    return(get_sct_payload(output))
Exemplo n.º 3
0
def run(data):
    exercise = Exercise(data)
    output = exercise.runInit()
    if 'backend-error' in str(output):
        print(output)
        raise(ValueError("Backend error"))
    output = exercise.runSubmit(data)
    sct_payload = get_sct_payload(output)
    if os.environ.get('PYTHONWHAT_DEBUG_FEEDBACK'):
        print('message: %s'%sct_payload.get('message'))
    return(sct_payload)
 def test_normal_fail(self):
     self.data = {
         "DC_PEC": '#no pec',
         "DC_CODE": 'x = 4',
         "DC_SOLUTION": 'x = 6',
         "DC_SCT": 'test_object("x")\nsuccess_msg("nice")'
     }
     self.exercise = Exercise(self.data)
     self.exercise.runInit()
     output = self.exercise.runSubmit(self.data)
     self.assertEqual(output[0]['type'], 'sct')
     self.assertFalse(output[0]['payload']['correct'])
 def test_enrichment_error(self):
     self.data = {
         "DC_PEC": '# no pec',
         "DC_CODE": '',
         "DC_SOLUTION": 'x = 6',
         "DC_SCT": 'test_object("x")'
     }
     self.exercise = Exercise(self.data)
     self.exercise.runInit()
     output = self.exercise.runSubmit(self.data)
     self.assertEqual(output[0]['type'], 'sct')
     self.assertFalse(output[0]['payload']['correct'])
     helper.test_absent_lines(self, output[0]['payload'])
 def test_indentation_error(self):
     self.data = {
         "DC_PEC": '# no pec',
         "DC_CODE": '	print("yolo")',
         "DC_SOLUTION": 'x = 6',
         "DC_SCT": 'test_object("x")'
     }
     self.exercise = Exercise(self.data)
     self.exercise.runInit()
     output = self.exercise.runSubmit(self.data)
     self.assertEqual(output[0]['type'], "script-output")
     self.assertFalse(output[1]['payload']['correct'])
     self.assertEqual(
         output[1]['payload']['message'],
         "Your code could not be parsed due to an error in the indentation:<br><code>unexpected indent (script.py, line 1).</code>"
     )
 def test_syntax_error(self):
     self.data = {
         "DC_PEC": '# no pec',
         "DC_CODE": 'print "yolo"',
         "DC_SOLUTION": 'x = 6',
         "DC_SCT": 'test_object("x")'
     }
     self.exercise = Exercise(self.data)
     self.exercise.runInit()
     output = self.exercise.runSubmit(self.data)
     self.assertEqual(output[0]['type'], "error")
     self.assertFalse(output[1]['payload']['correct'])
     self.assertEqual(
         output[1]['payload']['message'],
         "Your code can not be executed due to a syntax error:<br><code>Missing parentheses in call to 'print' (script.py, line 1).</code>"
     )
Exemplo n.º 8
0
	def test_normal_fail(self):
		self.data = {
			"DC_PEC": '#no pec',
			"DC_CODE": 'x = 4',
			"DC_SOLUTION": 'x = 6',
			"DC_SCT": 'test_object("x")\nsuccess_msg("nice")'
		}
		self.exercise = Exercise(self.data)
		self.exercise.runInit()
		output = self.exercise.runSubmit(self.data)
		self.assertEqual(output[0]['type'], 'sct')
		self.assertFalse(output[0]['payload']['correct'])
Exemplo n.º 9
0
	def test_enrichment_error(self):
		self.data = {
			"DC_PEC": '# no pec',
			"DC_CODE": '',
			"DC_SOLUTION": 'x = 6',
			"DC_SCT": 'test_object("x")'
		}
		self.exercise = Exercise(self.data)
		self.exercise.runInit()
		output = self.exercise.runSubmit(self.data)
		self.assertEqual(output[0]['type'], 'sct')
		self.assertFalse(output[0]['payload']['correct'])
		helper.test_absent_lines(self, output[0]['payload'])
Exemplo n.º 10
0
	def test_indentation_error(self):
		self.data = {
			"DC_PEC": '# no pec',
			"DC_CODE": '	print("yolo")',
			"DC_SOLUTION": 'x = 6',
			"DC_SCT": 'test_object("x")'
		}
		self.exercise = Exercise(self.data)
		self.exercise.runInit()
		output = self.exercise.runSubmit(self.data)
		self.assertEqual(output[0]['type'], "script-output")
		self.assertFalse(output[1]['payload']['correct'])
		self.assertEqual(output[1]['payload']['message'], "Your code could not be parsed due to an error in the indentation:<br><code>unexpected indent (script.py, line 1).</code>")
		self.assertEqual(output[1]['payload']['tags']['fun'], "indentation_error")
Exemplo n.º 11
0
	def test_syntax_error(self):
		self.data = {
			"DC_PEC": '# no pec',
			"DC_CODE": 'print "yolo"',
			"DC_SOLUTION": 'x = 6',
			"DC_SCT": 'test_object("x")'
		}
		self.exercise = Exercise(self.data)
		self.exercise.runInit()
		output = self.exercise.runSubmit(self.data)
		self.assertEqual(output[0]['type'], "error")
		self.assertFalse(output[1]['payload']['correct'])
		self.assertEqual(output[1]['payload']['message'], "Your code can not be executed due to a syntax error:<br><code>Missing parentheses in call to 'print' (script.py, line 1).</code>") 
		self.assertEqual(output[1]['payload']['tags']['fun'], "syntax_error")
Exemplo n.º 12
0
class TestTestExerciseError(unittest.TestCase):

	def test_normal_pass(self):
		self.data = {
			"DC_PEC": '#no pec',
			"DC_CODE": 'x = 4',
			"DC_SOLUTION": 'x = 4',
			"DC_SCT": 'test_object("x")\nsuccess_msg("nice")'
		}
		self.exercise = Exercise(self.data)
		self.exercise.runInit()
		output = self.exercise.runSubmit(self.data)
		self.assertEqual(output[0]['type'], 'sct')
		self.assertTrue(output[0]['payload']['correct'])
		self.assertEqual(output[0]['payload']['message'], 'nice')

	def test_normal_fail(self):
		self.data = {
			"DC_PEC": '#no pec',
			"DC_CODE": 'x = 4',
			"DC_SOLUTION": 'x = 6',
			"DC_SCT": 'test_object("x")\nsuccess_msg("nice")'
		}
		self.exercise = Exercise(self.data)
		self.exercise.runInit()
		output = self.exercise.runSubmit(self.data)
		self.assertEqual(output[0]['type'], 'sct')
		self.assertFalse(output[0]['payload']['correct'])

	def test_syntax_error(self):
		self.data = {
			"DC_PEC": '# no pec',
			"DC_CODE": 'print "yolo"',
			"DC_SOLUTION": 'x = 6',
			"DC_SCT": 'test_object("x")'
		}
		self.exercise = Exercise(self.data)
		self.exercise.runInit()
		output = self.exercise.runSubmit(self.data)
		self.assertEqual(output[0]['type'], "error")
		self.assertFalse(output[1]['payload']['correct'])
		self.assertEqual(output[1]['payload']['message'], "Your code can not be executed due to a syntax error:<br><code>Missing parentheses in call to 'print' (script.py, line 1).</code>") 
		self.assertEqual(output[1]['payload']['tags']['fun'], "syntax_error")

	def test_indentation_error(self):
		self.data = {
			"DC_PEC": '# no pec',
			"DC_CODE": '	print("yolo")',
			"DC_SOLUTION": 'x = 6',
			"DC_SCT": 'test_object("x")'
		}
		self.exercise = Exercise(self.data)
		self.exercise.runInit()
		output = self.exercise.runSubmit(self.data)
		self.assertEqual(output[0]['type'], "script-output")
		self.assertFalse(output[1]['payload']['correct'])
		self.assertEqual(output[1]['payload']['message'], "Your code could not be parsed due to an error in the indentation:<br><code>unexpected indent (script.py, line 1).</code>")
		self.assertEqual(output[1]['payload']['tags']['fun'], "indentation_error")

	def test_enrichment_error(self):
		self.data = {
			"DC_PEC": '# no pec',
			"DC_CODE": '',
			"DC_SOLUTION": 'x = 6',
			"DC_SCT": 'test_object("x")'
		}
		self.exercise = Exercise(self.data)
		self.exercise.runInit()
		output = self.exercise.runSubmit(self.data)
		self.assertEqual(output[0]['type'], 'sct')
		self.assertFalse(output[0]['payload']['correct'])
		helper.test_absent_lines(self, output[0]['payload'])
Exemplo n.º 13
0
class TestTestExerciseError(unittest.TestCase):
    def test_normal_pass(self):
        self.data = {
            "DC_PEC": '#no pec',
            "DC_CODE": 'x = 4',
            "DC_SOLUTION": 'x = 4',
            "DC_SCT": 'test_object("x")\nsuccess_msg("nice")'
        }
        self.exercise = Exercise(self.data)
        self.exercise.runInit()
        output = self.exercise.runSubmit(self.data)
        self.assertEqual(output[0]['type'], 'sct')
        self.assertTrue(output[0]['payload']['correct'])
        self.assertEqual(output[0]['payload']['message'], 'nice')

    def test_normal_fail(self):
        self.data = {
            "DC_PEC": '#no pec',
            "DC_CODE": 'x = 4',
            "DC_SOLUTION": 'x = 6',
            "DC_SCT": 'test_object("x")\nsuccess_msg("nice")'
        }
        self.exercise = Exercise(self.data)
        self.exercise.runInit()
        output = self.exercise.runSubmit(self.data)
        self.assertEqual(output[0]['type'], 'sct')
        self.assertFalse(output[0]['payload']['correct'])

    def test_syntax_error(self):
        self.data = {
            "DC_PEC": '# no pec',
            "DC_CODE": 'print "yolo"',
            "DC_SOLUTION": 'x = 6',
            "DC_SCT": 'test_object("x")'
        }
        self.exercise = Exercise(self.data)
        self.exercise.runInit()
        output = self.exercise.runSubmit(self.data)
        self.assertEqual(output[0]['type'], "error")
        self.assertFalse(output[1]['payload']['correct'])
        self.assertEqual(
            output[1]['payload']['message'],
            "Your code can not be executed due to a syntax error:<br><code>Missing parentheses in call to 'print' (script.py, line 1).</code>"
        )

    def test_indentation_error(self):
        self.data = {
            "DC_PEC": '# no pec',
            "DC_CODE": '	print("yolo")',
            "DC_SOLUTION": 'x = 6',
            "DC_SCT": 'test_object("x")'
        }
        self.exercise = Exercise(self.data)
        self.exercise.runInit()
        output = self.exercise.runSubmit(self.data)
        self.assertEqual(output[0]['type'], "script-output")
        self.assertFalse(output[1]['payload']['correct'])
        self.assertEqual(
            output[1]['payload']['message'],
            "Your code could not be parsed due to an error in the indentation:<br><code>unexpected indent (script.py, line 1).</code>"
        )

    def test_enrichment_error(self):
        self.data = {
            "DC_PEC": '# no pec',
            "DC_CODE": '',
            "DC_SOLUTION": 'x = 6',
            "DC_SCT": 'test_object("x")'
        }
        self.exercise = Exercise(self.data)
        self.exercise.runInit()
        output = self.exercise.runSubmit(self.data)
        self.assertEqual(output[0]['type'], 'sct')
        self.assertFalse(output[0]['payload']['correct'])
        helper.test_absent_lines(self, output[0]['payload'])