コード例 #1
0
def showDiff(achieved, expected, indent=''):
    diff = Differ().compare(
        expected.splitlines(),
        achieved.splitlines()
    )
    for each in diff:
        if each[0] == '+':
            print(indent+succeed(each))
        elif each[0] == '-':
            print(indent+info(each))
        elif each[0] == '?':
            print(indent+status(each))
        else:
            print(indent+each)
コード例 #2
0
ファイル: test.inform.py プロジェクト: KenKundert/inform
def showDiff(achieved, expected, indent=''):
    diff = Differ().compare(
        expected.splitlines(),
        achieved.splitlines()
    )
    for each in diff:
        if each[0] == '+':
            print(indent+succeed(each))
        elif each[0] == '-':
            print(indent+info(each))
        elif each[0] == '?':
            print(indent+status(each))
        else:
            print(indent+each)
コード例 #3
0
ファイル: test.scripting.py プロジェクト: KenKundert/ec
    warnings += [warning]

calc = Calculator(
    allActions,
    Display(defaultFormat, defaultDigits),
    messagePrinter=grabMessages,
    warningPrinter=grabWarnings,
)
for index, case in enumerate(testCases):
    messages = []
    warnings = []
    testsRun += 1
    stimulus = ' '.join(['ec', case['stimulus']])
    expectedResult = dedent(case['output']).strip()
    if printTests:
        print(status('Trying %d:' % index), stimulus)

    calc.clear()
    pipe = Popen(stimulus, shell=True, bufsize=-1, stdout=PIPE)
    pipe.wait()
    result = dedent(pipe.stdout.read().decode()).strip()
    if pipe.returncode != 0:
        failures += 1
        print(fail('Failure detected (%s):' % failures))
        print(info('    Given:'), stimulus)
        print(info('    Result  : invalid return code:'), pipe.returncode)
    elif expectedResult != result:
        failures += 1
        print(fail('Failure detected (%s):' % failures))
        print(info('    Given:'), stimulus)
        print(info('    Result  :'), '\n' + result)
コード例 #4
0
ファイル: test.main.py プロジェクト: KenKundert/abraxas
        name="thump",
        stimulus="pw.generate_password(master_password='******')",
        result="charlatan routine stagy printout",
    ),
    Case(name="stiff", stimulus="pw = PasswordGenerator(stateless=True, logger=logger)"),
    Case(name="lanyard", stimulus="pw.read_accounts(template='=anum')"),
    Case(name="nibble", stimulus="account = pw.get_account('fuzzy')"),
    Case(name="racialist", stimulus="pw.generate_password(master_password='******')", result="BwHWJgh3MPDh"),
]

# Run tests {{{1
for case in testCases:

    testsRun += 1
    if printTests:
        print(status("Trying %d (%s):" % (testsRun, case.name)), case.stimulus)

    failure = case.run()

    if failure:
        failures += 1
        name, stimulus, result, expected, kind = failure
        print(fail("Unexpected %s (%s):" % (kind, failures)))
        print(info("    Case    :"), name)
        print(info("    Given   :"), stimulus)
        print(info("    Result  :"), result)
        print(info("    Expected:"), expected)

# Print test summary {{{1
numTests = 76
assert testsRun == numTests, "Incorrect number of tests run (%s of %s)." % (testsRun, numTests)
コード例 #5
0
    fail,
    status,
    pythonCmd,
    coverageCmd,
)
import doctest
import sys

# Initialization {{{1
fast, printSummary, printTests, printResults, colorize, parent, coverage = cmdLineOpts(
)

# use the inform color package before unloading it.
failure = fail('FAIL:')
success = succeed('PASS:'******'Trying:')


# Unload the inform module so that it is reloaded during the doctests
# This is needed because doctest replaces stdout with its own stream so it
# can capture the output of the program being tested. Inform was imported from
# runtests, and it already saved away stdout. By unloading it here, it will be
# imported again after doctest has replaced stdout.
def unload_inform():
    to_delete = [m for m in sys.modules.keys() if m.startswith('inform')]
    for module in to_delete:
        del sys.modules[module]


if coverage is False:
    python = pythonCmd()