Exemple #1
0
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)
        print(info('    Expected:'))
        for r, e in zip(result, expectedResult):
            if r == e:
                print(e, end='')
            else:
                print(fail(e), end='')
        print()
Exemple #2
0
    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)
if printSummary:
    print(
        "%s: %s tests run, %s failures detected." % (fail("FAIL") if failures else succeed("PASS"), testsRun, failures)
    )

writeSummary(testsRun, failures)
sys.exit(int(bool(failures)))
Exemple #3
0
    writeSummary,
    succeed,
    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]

Exemple #4
0

# Run tests {{{1
testsRun = 0
failures = 0
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   :'), format(stimulus))
        print(info('    Result  :'), format(result))
        print(info('    Expected:'), format(expected))
        if result and expected:
            print(info('    Diff:'))
            showDiff(result, expected, indent=8*' ')


# Print test summary {{{1
numTests = len(testCases)
assert testsRun == numTests, "Incorrect number of tests run (%s of %s)." % (testsRun, numTests)
if printSummary:
    print('%s: %s tests run, %s failures detected.' % (
        fail('FAIL') if failures else succeed('PASS'), testsRun, failures
Exemple #5
0
                [clean(m) for m in messages] != [clean(m) for m in expectedMessages]
            ):
                failure = True
        elif messages != expectedMessages:
            failure = True
        if type(warnings) == list:
            if (
                [clean(w) for w in warnings] != [clean(w) for w in expectedWarnings]
            ):
                failure = True
        elif warnings != expectedWarnings:
            failure = True

        if failure:
            failures += 1
            print("%s:" % fail('Failure detected (%s):' % failures))
            print("%s: %s" % (info('    Given'), stimulus))
            print("%s: %s" % (
                info('    Result  ')
              , ', '.join([str(result), calc.format((result, units)), units])
            ))
            print("%s: %s" % (
                info('    Expected')
              , ', '.join([
                    str(expectedResult)
                  , str(expectedFormattedResult)
                  , str(expectedUnits)
                ])
            ))
            if messages != expectedMessages:
                if expectedMessages == True:
Exemple #6
0

# Run tests {{{1
testsRun = 0
failures = 0
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   :'), format(stimulus))
        print(info('    Result  :'), format(result))
        print(info('    Expected:'), format(expected))
        if result and expected:
            print(info('    Diff:'))
            showDiff(result, expected, indent=8*' ')


# Print test summary {{{1
numTests = len(testCases)
assert testsRun == numTests, "Incorrect number of tests run (%s of %s)." % (testsRun, numTests)
if printSummary:
    print('%s: %s tests run, %s failures detected.' % (
        fail('FAIL') if failures else succeed('PASS'), testsRun, failures