Ejemplo n.º 1
0
def main():
    skipTests = [
    ]  #['sequence_memory', 'chimp_test', 'aim_trainer', 'typing', 'verbal_memory', 'number_memory', 'visual_memory']

    driver = Browser()
    dashURL = 'https://humanbenchmark.com/dashboard'
    driver.implicitly_wait(0.05)
    driver.go_to(dashURL)
    driver.click('Accept all')

    for i, test in enumerate(tests.get_tests(), 1):
        if test.__name__ in skipTests:
            print('Skipping:', test.__name__)
            continue

        print('Completing:', test.__name__)

        if driver.get_current_url() != dashURL:
            print('At incorrect page:', driver.get_current_url())
            driver.go_to(dashURL)

        time.sleep(1)
        driver.click('Play', number=i)
        driver.click('Start')
        test(driver)

        time.sleep(0.2)
        driver.click('Save score')
        driver.implicitly_wait(0.05)
        driver.go_to(dashURL)

    #Keep browser open until user exit
    _ = input('Press enter to exit:')
Ejemplo n.º 2
0
def test_offline(verbosity=1):
    """ Run the unit tests in 'tests.py' """
    import tests as tests_module
    tests = tests_module.get_tests()

    ntests = len(tests)
    ncorrect = 0

    for index, (testname, getargs, testanswer, expected, fn_name, type) in enumerate(tests):
        dispindex = index+1
        summary = test_summary(dispindex, ntests)

        try:
            if callable(getargs):
                getargs = getargs()

            answer = run_test((index, type, fn_name, getargs), get_lab_module())
        except NotImplementedError:
            print "%d: (%s: Function not yet implemented, NotImplementedError raised)" % (dispindex, testname)
            continue
        except Exception:
            show_exception(summary, testname)
            continue

        # This prevents testanswer from throwing errors. eg, if return type is
        # incorrect, testanswer returns False instead of raising an exception.
        try:
            correct = testanswer(answer)
        except:
            correct = False
        show_result(summary, testname, correct, answer, expected, verbosity)
        if correct: ncorrect += 1

    print "Passed %d of %d tests." % (ncorrect, ntests)
    return ncorrect == ntests
Ejemplo n.º 3
0
def test_offline(verbosity=1):
    """ Run the unit tests in 'tests.py' """
    import tests as tests_module

    #    tests = [ (x[:-8],
    #               getattr(tests_module, x),
    #               getattr(tests_module, "%s_testanswer" % x[:-8]),
    #               getattr(tests_module, "%s_expected" % x[:-8]),
    #               "_".join(x[:-8].split('_')[:-1]))
    #              for x in tests_module.__dict__.keys() if x[-8:] == "_getargs" ]

    tests = tests_module.get_tests()

    ntests = len(tests)
    ncorrect = 0

    for index, (testname, getargs, testanswer, expected, fn_name,
                type) in enumerate(tests):
        dispindex = index + 1
        summary = test_summary(dispindex, ntests)

        try:
            if callable(getargs):
                getargs = getargs()

            answer = run_test((index, type, fn_name, getargs),
                              get_lab_module())
        except NotImplementedError:
            print "%d: (%s: Function not yet implemented, NotImplementedError raised)" % (
                dispindex, testname)
            continue
        except Exception:
            show_exception(summary, testname)
            continue

        # This prevents testanswer from throwing errors. eg, if return type is
        # incorrect, testanswer returns False instead of raising an exception.
        try:
            correct = testanswer(answer)
        except (KeyboardInterrupt,
                SystemExit):  # Allow user to interrupt tester
            raise
        except:
            correct = False
        show_result(summary, testname, correct, answer, expected, verbosity)
        if correct: ncorrect += 1

    print "Passed %d of %d tests." % (ncorrect, ntests)
    return ncorrect == ntests
Ejemplo n.º 4
0
def test_offline(verbosity=1):
    """ Run the unit tests in 'tests.py' """
    import tests as tests_module

    tests = tests_module.get_tests()
    ntests = len(tests)
    ncorrect = 0

    for index, (testname, getargs, testanswer, expected, fn_name,
                type) in enumerate(tests):
        dispindex = index + 1
        summary = test_summary(dispindex, ntests)

        try:
            if callable(getargs):
                getargs = getargs()

            answer = run_test((index, type, fn_name, getargs),
                              get_lab_module())
        except NotImplementedError:
            print(
                "%d: (%s: Function not yet implemented, NotImplementedError raised)"
                % (dispindex, testname))
            continue
        except Exception:
            show_exception(summary, testname)
            continue

        # This prevents testanswer from throwing errors. eg, if return type is
        # incorrect, testanswer returns False instead of raising an exception.
        try:
            correct = testanswer(answer)
        except NotImplementedError:
            print("%d: (%s: No answer given, NotImplementedError raised)" %
                  (dispindex, testname))
            continue
        except (KeyboardInterrupt,
                SystemExit):  # Allow user to interrupt tester
            raise
        except Exception:
            #raise   # To debug local tests by allowing them to raise exceptions, uncomment this
            correct = False

        show_result(summary, testname, correct, answer, expected, verbosity)
        if correct: ncorrect += 1

    print("Passed %d of %d tests." % (ncorrect, ntests))
    return ncorrect == ntests
