How to use the xdoctest.doctest_example.Config function in xdoctest

To help you get started, we’ve selected a few xdoctest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Erotemic / xdoctest / xdoctest / __main__.py View on Github external
import xdoctest

    options = ns['options']
    if options is None:
        options = ''
        if exists('pytest.ini'):
            from six.moves import configparser
            parser = configparser.ConfigParser()
            parser.read('pytest.ini')
            try:
                options = parser.get('pytest', 'xdoctest_options')
            except configparser.NoOptionError:
                pass
        ns['options'] = options
    from xdoctest import doctest_example
    config = doctest_example.Config()._populate_from_cli(ns)

    # from xdoctest.directive import parse_directive_optstr
    # default_runtime_state = {}
    # for optpart in options.split(','):
    #     if optpart:
    #         directive = parse_directive_optstr(optpart)
    #         if directive is not None:
    #             default_runtime_state[directive.name] = directive.positive

    # # Specify a default doctest_example.Config state
    # config = {
    #     'default_runtime_state': default_runtime_state,
    # offset_linenos = ns['offset_linenos']
    #     'offset_linenos': offset_linenos,
    # colored = ns['colored']
    #     'colored': colored,
github Erotemic / xdoctest / xdoctest / __main__.py View on Github external
# modname_or_path_group = parser.add_mutually_exclusive_group()
    # modname_or_path_group.add_argument('modpath', help='module name or path')
    parser.add_argument(*('-m', '--modname'), type=str,
                        help='module name or path. If specified positional modules are ignored',
                        default=None)

    parser.add_argument(*('-c', '--command'), type=str,
                        help='a doctest name or a command (list|all|). '
                        'Defaults to all',
                        default=None)

    parser.add_argument(*('--style',), type=str, help='choose your style',
                        choices=['auto', 'google', 'freeform'], default='auto')

    from xdoctest import doctest_example
    doctest_example.Config()._update_argparse_cli(parser.add_argument)

    # parser.add_argument(*('--options',), type=str,
    #                     help='specify the default directive state',
    #                     default=None)

    # parser.add_argument(*('--offset',), dest='offset_linenos', action='store_true',
    #                     help=('Doctest outputs will display line numbers '
    #                           'wrt to the source file.'))

    # parser.add_argument(*('--nocolor',), dest='colored', action='store_true',
    #                     help=('Disable ANSI coloration.'))

    parser.add_argument(*('--durations',), type=int,
                        help=('specify execution times for slowest N tests.'
                              'N=0 will show times for all tests'),
                        default=None)
github Erotemic / xdoctest / xdoctest / runner.py View on Github external
_log('modpath_or_name = {!r}'.format(modpath_or_name))
    _log('durations = {!r}'.format(durations))
    _log('config = {!r}'.format(config))
    _log('verbose = {!r}'.format(verbose))
    _log('style = {!r}'.format(style))
    _log('------+ /DEBUG +------')

    # Determine package name via caller if not specified
    if modpath_or_name is None:
        frame_parent = dynamic.get_parent_frame()
        modpath = frame_parent.f_globals['__file__']
    else:
        modpath = core._rectify_to_modpath(modpath_or_name)

    if config is None:
        config = doctest_example.Config()

    command, style, verbose = _parse_commandline(command, style, verbose, argv)

    from functools import partial
    _log = partial(log, verbose=verbose)

    _log('Start doctest_module({!r})'.format(modpath_or_name))
    _log('Listing tests')

    if command is None:
        # Display help if command is not specified
        _log('Not testname given. Use `all` to run everything or'
             ' pick from a list of valid choices:')
        command = 'list'

    # TODO: command should not be allowed to be the requested doctest name in
github Erotemic / xdoctest / xdoctest / doctest_example.py View on Github external
def __init__(self, *args, **kwargs):
        super(Config, self).__init__(*args, **kwargs)
        self.update({
            # main options exposed by command line runner/plugin
            'colored': hasattr(sys.stdout, 'isatty') and sys.stdout.isatty(),
            'reportchoice': 'udiff',
            'default_runtime_state': {},
            'offset_linenos': False,
            'global_exec': None,
            'on_error': 'raise',
            'partnos': False,
            'verbose': 1,
        })
github Erotemic / xdoctest / xdoctest / plugin.py View on Github external
def _prepare_internal_config(self):

        class NamespaceLike(object):
            def __init__(self, config):
                self.config = config
            def __getitem__(self, attr):
                return self.config.getvalue('xdoctest_' + attr)
            def __getattr__(self, attr):
                return self.config.getvalue('xdoctest_' + attr)

        ns = NamespaceLike(self.config)

        from xdoctest import doctest_example
        self._examp_conf = doctest_example.Config()._populate_from_cli(ns)
github Erotemic / xdoctest / xdoctest / doctest_example.py View on Github external
def __init__(self, docsrc, modpath=None, callname=None, num=0,
                 lineno=1, fpath=None, block_type=None, mode='pytest'):

        # if we know the google block type it is recorded
        self.block_type = block_type

        self.config = Config()

        self.modpath = modpath
        self.fpath = fpath
        if modpath is None:
            self.modname = ''
            self.modpath = ''
        else:
            if fpath is not None:
                assert fpath == modpath, (
                    'only specify fpath for non-python files')
            self.fpath = modpath
            self.modname = static.modpath_to_modname(modpath)
        if callname is None:
            self.callname = ''
        else:
            self.callname = callname