Test the student code. Tests if the student typed a (pattern of) text. It is advised to use ``has_equal_ast()`` instead of ``has_code()``, as it is more robust to small syntactical differences that don't change the code's behavior. Args: text (str): the text that is searched fo
(state, text, pattern=True, not_typed_msg=None)
| 457 | |
| 458 | |
| 459 | def has_code(state, text, pattern=True, not_typed_msg=None): |
| 460 | """Test the student code. |
| 461 | |
| 462 | Tests if the student typed a (pattern of) text. It is advised to use ``has_equal_ast()`` instead of ``has_code()``, |
| 463 | as it is more robust to small syntactical differences that don't change the code's behavior. |
| 464 | |
| 465 | Args: |
| 466 | text (str): the text that is searched for |
| 467 | pattern (bool): if True (the default), the text is treated as a pattern. If False, it is treated as plain text. |
| 468 | not_typed_msg (str): feedback message to be displayed if the student did not type the text. |
| 469 | |
| 470 | :Example: |
| 471 | |
| 472 | Student code and solution code:: |
| 473 | |
| 474 | y = 1 + 2 + 3 |
| 475 | |
| 476 | SCT:: |
| 477 | |
| 478 | # Verify that student code contains pattern (not robust!!): |
| 479 | Ex().has_code(r"1\\s*\\+2\\s*\\+3") |
| 480 | |
| 481 | """ |
| 482 | if not not_typed_msg: |
| 483 | if pattern: |
| 484 | not_typed_msg = "Could not find the correct pattern in your code." |
| 485 | else: |
| 486 | not_typed_msg = "Could not find the following text in your code: %r" % text |
| 487 | |
| 488 | student_code = state.student_code |
| 489 | |
| 490 | state.do_test(StringContainsTest(student_code, text, pattern, not_typed_msg)) |
| 491 | |
| 492 | return state |
| 493 | |
| 494 | |
| 495 | def has_import( |
nothing calls this directly
no test coverage detected