Beispiel #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)
Beispiel #2
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)
Beispiel #3
0
    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()

    elif printResults:
Beispiel #4
0
]

# 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)))
Beispiel #5
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
    ))
Beispiel #6
0
            ):
                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:
                    print(info('    Expected message is missing.'))
Beispiel #7
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
    ))