Ejemplo n.º 5
0
def test_offline(verbosity=1, tests_module=None):
    """ Run the unit tests in 'tests.py' """
    if tests_module is None:
        # This was taking too long so I imported it once in the command
        # line and then passed it as a parameter each subsequent time to keep
        # the run time down.
        import tests as tests_module


#    tests = [ (x[:-8],
#               getattr(tests_module, x),
#               getattr(tests_module, "%s_testanswer" % x[:-8]),
#               getattr(tests_module, "%s_expected" % x[:-8]),
#               "_".join(x[:-8].split('_')[:-1]))
#              for x in tests_module.__dict__.keys() if x[-8:] == "_getargs" ]

    tests = tests_module.get_tests()

    ntests = len(tests)
    ncorrect = 0

    for index, (testname, getargs, testanswer, expected, fn_name,
                type) in enumerate(tests):
        dispindex = index + 1
        summary = test_summary(dispindex, ntests)

        try:
            if callable(getargs):
                getargs = getargs()

            answer = run_test((index, type, fn_name, getargs),
                              get_lab_module())
        except NotImplementedError:
            print(
                "%d: (%s: Function not yet implemented, NotImplementedError raised)"
                % (index, testname))
            continue
        except Exception:
            show_exception(summary, testname)
            continue

        correct = testanswer(answer)
        show_result(summary, testname, correct, answer, expected, verbosity)
        if correct: ncorrect += 1

    print("Passed %d of %d tests." % (ncorrect, ntests))
    return ncorrect == ntests
Ejemplo n.º 6
0
def test_offline(verbosity=1):
    """ Run the unit tests in 'tests.py' """
    import tests as tests_module

    #    tests = [ (x[:-8],
    #               getattr(tests_module, x),
    #               getattr(tests_module, "%s_testanswer" % x[:-8]),
    #               getattr(tests_module, "%s_expected" % x[:-8]),
    #               "_".join(x[:-8].split('_')[:-1]))
    #              for x in tests_module.__dict__.keys() if x[-8:] == "_getargs" ]

    tests = tests_module.get_tests()

    ntests = len(tests)
    ncorrect = 0

    for index, (testname, getargs, testanswer, expected, fn_name, type) in enumerate(tests):
        dispindex = index + 1
        summary = test_summary(dispindex, ntests)

        try:
            if callable(getargs):
                getargs = getargs()

            answer = run_test((index, type, fn_name, getargs), get_lab_module())
        except NotImplementedError:
            print "%d: (%s: Function not yet implemented, NotImplementedError raised)" % (dispindex, testname)
            continue
        except Exception:
            show_exception(summary, testname)
            continue

        # This prevents testanswer from throwing errors. eg, if return type is
        # incorrect, testanswer returns False instead of raising an exception.
        try:
            correct = testanswer(answer)
        except (KeyboardInterrupt, SystemExit):  # Allow user to interrupt tester
            raise
        except:
            correct = False
        show_result(summary, testname, correct, answer, expected, verbosity)
        if correct:
            ncorrect += 1

    print "Passed %d of %d tests." % (ncorrect, ntests)
    return ncorrect == ntests
