def runTests(r):
    sys.path.insert(0, success)
    grepKeep = o(grepTests=[], grepSuites=[], grep=["keep"])
    code = "runProcess(success, 'theTests.spyReporter', 'False', grepKeep)"
    result = runProcess(success, "theTests.spyReporter", "False", grepKeep)
    testState = getTestState()
    passed = (
        result.code == 0
        and result.stdout is None
        and result.stderr is None
        and hasExpectedRootTests(testState)
        and hasExpectedRootSuites(testState)
        and spyReporter.lastCalledState.wasCalled is True
        and spyReporter.lastCalledState.testState is testState
    )
    if not passed:
        r.addError(code)

    grepTwoTest = o(grepTests=["^two test$"], grepSuites=[], grep=[])
    code = "runProcess(success, 'theTests.spyReporter', 'False', grepTwoTest)"
    result = runProcess(success, "theTests.spyReporter", "False", grepTwoTest)
    testState = getTestState()
    passed = (
        result.code == 0
        and result.stdout is None
        and result.stderr is None
        and hasTest2(testState)
        and len(testState.suites) == 0
        and spyReporter.lastCalledState.wasCalled is True
        and spyReporter.lastCalledState.testState is testState
    )
    if not passed:
        r.addError(code)

    grepSubSuite1 = o(grepTests=[], grepSuites=["^sub suite 1 keep$"], grep=[])
    code = "runProcess(success, 'theTests.spyReporter', 'False', grepSubSuite1)"
    result = runProcess(success, "theTests.spyReporter", "False", grepSubSuite1)
    testState = getTestState()
    passed = (
        result.code == 0
        and result.stdout is None
        and result.stderr is None
        and len(testState.tests) == 0
        and hasSubSuite1(testState)
        and spyReporter.lastCalledState.wasCalled is True
        and spyReporter.lastCalledState.testState is testState
    )
    if not passed:
        r.addError(code)

    sys.path.pop(0)
    del sys.modules["tests"]
    return r
Esempio n. 2
0
def runTests(r):
    sys.path.insert(0, success)
    code = "runProcess(success, 'theTests.spyReporter', 'False', noGrepArgs)"
    result = runProcess(success, "theTests.spyReporter", "False", noGrepArgs)
    testState = getTestState()
    passed = (result.code == 0 and result.stdout is None
              and result.stderr is None and hasExpectedRootTests(testState)
              and hasExpectedRootSuites(testState)
              and spyReporter.lastCalledState.wasCalled is True
              and spyReporter.lastCalledState.testState is testState)
    if not passed:
        r.addError(code)

    sys.path.pop(0)
    del sys.modules["tests"]
    return r
Esempio n. 3
0
def runTests(r):
    sys.path.insert(0, success)
    code = "runProcess(success, 'theTests.spyReporter', 'False', noGrepArgs)"
    result = runProcess(success, "theTests.spyReporter", "False", noGrepArgs)
    testState = getTestState()
    test1 = testState.tests[0]
    suite1 = testState.suites[0]
    suite2 = suite1.suites[0]
    passed = (result.code == 0 and result.stdout is None
              and result.stderr is None and len(testState.tests) == 1
              and len(testState.suites) == 1
              and test1.after.__name__ == "afterTest1"
              and test1.after.numTimesRan == 1
              and test1.before.__name__ == "beforeTest1"
              and test1.before.numTimesRan == 1
              and test1.before.__name__ == "beforeTest1"
              and test1.before.numTimesRan == 1
              and suite1.after.__name__ == "afterSuite1"
              and suite1.after.numTimesRan == 1
              and suite1.before.__name__ == "beforeSuite1"
              and suite1.before.numTimesRan == 1 and len(suite1.afterEach) == 1
              and len(suite1.beforeEach) == 1
              and suite1.afterEach[0].__name__ == "afterEachSuite1"
              and suite1.afterEach[0].numTimesRan == 2
              and suite1.beforeEach[0].__name__ == "beforeEachSuite1"
              and suite1.beforeEach[0].numTimesRan == 2
              and len(suite2.afterEach) == 2 and len(suite2.beforeEach) == 2
              and suite2.afterEach[1].__name__ == "afterEachSuite2"
              and suite2.afterEach[1].numTimesRan == 1
              and suite2.beforeEach[1].__name__ == "beforeEachSuite2"
              and suite2.beforeEach[1].numTimesRan == 1
              and spyReporter.lastCalledState.testState is testState)
    if not passed:
        print("suite1.after.numTimesRan: " + str(suite1.after.numTimesRan))
        r.addError(code)

    sys.path.pop(0)
    return r
def runTests(r):
    sys.path.insert(0, success)
    code = "runProcess(success, 'theTests.spyReporter', 'False', noGrepArgs)"
    result = runProcess(success, "theTests.spyReporter", "False", noGrepArgs)
    testState = getTestState()
    successFiles = set(os.listdir(success))
    passed = (result.code == 0 and result.stdout is None
              and result.stderr is None and len(testState.tests) == 1
              and testState.after.__name__ != "noop"
              and testState.before.__name__ != "noop"
              and "after-ran.txt" in successFiles
              and "before-ran.txt" in successFiles
              and spyReporter.lastCalledState.testState is testState)
    if not passed:
        print(result.stderr)
        r.addError(code)

    rm([
        path.join(success, "after-ran.txt"),
        path.join(success, "before-ran.txt"),
    ])

    sys.path.pop(0)
    return r
Esempio n. 5
0
def runTests(r):
    sys.path.insert(0, success)
    code = "runProcess(success, 'theTests.spyReporter', 'False', noGrepArgs)"
    result = runProcess(success, "theTests.spyReporter", "False", noGrepArgs)
    testState = getTestState()
    passed = (result.code == 0 and result.stdout is None
              and result.stderr is None and len(testState.tests) == 1
              and spyReporter.lastCalledState.testState is testState)
    if not passed:
        r.addError(code)

    #
    # silent
    #
    spyReporter.resetLastCalledState()
    code = "runProcess(success, 'theTests.spyReporter', 'True', noGrepArgs)"
    result = runProcess(success, "theTests.spyReporter", "True", noGrepArgs)
    testState = getTestState()
    passed = (result.code == 0 and result.stdout is None
              and result.stderr is None and len(testState.tests) == 1
              and spyReporter.lastCalledState.wasCalled is False)
    if not passed:
        r.addError(code)

    #
    # fail
    #
    del sys.modules["tests"]
    sys.path[0] = fail
    spyReporter.resetLastCalledState()
    code = "runProcess(fail, 'theTests.spyReporter', 'False', noGrepArgs)"
    result = runProcess(fail, "theTests.spyReporter", "False", noGrepArgs)
    testState = getTestState()
    expectedErrorStr = "test failed"
    passed = (result.code == 1 and result.stdout is None
              and result.stderr is None and len(testState.tests) == 1
              and expectedErrorStr in str(testState.tests[0].error)
              and spyReporter.lastCalledState.wasCalled is True
              and spyReporter.lastCalledState.testState is testState)
    if not passed:
        r.addError(code)

    #
    # error
    #
    del sys.modules["tests"]
    sys.path[0] = error
    spyReporter.resetLastCalledState()
    code = "runProcess(error, 'theTests.spyReporter', 'False', noGrepArgs)"
    result = runProcess(error, "theTests.spyReporter", "False", noGrepArgs)
    expectedErrorStr = "test import error"
    passed = (result.code == 2 and result.stdout is None
              and expectedErrorStr in result.stderr
              and spyReporter.lastCalledState.wasCalled is False)
    if not passed:
        r.addError(code)

    #
    # successDir
    #
    del sys.modules["tests"]
    sys.path[0] = successDir
    spyReporter.resetLastCalledState()
    code = "runProcess(successDir, 'theTests.spyReporter', 'False', noGrepArgs)"
    result = runProcess(successDir, "theTests.spyReporter", "False",
                        noGrepArgs)
    testState = getTestState()
    passed = (result.code == 0 and result.stdout is None
              and result.stderr is None and len(testState.tests) == 1
              and spyReporter.lastCalledState.wasCalled is True)
    if not passed:
        r.addError(code)

    #
    # noTests
    #
    del sys.modules["tests"]
    sys.path[0] = noTests
    spyReporter.resetLastCalledState()
    code = "runProcess(noTests, 'theTests.spyReporter', 'False', noGrepArgs)"
    result = runProcess(noTests, "theTests.spyReporter", "False", noGrepArgs)
    testState = getTestState()
    expectedErrorStr = "No tests were found in any python files"
    passed = (result.code == 2 and result.stdout is None
              and expectedErrorStr in result.stderr
              and len(testState.tests) == 0
              and spyReporter.lastCalledState.wasCalled is False)
    if not passed:
        r.addError(code)

    sys.path.pop(0)
    return r