Commit 95b1bd953635b9d90a34e4e82f4a2cda7fe3ad8d
1 parent
524327c3
Exists in
master
and in
1 other branch
- more raise from patterns
- remove __init__() from Test class as its useless
Showing
3 changed files
with
14 additions
and
15 deletions
Show diff stats
perguntations/app.py
@@ -182,12 +182,11 @@ class App(): | @@ -182,12 +182,11 @@ class App(): | ||
182 | logger.info('Test factory ready. No errors found.') | 182 | logger.info('Test factory ready. No errors found.') |
183 | 183 | ||
184 | # ------------------------------------------------------------------------ | 184 | # ------------------------------------------------------------------------ |
185 | - def _pregenerate_tests(self, n): | ||
186 | - for _ in range(n): | 185 | + def _pregenerate_tests(self, num): |
186 | + for _ in range(num): | ||
187 | event_loop = asyncio.get_event_loop() | 187 | event_loop = asyncio.get_event_loop() |
188 | test = event_loop.run_until_complete(self.testfactory.generate()) | 188 | test = event_loop.run_until_complete(self.testfactory.generate()) |
189 | self.pregenerated_tests.append(test) | 189 | self.pregenerated_tests.append(test) |
190 | - print(test) | ||
191 | 190 | ||
192 | # ------------------------------------------------------------------------ | 191 | # ------------------------------------------------------------------------ |
193 | async def generate_test(self, uid): | 192 | async def generate_test(self, uid): |
perguntations/questions.py
@@ -110,10 +110,10 @@ class QuestionRadio(Question): | @@ -110,10 +110,10 @@ class QuestionRadio(Question): | ||
110 | # make sure is a list of floats | 110 | # make sure is a list of floats |
111 | try: | 111 | try: |
112 | self['correct'] = [float(x) for x in self['correct']] | 112 | self['correct'] = [float(x) for x in self['correct']] |
113 | - except (ValueError, TypeError): | 113 | + except (ValueError, TypeError) as exc: |
114 | msg = (f'Correct list must contain numbers [0.0, 1.0] or ' | 114 | msg = (f'Correct list must contain numbers [0.0, 1.0] or ' |
115 | f'booleans in "{self["ref"]}"') | 115 | f'booleans in "{self["ref"]}"') |
116 | - raise QuestionException(msg) | 116 | + raise QuestionException(msg) from exc |
117 | 117 | ||
118 | # check grade boundaries | 118 | # check grade boundaries |
119 | if self['discount'] and not all(0.0 <= x <= 1.0 | 119 | if self['discount'] and not all(0.0 <= x <= 1.0 |
@@ -217,10 +217,10 @@ class QuestionCheckbox(Question): | @@ -217,10 +217,10 @@ class QuestionCheckbox(Question): | ||
217 | # make sure is a list of floats | 217 | # make sure is a list of floats |
218 | try: | 218 | try: |
219 | self['correct'] = [float(x) for x in self['correct']] | 219 | self['correct'] = [float(x) for x in self['correct']] |
220 | - except (ValueError, TypeError): | 220 | + except (ValueError, TypeError) as exc: |
221 | msg = (f'Correct list must contain numbers or ' | 221 | msg = (f'Correct list must contain numbers or ' |
222 | f'booleans in "{self["ref"]}"') | 222 | f'booleans in "{self["ref"]}"') |
223 | - raise QuestionException(msg) | 223 | + raise QuestionException(msg) from exc |
224 | 224 | ||
225 | # check grade boundaries | 225 | # check grade boundaries |
226 | if self['discount'] and not all(0.0 <= x <= 1.0 | 226 | if self['discount'] and not all(0.0 <= x <= 1.0 |
@@ -379,9 +379,9 @@ class QuestionTextRegex(Question): | @@ -379,9 +379,9 @@ class QuestionTextRegex(Question): | ||
379 | # converts patterns to compiled versions | 379 | # converts patterns to compiled versions |
380 | try: | 380 | try: |
381 | self['correct'] = [re.compile(a) for a in self['correct']] | 381 | self['correct'] = [re.compile(a) for a in self['correct']] |
382 | - except Exception: | 382 | + except Exception as exc: |
383 | msg = f'Failed to compile regex in "{self["ref"]}"' | 383 | msg = f'Failed to compile regex in "{self["ref"]}"' |
384 | - raise QuestionException(msg) | 384 | + raise QuestionException(msg) from exc |
385 | 385 | ||
386 | # ------------------------------------------------------------------------ | 386 | # ------------------------------------------------------------------------ |
387 | def correct(self) -> None: | 387 | def correct(self) -> None: |
@@ -430,10 +430,10 @@ class QuestionNumericInterval(Question): | @@ -430,10 +430,10 @@ class QuestionNumericInterval(Question): | ||
430 | 430 | ||
431 | try: | 431 | try: |
432 | self['correct'] = [float(n) for n in self['correct']] | 432 | self['correct'] = [float(n) for n in self['correct']] |
433 | - except Exception: | 433 | + except Exception as exc: |
434 | msg = (f'Numeric interval must be a list with two numbers, in ' | 434 | msg = (f'Numeric interval must be a list with two numbers, in ' |
435 | f'{self["ref"]}') | 435 | f'{self["ref"]}') |
436 | - raise QuestionException(msg) | 436 | + raise QuestionException(msg) from exc |
437 | 437 | ||
438 | # invalid | 438 | # invalid |
439 | else: | 439 | else: |
perguntations/test.py
@@ -111,9 +111,9 @@ class TestFactory(dict): | @@ -111,9 +111,9 @@ class TestFactory(dict): | ||
111 | # check if all the questions can be correctly generated | 111 | # check if all the questions can be correctly generated |
112 | try: | 112 | try: |
113 | self.question_factory[question['ref']].generate() | 113 | self.question_factory[question['ref']].generate() |
114 | - except Exception: | 114 | + except Exception as exc: |
115 | msg = f'Failed to generate "{question["ref"]}"' | 115 | msg = f'Failed to generate "{question["ref"]}"' |
116 | - raise TestFactoryException(msg) | 116 | + raise TestFactoryException(msg) from exc |
117 | else: | 117 | else: |
118 | logger.info('%4d. "%s" Ok.', counter, question["ref"]) | 118 | logger.info('%4d. "%s" Ok.', counter, question["ref"]) |
119 | counter += 1 | 119 | counter += 1 |
@@ -299,8 +299,8 @@ class Test(dict): | @@ -299,8 +299,8 @@ class Test(dict): | ||
299 | ''' | 299 | ''' |
300 | 300 | ||
301 | # ------------------------------------------------------------------------ | 301 | # ------------------------------------------------------------------------ |
302 | - def __init__(self, d): | ||
303 | - super().__init__(d) | 302 | + # def __init__(self, d): |
303 | + # super().__init__(d) | ||
304 | 304 | ||
305 | # ------------------------------------------------------------------------ | 305 | # ------------------------------------------------------------------------ |
306 | def start(self, student): | 306 | def start(self, student): |