def run_all(): for file in ['basicexample', 'blanklines', 'fix_input_whitespace']: output = process_docstr(mod2doctest.convert(src='%s.py' % file, target=None, run_doctest=False, )) known_to_be_good_output = process_docstr(open('%s_doctest.py' % file).read()) print `output` print `known_to_be_good_output` assert(output == known_to_be_good_output)
if __name__ == '__main__': import mod2doctest mod2doctest.convert( r'C:\Python24\python.exe', src=True, add_autogen=False, target='_doctest', run_doctest=False, ) #>Some examples of connecting to functions #>------------------------------------------------------------------------------ #>Prevent function from firing #>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #>Let's say you want to 1. monitor and 2. prevent every time something is #>opening a file: import pyjack def fakeopen(orgopen, *args, **kwargs): print 'Here is the org open fn: %r' % orgopen print 'Someone trying to open a file with args:%r kwargs%r' % ( args, kwargs, ) return () pyjack.connect(open, proxyfn=fakeopen)
if __name__ == '__main__': # Anything inside a __name__ == '__main__' block is removed import mod2doctest mod2doctest.convert('python', src=True, run_doctest=False) #>Test Setup #>------------------------------------------------------------------------------ import os import shutil import time import threading #>Setup test: note -- the weird newlines / whitespacing is to stress mod2doctest #>------------------------------------------------------------------------------ dir_main = 'dirmain' try: shutil.rmtree(dir_main) except OSError: pass finally: print 'Setup complete' os.mkdir(dir_main) #>Make threading class #>------------------------------------------------------------------------------
if __name__ == '__main__': import mod2doctest mod2doctest.convert('python', src=True, target='_doctest', run_doctest=True) class Foobar(object): def __init__(self, i): print 'Hi #%d.' % i for i in range(2): print Foobar(i) for i in range(3): print Foobar(i) class Baz(object): def __init__(self, i): print 'Bye #%d.' % i for i in range(3): print Baz(i) def doit(): print 'did it ..'
if __name__ == "__main__": # Anything inside a __name__ == '__main__' block is removed import mod2doctest mod2doctest.convert("python", src=True, target="_doctest", run_doctest=False) # >Test Setup # >------------------------------------------------------------------------------ import os import shutil import time import threading print "Imports complete" # >Setup test: note -- the weird newlines / whitespacing is to stress mod2doctest # >------------------------------------------------------------------------------ dir_main = "dirmain" try: shutil.rmtree(dir_main) except OSError: pass finally:
if __name__ == '__main__': import mod2doctest mod2doctest.convert(r'C:\Python24\python.exe', src=True, add_autogen=False, target='_doctest', run_doctest=False,) #>Some examples of connecting to functions #>------------------------------------------------------------------------------ #>Prevent function from firing #>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #>Let's say you want to 1. monitor and 2. prevent every time something is #>opening a file: import pyjack def fakeopen(orgopen, *args, **kwargs): print 'Here is the org open fn: %r' % orgopen print 'Someone trying to open a file with args:%r kwargs%r' %(args, kwargs,) return () pyjack.connect(open, proxyfn=fakeopen) for line in open('/some/path', 'r'): print line #>Filtering args #>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ def absmin(orgmin, seq): return orgmin([abs(x) for x in seq])
if __name__ == '__main__': # All __name__ == '__main__' blocks are removed, serving as mod2doctest # comments import mod2doctest mod2doctest.convert('python', src=True, target='_doctest', run_doctest=False, add_testmod=False, add_autogen=False) #>Welcome to mod2doctest #>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #| #|Just enter in some python #| #|.. warning:: #| make sure to examine your resulting docstr to make sure output is as #| expected! #|The basics: print 'Hello World!' #>Extended Example #>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #|A little more: somelist = [100, 2, -20, 340, 0, 0, 10, 10, 88, -3, 100, 2, -99, -1] sorted(set(somelist))