MCPcopy Index your code
hub / github.com/RustPython/RustPython / script_from_examples

Function script_from_examples

Lib/doctest.py:2643–2723  ·  view source on GitHub ↗

r"""Extract script from text with examples. Converts text with examples to a Python script. Example input is converted to regular code. Example output and all other words are converted to comments: >>> text = ''' ... Here are examples of simple math.

(s)

Source from the content-addressed store, hash-verified

2641######################################################################
2642
2643def script_from_examples(s):
2644 r"""Extract script from text with examples.
2645
2646 Converts text with examples to a Python script. Example input is
2647 converted to regular code. Example output and all other words
2648 are converted to comments:
2649
2650 >>> text = '''
2651 ... Here are examples of simple math.
2652 ...
2653 ... Python has super accurate integer addition
2654 ...
2655 ... >>> 2 + 2
2656 ... 5
2657 ...
2658 ... And very friendly error messages:
2659 ...
2660 ... >>> 1/0
2661 ... To Infinity
2662 ... And
2663 ... Beyond
2664 ...
2665 ... You can use logic if you want:
2666 ...
2667 ... >>> if 0:
2668 ... ... blah
2669 ... ... blah
2670 ... ...
2671 ...
2672 ... Ho hum
2673 ... '''
2674
2675 >>> print(script_from_examples(text))
2676 # Here are examples of simple math.
2677 #
2678 # Python has super accurate integer addition
2679 #
2680 2 + 2
2681 # Expected:
2682 ## 5
2683 #
2684 # And very friendly error messages:
2685 #
2686 1/0
2687 # Expected:
2688 ## To Infinity
2689 ## And
2690 ## Beyond
2691 #
2692 # You can use logic if you want:
2693 #
2694 if 0:
2695 blah
2696 blah
2697 #
2698 # Ho hum
2699 <BLANKLINE>
2700 """

Callers 2

testsourceFunction · 0.85
debug_srcFunction · 0.85

Calls 8

DocTestParserClass · 0.85
isinstanceFunction · 0.85
_comment_lineFunction · 0.85
parseMethod · 0.45
appendMethod · 0.45
splitMethod · 0.45
popMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected