MCPcopy Index your code
hub / github.com/datacamp/pythonwhat / has_output

Function has_output

pythonwhat/checks/has_funcs.py:581–620  ·  view source on GitHub ↗

r"""Search student output for a pattern. Among the student and solution process, the student submission and solution code as a string, the ``Ex()`` state also contains the output that a student generated with his or her submission. With ``has_output()``, you can access this output and

(state, text, pattern=True, no_output_msg=None)

Source from the content-addressed store, hash-verified

579
580
581def has_output(state, text, pattern=True, no_output_msg=None):
582 r"""Search student output for a pattern.
583
584 Among the student and solution process, the student submission and solution code as a string,
585 the ``Ex()`` state also contains the output that a student generated with his or her submission.
586
587 With ``has_output()``, you can access this output and match it against a regular or fixed expression.
588
589 Args:
590 text (str): the text that is searched for
591 pattern (bool): if True (default), the text is treated as a pattern. If False, it is treated as plain text.
592 no_output_msg (str): feedback message to be displayed if the output is not found.
593
594 :Example:
595
596 As an example, suppose we want a student to print out a sentence: ::
597
598 # Print the "This is some ... stuff"
599 print("This is some weird stuff")
600
601 The following SCT tests whether the student prints out ``This is some weird stuff``: ::
602
603 # Using exact string matching
604 Ex().has_output("This is some weird stuff", pattern = False)
605
606 # Using a regular expression (more robust)
607 # pattern = True is the default
608 msg = "Print out ``This is some ... stuff`` to the output, " + \\
609 "fill in ``...`` with a word you like."
610 Ex().has_output(r"This is some \w* stuff", no_output_msg = msg)
611
612 """
613 if not no_output_msg:
614 no_output_msg = "You did not output the correct things."
615
616 state.do_test(
617 StringContainsTest(state.raw_student_output, text, pattern, no_output_msg)
618 )
619
620 return state
621
622
623def has_printout(

Callers 1

has_printoutFunction · 0.85

Calls 1

StringContainsTestClass · 0.90

Tested by

no test coverage detected