Example #1
0
"""

# 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')
opt = clp.addOption(key='tests', shortName='t', longName='tests')
Example #2
0
# 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
      , '10e-9'         # fromEngFmt() result with units stripped
Example #3
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
colorResultTemplate = '\033[%d;3%dmthis is %%s\033[0m, this is not.'
noColorResultTemplate = '\033[0mthis is %s\033[0m, this is not.'
testColors = [
    ('black',   colorResultTemplate % (0, 0))
  , ('red',     colorResultTemplate % (0, 1))
  , ('green',   colorResultTemplate % (0, 2))
  , ('yellow',  colorResultTemplate % (0, 3))
  , ('blue',    colorResultTemplate % (0, 4))
  , ('magenta', colorResultTemplate % (0, 5))
  , ('cyan',    colorResultTemplate % (0, 6))
  , ('white',   colorResultTemplate % (0, 7))