The imports:
import difflib import io import os from pathlib import Path import re import shutil import sys sys.path.append(str(Path(__file__).resolve().parent.parent)) from asciidoc import asciidoc # noqa: E402
Some random ranges:
def iif(condition, iftrue, iffalse=None): """ Immediate if c.f. ternary ?: operator. False value defaults to '' if the true value is a string. False value defaults to 0 if the true value is a number. """ if iffalse is None: if isinstance(iftrue, str): iffalse = '' if type(iftrue) in (int, float): iffalse = 0 if condition: return iftrue else: return iffalse def normalize_data(lines): """ Strip comments and trailing blank strings from lines. """ result = [s for s in lines if not s.startswith('#')] strip_end(result) return result class AsciiDocTest(object): if __name__ == '__main__': # guarantee a stable timestamp matching the test fixtures os.environ['SOURCE_DATE_EPOCH'] = '1038184662' # Process command line options. from argparse import ArgumentParser parser = ArgumentParser( description='Run AsciiDoc conformance tests specified in configuration' 'FILE.' ) msg = 'Use configuration file CONF_FILE (default configuration file is '\ 'testasciidoc.conf in testasciidoc.py directory)' parser.add_argument( '-v', '--version', action='version', version='%(prog)s {}'.format(__version__) ) parser.add_argument('-f', '--conf-file', help=msg) subparsers = parser.add_subparsers(metavar='command', dest='command') subparsers.required = True subparsers.add_parser('list', help='List tests') options = ArgumentParser(add_help=False) options.add_argument('-n', '--number', type=int, help='Test number to run') options.add_argument('-b', '--backend', type=str, help='Backend to run') subparsers.add_parser('run', help='Execute tests', parents=[options]) subparser = subparsers.add_parser( 'update', help='Regenerate and update test data', parents=[options] ) subparser.add_argument( '--force', action='store_true', help='Update all test data overwriting existing data' ) args = parser.parse_args() conffile = os.path.join(os.path.dirname(sys.argv[0]), 'testasciidoc.conf') force = 'force' in args and args.force is True if args.conf_file is not None: conffile = args.conf_file if not os.path.isfile(conffile): message('missing CONF_FILE: %s' % conffile) sys.exit(1) tests = AsciiDocTests(conffile) cmd = args.command number = None backend = None if 'number' in args: number = args.number if 'backend' in args: backend = args.backend if backend and backend not in BACKENDS: message('illegal BACKEND: {:s}'.format(backend)) sys.exit(1) if number is not None and (number < 1 or number > len(tests.tests)): message('illegal test NUMBER: {:d}'.format(number)) sys.exit(1) if cmd == 'run': tests.run(number, backend) if tests.failed: sys.exit(1) elif cmd == 'update': tests.update(number, backend, force=force) elif cmd == 'list': tests.list()
Using ; as separator:
def iif(condition, iftrue, iffalse=None): """ Immediate if c.f. ternary ?: operator. False value defaults to '' if the true value is a string. False value defaults to 0 if the true value is a number. """ if iffalse is None: if isinstance(iftrue, str): iffalse = '' if type(iftrue) in (int, float): iffalse = 0 if condition: return iftrue else: return iffalse def normalize_data(lines): """ Strip comments and trailing blank strings from lines. """ result = [s for s in lines if not s.startswith('#')] strip_end(result) return result