summary files should contain a dictionary with keys: 'tests', 'failures'. """ # preliminaries {{{1 # imports {{{2 import os, sys # use yaml if available, otherwise use pickle try: from yaml import load as loadSummary, dump as dumpSummary except ImportError: from pickle import load as loadSummary, dump as dumpSummary from textcolors import Colors from cmdline import commandLineProcessor # define useful colors {{{2 colors = Colors() status = colors.colorizer('blue') info = colors.colorizer('magenta') fail = colors.colorizer('red') succeed = colors.colorizer('green') exception = colors.colorizer('Red') # configure the command line processor {{{2 clp = commandLineProcessor() clp.setDescription('Run Tests', 'Utility for recursively running self tests') clp.setNumArgs((0,), '[test ...]') clp.setHelpParams(key='-h', colWidth=14) opt = clp.addOption(key='fast', shortName='f', longName='fast') opt.setSummary('take any shortcuts possible to speed testing') opt = clp.addOption(key='nosummary', shortName='s', longName='nosummary') opt.setSummary('do not print the summary of test results')
#!/usr/bin/env python # Imports {{{1 import sys from engfmt import \ fromEngFmt, toEngFmt, \ toNumber, isNumber, stripUnits, \ allToEngFmt, allFromEngFmt from runtests import cmdLineOpts, writeSummary from textcolors import Colors # Initialization {{{1 fast, printSummary, printTests, printResults, colorize, parent = cmdLineOpts() testsRun = 0 failures = 0 colors = Colors(colorize) succeed = colors.colorizer('green') fail = colors.colorizer('red') info = colors.colorizer('magenta') status = colors.colorizer('cyan') # Test cases {{{1 testCases = [ ( '1ns' # input , '1e-9' # fromEngFmt() result with units stripped , ('1e-9', 's') # fromEngFmt() result without units stripped , '1ns' # toNumber() -> toEngFmt() result , '1n' # stripUnits() result , True # isNumber() result ), ( '10ns' # input
# Test Colorizer # Imports {{{1 from runtests import cmdLineOpts, writeSummary from textcolors import Colors, stripColors, _BaseColors, _colorRegex import sys # Initialization {{{1 fast, printSummary, printTests, printResults, colorize, parent = cmdLineOpts() testsRun = 0 failures = 0 # simple names are required for colors to support color replacements for each in _BaseColors: assert _colorRegex.match('<%s>' % each) color = Colors() color.addAlias('error', 'red') color.addAlias('fails', 'Red') color.addAlias('warning', 'yellow') color.addAlias('okay', 'Green') color.addAlias('passes', 'green') # cannot use pass as that is a keyword color.addAlias('narrate', 'cyan') color.addAlias('info', 'Magenta') color.addAlias('hot', 'red') color.addAlias('cold', 'Cyan') testColors = Colors(colorize) status = testColors.colorizer('cyan') succeed = testColors.colorizer('green') fail = testColors.colorizer('red') # Test cases {{{1