def test_caught_exception(): # showme should not accept builtins and variables if pi.showme("a string"): # showme returns False for bad inputs raise ValueError("pi.showme should not acccept variables") if pi.showme(sum): raise ValueError("pi.showme should not acccept builtins")
def test_showme(): # try with a function that works if not pi.showme(pi.showme): raise ValueError("pi.showme failed to print a funciton") # try with a class if not pi.showme(Console): raise ValueError("pi.showme failed to print a class") # try with a class' method if not pi.showme(Console.print): raise ValueError("pi.showme failed to print a class method")
def test_showme_custom_class(): t = Test() pi.showme(t) pi.showme(Test) pi.showme(t.a) pi.showme(Test.a) pi.showme(t.hi) pi.showme(Test.hi)
import pyinspect as pi pi.search(pi, "search") pi.showme(pi.find.search)
""" This tutorial shows how to print a function's source code """ # import pyinspect import pyinspect as pi # Print a function's source code pi.showme(pi.search)
""" This tutorial shows how to print the source code of a class' method to the consol """ # import the class you're using from rich.console import Console # import pyinspect import pyinspect as pi # Print a function's source code pi.showme(Console.export_text)