Ejemplo n.º 7
0
def test_offline(verbosity=1):
    """ Run the unit tests in 'tests.py' """
    import tests as tests_module

    #    tests = [ (x[:-8],
    #               getattr(tests_module, x),
    #               getattr(tests_module, "%s_testanswer" % x[:-8]),
    #               getattr(tests_module, "%s_expected" % x[:-8]),
    #               "_".join(x[:-8].split('_')[:-1]))
    #              for x in tests_module.__dict__.keys() if x[-8:] == "_getargs" ]

    tests = tests_module.get_tests()

    ntests = len(tests)
    ncorrect = 0

    for index, (testname, getargs, testanswer, expected, fn_name,
                type) in enumerate(tests):
        dispindex = index + 1
        summary = test_summary(dispindex, ntests)

        try:
            if callable(getargs):
                getargs = getargs()

            answer = run_test((index, type, fn_name, getargs),
                              get_lab_module())
        except NotImplementedError:
            print(
                "%d: (%s: Function not yet implemented, NotImplementedError raised)"
                % (index, testname))
            continue
        except Exception:
            show_exception(summary, testname)
            continue

        correct = testanswer(answer)
        show_result(summary, testname, correct, answer, expected, verbosity)
        if correct: ncorrect += 1

    print("Passed %d of %d tests." % (ncorrect, ntests))
    if ncorrect == ntests:
        print(
            "You're done! Run 'python %s submit' to submit your code and have it graded."
            % sys.argv[0])
Ejemplo n.º 8
0
def _run_tests(squadron_dir, commit_info):
    commit_keys = sorted(commit_info)
    for service_name in commit_keys:
        version = commit_info[service_name]['version']
        tests_to_run = tests.get_tests(squadron_dir, service_name, version)

        log.info("Running %s tests for %s v%s", len(tests_to_run),
                service_name, version)
        failed_tests = tests.run_tests(tests_to_run, commit_info[service_name])

        if failed_tests:
            log.error("Failed tests for %s v%s: ", service_name, version)
            for failed_test, exitcode in failed_tests.items():
                log.error("\t%s failed with exitcode %s", failed_test, exitcode)

            log.error("Aborting due to %s failed tests (total tests %s)",
                    len(failed_tests), len(tests_to_run))
            raise TestException()
def test_offline(verbosity=1):
    """ Run the unit tests in 'tests.py' """
    import tests as tests_module

    #    tests = [ (x[:-8],
    #               getattr(tests_module, x),
    #               getattr(tests_module, "%s_testanswer" % x[:-8]),
    #               getattr(tests_module, "%s_expected" % x[:-8]),
    #               "_".join(x[:-8].split('_')[:-1]))
    #              for x in tests_module.__dict__.keys() if x[-8:] == "_getargs" ]

    tests = tests_module.get_tests()

    ntests = len(tests)
    ncorrect = 0

    for index, (testname, getargs, testanswer, expected, fn_name, type) in enumerate(tests):
        dispindex = index + 1
        summary = test_summary(dispindex, ntests)

        try:
            if callable(getargs):
                getargs = getargs()

            answer = run_test((index, type, fn_name, getargs), get_lab_module())
        except NotImplementedError:
            print "%d: (%s: Function not yet implemented, NotImplementedError raised)" % (index, testname)
            continue
        except Exception:
            show_exception(summary, testname)
            continue

        correct = testanswer(answer)
        show_result(summary, testname, correct, answer, expected, verbosity)
        if correct:
            ncorrect += 1

    print "Passed %d of %d tests." % (ncorrect, ntests)
    if ncorrect == ntests:
        print "You're done! Run 'python %s submit' to submit your code and have it graded." % sys.argv[0]
Ejemplo n.º 10
0
def test_offline(verbosity=1):
    """ Run the unit tests in 'tests.py' """
    import tests as tests_module
    
#    tests = [ (x[:-8],
#               getattr(tests_module, x),
#               getattr(tests_module, "%s_testanswer" % x[:-8]),
#               getattr(tests_module, "%s_expected" % x[:-8]),
#               "_".join(x[:-8].split('_')[:-1]))
#              for x in tests_module.__dict__.keys() if x[-8:] == "_getargs" ]

    tests = tests_module.get_tests()
    
    ntests = len(tests)
    ncorrect = 0
    
    for index, (testname, getargs, testanswer, expected, fn_name, type) in enumerate(tests):
        dispindex = index+1
        summary = test_summary(dispindex, ntests, fn_name)
        
        try:
            if isinstance(getargs, collections.Callable):
                getargs = getargs()
                
            answer = run_test((index, type, fn_name, getargs), get_lab_module())
        except NotImplementedError:
            print("%d: (%s: Function not yet implemented, NotImplementedError raised)" % (index, testname))
            continue
        except Exception:
            show_exception(summary, testname)
            continue
        
        correct = testanswer(answer, original_val = getargs)
        show_result(summary, testname, correct, answer, expected, verbosity)
        if correct: ncorrect += 1
    
    print("Passed %d of %d tests." % (ncorrect, ntests))
    return ncorrect == ntests
Ejemplo n.º 11
0
#!/usr/bin/env python
from tests import get_tests
import unittest

if __name__ == "__main__":
    runner = unittest.TextTestRunner()
    runner.run(get_tests())