def make_default_module_maintest(modname, modpath=None, test_code=None):
    """
    make_default_module_maintest

    DEPRICATE

    TODO: use path relative to home dir if the file is a script

    Args:
        modname (str):  module name

    Returns:
        str: text source code

    CommandLine:
        python -m utool.util_autogen --test-make_default_module_maintest

    References:
        http://legacy.python.org/dev/peps/pep-0338/

    Example:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_autogen import *  # NOQA
        >>> modname = 'utool.util_autogen'
        >>> text = make_default_module_maintest(modname)
        >>> result = str(text)
        >>> print(result)
    """
    import utool as ut
    # Need to use python -m to run a module
    # otherwise their could be odd platform specific errors.
    #python -c "import utool, {modname};
    # ut.doctest_funcs({modname}, allexamples=True)"
    #in_pythonpath, module_type, path = find_modname_in_pythonpath(modname)
    # only use the -m if it is part of a package directory

    if modpath is not None:
        moddir = dirname(modpath)
        pkginit_fpath = join(moddir, '__init__.py')
        use_modrun = exists(pkginit_fpath)
    else:
        use_modrun = True

    if use_modrun:
        pyargs = '-m ' + modname
    else:
        if ut.WIN32:
            modpath = normpath(modpath).replace(expanduser('~'), '%HOME%')
            pyargs = '-B ' + ut.ensure_unixslash(modpath)
        else:
            modpath = normpath(modpath).replace(expanduser('~'), '~')
            pyargs = modpath

    cmdline = ut.codeblock(
        '''
        python {pyargs}
        ''')

    if not use_modrun:
        if ut.WIN32:
            augpath = 'set PYTHONPATH=%PYTHONPATH%' + os.pathsep + moddir
        else:
            augpath = 'export PYTHONPATH=$PYTHONPATH' + os.pathsep + moddir
        cmdline = augpath + '\n' + cmdline

    cmdline = ut.indent(cmdline, ' ' * 8).lstrip(' ').format(pyargs=pyargs)

    if test_code is None:
        test_code = ut.codeblock(
            r'''
            import multiprocessing
            multiprocessing.freeze_support()  # for win32
            import utool as ut  # NOQA
            ut.doctest_funcs()
            ''')

    test_code = ut.indent(test_code, ' ' * 4).lstrip(' ')

    text = ut.codeblock(
        r'''
        # STARTBLOCK
        if __name__ == '__main__':
            r"""
            CommandLine:
                {cmdline}
            """
            {test_code}
        # ENDBLOCK
        '''
    ).format(cmdline=cmdline, test_code=test_code)
    print('test_code = {!r}'.format(test_code))
    text = remove_codeblock_syntax_sentinals(text)
    return text
def make_default_module_maintest ( modname , modpath = None , test_code = None ) : import utool as ut if modpath is not None : moddir = dirname ( modpath ) pkginit_fpath = join ( moddir , '__init__.py' ) use_modrun = exists ( pkginit_fpath ) else : use_modrun = True if use_modrun : pyargs = '-m ' + modname else : if ut . WIN32 : modpath = normpath ( modpath ) . replace ( expanduser ( '~' ) , '%HOME%' ) pyargs = '-B ' + ut . ensure_unixslash ( modpath ) else : modpath = normpath ( modpath ) . replace ( expanduser ( '~' ) , '~' ) pyargs = modpath cmdline = ut . codeblock ( '''
        python {pyargs}
        ''' ) if not use_modrun : if ut . WIN32 : augpath = 'set PYTHONPATH=%PYTHONPATH%' + os . pathsep + moddir else : augpath = 'export PYTHONPATH=$PYTHONPATH' + os . pathsep + moddir cmdline = augpath + '\n' + cmdline cmdline = ut . indent ( cmdline , ' ' * 8 ) . lstrip ( ' ' ) . format ( pyargs = pyargs ) if test_code is None : test_code = ut . codeblock ( r'''
            import multiprocessing
            multiprocessing.freeze_support()  # for win32
            import utool as ut  # NOQA
            ut.doctest_funcs()
            ''' ) test_code = ut . indent ( test_code , ' ' * 4 ) . lstrip ( ' ' ) text = ut . codeblock ( r'''
        # STARTBLOCK
        if __name__ == '__main__':
            r"""
            CommandLine:
                {cmdline}
            """
            {test_code}
        # ENDBLOCK
        ''' ) . format ( cmdline = cmdline , test_code = test_code ) print ( 'test_code = {!r}' . format ( test_code ) ) text = remove_codeblock_syntax_sentinals ( text ) return text
make_default_module_maintest

    DEPRICATE

    TODO: use path relative to home dir if the file is a script

    Args:
        modname (str):  module name

    Returns:
        str: text source code

    CommandLine:
        python -m utool.util_autogen --test-make_default_module_maintest

    References:
        http://legacy.python.org/dev/peps/pep-0338/

    Example:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_autogen import *  # NOQA
        >>> modname = 'utool.util_autogen'
        >>> text = make_default_module_maintest(modname)
        >>> result = str(text)
        >>> print(result)