Commit 81d72682bfae7b4878a609ffce482db8bf05b3cc
1 parent
96ae3635
Exists in
master
and in
1 other branch
run tests of textarea questions before starting the test.
Showing
2 changed files
with
37 additions
and
10 deletions
Show diff stats
perguntations/templates/review.html
| @@ -97,7 +97,7 @@ | @@ -97,7 +97,7 @@ | ||
| 97 | <div class="row"> | 97 | <div class="row"> |
| 98 | <label for="nota" class="col-sm-2">Nota:</label> | 98 | <label for="nota" class="col-sm-2">Nota:</label> |
| 99 | <div class="col-sm-10" id="nota"> | 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 | {% if t['state'] == 'QUIT' %} | 101 | {% if t['state'] == 'QUIT' %} |
| 102 | (DESISTÊNCIA) | 102 | (DESISTÊNCIA) |
| 103 | {% end %} | 103 | {% end %} |
perguntations/testfactory.py
| @@ -223,24 +223,51 @@ class TestFactory(dict): | @@ -223,24 +223,51 @@ class TestFactory(dict): | ||
| 223 | ''' | 223 | ''' |
| 224 | logger.info('Checking if questions can be generated and corrected...') | 224 | logger.info('Checking if questions can be generated and corrected...') |
| 225 | for i, (qref, qfact) in enumerate(self['question_factory'].items()): | 225 | for i, (qref, qfact) in enumerate(self['question_factory'].items()): |
| 226 | - logger.info('%4d. %s:', i, qref) | ||
| 227 | try: | 226 | try: |
| 228 | question = qfact.generate() | 227 | question = qfact.generate() |
| 229 | except Exception as exc: | 228 | except Exception as exc: |
| 230 | msg = f'Failed to generate "{qref}"' | 229 | msg = f'Failed to generate "{qref}"' |
| 231 | raise TestFactoryException(msg) from exc | 230 | raise TestFactoryException(msg) from exc |
| 232 | else: | 231 | else: |
| 233 | - logger.info(' generate Ok') | 232 | + logger.info('%4d. %s: Ok', i, qref) |
| 233 | + # logger.info(' generate Ok') | ||
| 234 | 234 | ||
| 235 | if question['type'] in ('code', 'textarea'): | 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 | else: | 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 | async def generate(self): | 273 | async def generate(self): |