Пример #1
0
def main(parser):
  parser.add_option('--debug', dest='debug', action='store_true', default=False, help='Break into pdb when an assertion fails')
  parser.add_option('-i', '--incremental', dest='incremental', action='store_true', default=False, help='Run tests one at a time.')
  parser.add_option('-s', '--stop', dest='stop_on_error', action='store_true', default=False, help='Stop running tests on error.')
  parser.add_option('-m', '--manually-handled-tests', dest='manual_handling_allowed', action='store_true', default=False, help='Only run tests flagged with a \'requires_manual_handling\' attribute.')
  (options, args) = parser.parse_args()

  # install hook on set_trace if --debug
  if options.debug:
    import exceptions
    class DebuggingAssertionError(exceptions.AssertionError):
      def __init__(self, *args):
        exceptions.AssertionError.__init__(self, *args)
        print "Assertion failed, entering PDB..."
        import pdb
        if hasattr(sys, '_getframe'):
          pdb.Pdb().set_trace(sys._getframe().f_back.f_back)
        else:
          pdb.set_trace()
    unittest.TestCase.failureException = DebuggingAssertionError

    def hook(*args):
      import traceback, pdb
      traceback.print_exception(*args)
      pdb.pm()
    sys.excepthook = hook

    try:
      import browser
      browser.debug_mode = True
    except:
      pass

  # make sure cwd is the base directory!
  os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))

  if len(args) > 0:
    suites = discover(args, options.manual_handling_allowed)
  else:
    suites = discover(['.*'], options.manual_handling_allowed)

  r = unittest.TextTestRunner()
  if not options.incremental:
    message_loop.set_unittests_running(True)
    res = r.run(suites)
    message_loop.set_unittests_running(False)
    if res.wasSuccessful():
      return 0
    return 255
  else:
    message_loop.set_unittests_running(True)
    ok = True
    for s in suites:
      if isinstance(s, unittest.TestSuite):
        for t in s:
          print '----------------------------------------------------------------------'
          print 'Running %s' % str(t)
          res = r.run(t)
          if not res.wasSuccessful():
            ok = False
            if options.stop_on_error:
              break
        if ok == False and options.stop_on_error:
          break
      else:
        res = r.run(s)
        if not res.wasSuccessful():
          ok = False
          if options.stop_on_error:
            break
    message_loop.set_unittests_running(False)
    if ok:
      return 0
    return 255
Пример #2
0
 def do_test():
     message_loop.set_unittests_running(True)
     test.run(result)
Пример #3
0
def main(parser):
  parser.add_option('--debug', dest='debug', action='store_true', default=False, help='Break into pdb when an assertion fails')
  parser.add_option('-i', '--incremental', dest='incremental', action='store_true', default=False, help='Run tests one at a time.')
  parser.add_option('-s', '--stop', dest='stop_on_error', action='store_true', default=False, help='Stop running tests on error.')
  parser.add_option('-m', '--manually-handled-tests', dest='manual_handling_allowed', action='store_true', default=False, help='Only run tests flagged with a \'requires_manual_handling\' attribute.')
  parser.add_option('--check-for-fd-leaks', dest='check_for_fd_leaks', action='store_true', default=False, help='Checks for fd leaks after each test run.')
  (options, args) = parser.parse_args()

  # install hook on set_trace if --debug
  if options.debug:
    import exceptions
    class DebuggingAssertionError(exceptions.AssertionError):
      def __init__(self, *args):
        exceptions.AssertionError.__init__(self, *args)
        print "Assertion failed, entering PDB..."
        import pdb
        if hasattr(sys, '_getframe'):
          pdb.Pdb().set_trace(sys._getframe().f_back.f_back)
        else:
          pdb.set_trace()
    unittest.TestCase.failureException = DebuggingAssertionError

    def hook(*args):
      import traceback, pdb
      traceback.print_exception(*args)
      pdb.pm()
    sys.excepthook = hook

    try:
      import browser
      browser.debug_mode = True
    except:
      pass

  if options.check_for_fd_leaks and not options.incremental:
    print "--check-for-fd-leaks forces --incremental."
    options.incremental = True

  # make sure cwd is the base directory!
  os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))

  def args_filter(test):
    if len(args) == 0:
      return True

    for x in args:
      if str(test).find(x) != -1:
        return True
    return False

  def manual_test_filter(test):
    module_name = test.__class__.__module__
    module = sys.modules[module_name]

    requires_manual_handling = False
    if hasattr(module, 'requires_manual_handling'):
      requires_manual_handling = module.requires_manual_handling
    if requires_manual_handling != options.manual_handling_allowed:
      return False
    return True

  def module_filename_filter(test):
    if test.__class__.__name__.startswith("_"):
      return False

    module_name = test.__class__.__module__
    module = sys.modules[module_name]
    if module.__file__.startswith("."):
      return False
    return True

  def test_filter(test):
    if not module_filename_filter(test):
      return False
    if not manual_test_filter(test):
      return False
    if not args_filter(test):
      return False
    return True

  all_tests_suite = discover("src", "*_test.py", ".")
  selected_tests_suite = filter_suite(all_tests_suite, test_filter)

  if not options.incremental:
    r = unittest.TextTestRunner()
    message_loop.set_unittests_running(True)
    res = r.run(selected_tests_suite)
    message_loop.set_unittests_running(False)
    if res.wasSuccessful():
      return 0
    return 255
  else:
    r = IncrementalTestRunner(options)
    message_loop.set_unittests_running(True)
    ok = True
    for t in get_tests_from_suite(selected_tests_suite):
      assert isinstance(t, unittest.TestCase)
      print '----------------------------------------------------------------------'
      print 'Running %s' % str(t)

      res = r.run(t)
      if not res.wasSuccessful():
        ok = False
        if options.stop_on_error:
          break
    message_loop.set_unittests_running(False)
    if ok:
      return 0
    return 255
