Commit 81d72682bfae7b4878a609ffce482db8bf05b3cc

Authored by Miguel Barão
1 parent 96ae3635
Exists in master and in 1 other branch dev

run tests of textarea questions before starting the test.

perguntations/templates/review.html
... ... @@ -97,7 +97,7 @@
97 97 <div class="row">
98 98 <label for="nota" class="col-sm-2">Nota:</label>
99 99 <div class="col-sm-10" id="nota">
100   - <span class="badge badge-primary">{{ round(t['grade'], 1) }}</span> valores
  100 + <span class="badge badge-primary">{{ round(t['grade'], 2) }}</span> valores
101 101 {% if t['state'] == 'QUIT' %}
102 102 (DESISTÊNCIA)
103 103 {% end %}
... ...
perguntations/testfactory.py
... ... @@ -223,24 +223,51 @@ class TestFactory(dict):
223 223 '''
224 224 logger.info('Checking if questions can be generated and corrected...')
225 225 for i, (qref, qfact) in enumerate(self['question_factory'].items()):
226   - logger.info('%4d. %s:', i, qref)
227 226 try:
228 227 question = qfact.generate()
229 228 except Exception as exc:
230 229 msg = f'Failed to generate "{qref}"'
231 230 raise TestFactoryException(msg) from exc
232 231 else:
233   - logger.info(' generate Ok')
  232 + logger.info('%4d. %s: Ok', i, qref)
  233 + # logger.info(' generate Ok')
234 234  
235 235 if question['type'] in ('code', 'textarea'):
236   - try:
237   - question.set_answer('')
238   - question.correct()
239   - except Exception as exc:
240   - msg = f'Failed to correct "{qref}"'
241   - raise TestFactoryException(msg) from exc
  236 + if 'tests_right' in question:
  237 + for i, right_answer in enumerate(question['tests_right']):
  238 + try:
  239 + question.set_answer(right_answer)
  240 + question.correct()
  241 + except Exception as exc:
  242 + msg = f'Failed to correct "{qref}"'
  243 + raise TestFactoryException(msg) from exc
  244 +
  245 + if question['grade'] == 1.0:
  246 + logger.info(' test %i Ok', i)
  247 + else:
  248 + logger.error(' TEST %i IS WRONG!!!', i)
  249 + elif 'tests_wrong' in question:
  250 + for i, wrong_answer in enumerate(question['tests_wrong']):
  251 + try:
  252 + question.set_answer(wrong_answer)
  253 + question.correct()
  254 + except Exception as exc:
  255 + msg = f'Failed to correct "{qref}"'
  256 + raise TestFactoryException(msg) from exc
  257 +
  258 + if question['grade'] < 1.0:
  259 + logger.info(' test %i Ok', i)
  260 + else:
  261 + logger.error(' TEST %i IS WRONG!!!', i)
242 262 else:
243   - logger.info(' correct Ok')
  263 + try:
  264 + question.set_answer('')
  265 + question.correct()
  266 + except Exception as exc:
  267 + msg = f'Failed to correct "{qref}"'
  268 + raise TestFactoryException(msg) from exc
  269 + else:
  270 + logger.info(' correct Ok but no tests to run')
244 271  
245 272 # ------------------------------------------------------------------------
246 273 async def generate(self):
... ...