Пример #4
0
 def do_test():
     message_loop.set_unittests_running(True)
     test.run(result)
Пример #5
0
def main(parser):
    parser.add_option('--debug',
                      dest='debug',
                      action='store_true',
                      default=False,
                      help='Break into pdb when an assertion fails')
    parser.add_option('-i',
                      '--incremental',
                      dest='incremental',
                      action='store_true',
                      default=False,
                      help='Run tests one at a time.')
    parser.add_option('-s',
                      '--stop',
                      dest='stop_on_error',
                      action='store_true',
                      default=False,
                      help='Stop running tests on error.')
    parser.add_option(
        '-m',
        '--manually-handled-tests',
        dest='manual_handling_allowed',
        action='store_true',
        default=False,
        help=
        'Only run tests flagged with a \'requires_manual_handling\' attribute.'
    )
    parser.add_option('--check-for-fd-leaks',
                      dest='check_for_fd_leaks',
                      action='store_true',
                      default=False,
                      help='Checks for fd leaks after each test run.')
    (options, args) = parser.parse_args()

    # install hook on set_trace if --debug
    if options.debug:
        import exceptions

        class DebuggingAssertionError(exceptions.AssertionError):
            def __init__(self, *args):
                exceptions.AssertionError.__init__(self, *args)
                print "Assertion failed, entering PDB..."
                import pdb
                if hasattr(sys, '_getframe'):
                    pdb.Pdb().set_trace(sys._getframe().f_back.f_back)
                else:
                    pdb.set_trace()

        unittest.TestCase.failureException = DebuggingAssertionError

        def hook(*args):
            import traceback, pdb
            traceback.print_exception(*args)
            pdb.pm()

        sys.excepthook = hook

        try:
            import browser
            browser.debug_mode = True
        except:
            pass

    if options.check_for_fd_leaks and not options.incremental:
        print "--check-for-fd-leaks forces --incremental."
        options.incremental = True

    # make sure cwd is the base directory!
    os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))

    def args_filter(test):
        if len(args) == 0:
            return True

        for x in args:
            if str(test).find(x) != -1:
                return True
        return False

    def manual_test_filter(test):
        module_name = test.__class__.__module__
        module = sys.modules[module_name]

        requires_manual_handling = False
        if hasattr(module, 'requires_manual_handling'):
            requires_manual_handling = module.requires_manual_handling
        if requires_manual_handling != options.manual_handling_allowed:
            return False
        return True

    def module_filename_filter(test):
        if test.__class__.__name__.startswith("_"):
            return False

        module_name = test.__class__.__module__
        module = sys.modules[module_name]
        if module.__file__.startswith("."):
            return False
        return True

    def test_filter(test):
        if not module_filename_filter(test):
            return False
        if not manual_test_filter(test):
            return False
        if not args_filter(test):
            return False
        return True

    all_tests_suite = discover("src", "*_test.py", ".")
    selected_tests_suite = filter_suite(all_tests_suite, test_filter)

    if not options.incremental:
        r = unittest.TextTestRunner()
        message_loop.set_unittests_running(True)
        res = r.run(selected_tests_suite)
        message_loop.set_unittests_running(False)
        if res.wasSuccessful():
            return 0
        return 255
    else:
        r = IncrementalTestRunner(options)
        message_loop.set_unittests_running(True)
        ok = True
        for t in get_tests_from_suite(selected_tests_suite):
            assert isinstance(t, unittest.TestCase)
            print '----------------------------------------------------------------------'
            print 'Running %s' % str(t)

            res = r.run(t)
            if not res.wasSuccessful():
                ok = False
                if options.stop_on_error:
                    break
        message_loop.set_unittests_running(False)
        if ok:
            return 0
        return 255