当前位置: 首页>>代码示例>>Python>>正文


Python result.ProtoTestResult类代码示例

本文整理汇总了Python中green.result.ProtoTestResult的典型用法代码示例。如果您正苦于以下问题:Python ProtoTestResult类的具体用法?Python ProtoTestResult怎么用?Python ProtoTestResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ProtoTestResult类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_addSuccess

 def test_addSuccess(self):
     """
     addSuccess adds a test correctly
     """
     ptr = ProtoTestResult()
     test = proto_test(MagicMock())
     ptr.addSuccess(test)
     self.assertEqual(test, ptr.passing[0])
开发者ID:MinchinWeb,项目名称:green,代码行数:8,代码来源:test_result.py

示例2: test_addSkip

 def test_addSkip(self):
     "addSkip adds a test and reason correctly"
     ptr = ProtoTestResult()
     test = proto_test(MagicMock())
     reason = "some plausible reason"
     ptr.addSkip(test, reason)
     self.assertEqual(test, ptr.skipped[0][0])
     self.assertEqual(reason, ptr.skipped[0][1])
开发者ID:eavilesmejia,项目名称:green,代码行数:8,代码来源:test_result.py

示例3: poolRunner

def poolRunner(test_name, coverage_number=None, omit_patterns=[]):
    "I am the function that pool worker subprocesses run.  I run one unit test."
    # Each pool worker gets his own temp directory, to avoid having tests that
    # are used to taking turns using the same temp file name from interfering
    # with eachother.  So long as the test doesn't use a hard-coded temp
    # directory, anyway.
    saved_tempdir = tempfile.tempdir
    tempfile.tempdir = tempfile.mkdtemp()

    # Each pool starts its own coverage, later combined by the main process.
    if coverage_number and coverage:
        cov = coverage.coverage(
                data_file='.coverage.{}_{}'.format(
                    coverage_number, random.randint(0, 10000)),
                omit=omit_patterns)
        cov.start()

    # Create a structure to return the results of this one test
    result = ProtoTestResult()
    test = None
    try:
        test = loadTargets(test_name)
    except:
        err = sys.exc_info()
        t             = ProtoTest()
        t.module      = 'green.loader'
        t.class_name  = 'N/A'
        t.description = 'Green encountered an error loading the unit test.'
        t.method_name = 'poolRunner'
        result.addError(t, err)

    try:
        test.run(result)
    except:
        # Some frameworks like testtools record the error AND THEN let it
        # through to crash things.  So we only need to manufacture another error
        # if the underlying framework didn't, but either way we don't want to
        # crash.
        if not result.errors:
            err = sys.exc_info()
            t             = ProtoTest()
            t.module      = 'green.runner'
            t.class_name  = 'N/A'
            t.description = 'Green encountered an exception not caught by the underlying test framework.'
            t.method_name = 'poolRunner'
            result.addError(t, err)

    # Finish coverage
    if coverage_number and coverage:
        cov.stop()
        cov.save()

    # Restore the state of the temp directory
    shutil.rmtree(tempfile.tempdir)
    tempfile.tempdir = saved_tempdir
    return result
开发者ID:gitter-badger,项目名称:green,代码行数:56,代码来源:subprocess.py

示例4: test_addExpectedFailure

 def test_addExpectedFailure(self):
     "addExpectedFailure adds a test and error correctly"
     ptr = ProtoTestResult()
     test = proto_test(MagicMock())
     try:
         raise Exception
     except:
         err = proto_error(sys.exc_info())
     ptr.addExpectedFailure(test, err)
     self.assertEqual(test, ptr.expectedFailures[0][0])
     self.assertEqual(err, ptr.expectedFailures[0][1])
开发者ID:eavilesmejia,项目名称:green,代码行数:11,代码来源:test_result.py

示例5: test_addSubTest_error

 def test_addSubTest_error(self, mock_addFailure, mock_addError):
     """
     addSubTest calls over to addError for errors
     """
     ptr = ProtoTestResult()
     test = proto_test(MagicMock())
     test.failureException = KeyError
     subtest = MagicMock()
     err = [Exception]
     ptr.addSubTest(test, subtest, err)
     mock_addError.assert_called_with(subtest, err)
开发者ID:CleanCut,项目名称:green,代码行数:11,代码来源:test_result.py

示例6: poolRunner

def poolRunner(test_name, coverage_number=None, omit=[]):
    "I am the function that pool worker subprocesses run.  I run one unit test."
    # Each pool worker gets his own temp directory, to avoid having tests that
    # are used to taking turns using the same temp file name from interfering
    # with eachother.  So long as the test doesn't use a hard-coded temp
    # directory, anyway.
    saved_tempdir = tempfile.tempdir
    tempfile.tempdir = tempfile.mkdtemp()

    # Each pool starts its own coverage, later combined by the main process.
    if coverage_number and coverage:
        cov = coverage.coverage(
                data_file='.coverage.{}_{}'.format(
                    coverage_number, random.randint(0, 10000)),
                omit=omit)
        cov.start()

    # Create a structure to return the results of this one test
    result = ProtoTestResult()
    test = None
    try:
        test = getTests(test_name)
        test.run(result)
    except:
        err = sys.exc_info()
        t             = ProtoTest()
        t.module      = 'green.runner'
        t.class_name  = 'N/A'
        t.description = 'Green encountered an error loading the unit test itself.'
        t.method_name = 'poolRunner'
        result.addError(t, err)

    # Finish coverage
    if coverage_number and coverage:
        cov.stop()
        cov.save()

    # Restore the state of the temp directory
    shutil.rmtree(tempfile.tempdir)
    tempfile.tempdir = saved_tempdir
    return result
开发者ID:eavilesmejia,项目名称:green,代码行数:41,代码来源:subprocess.py

示例7: test_addUnexpectedSuccess

 def test_addUnexpectedSuccess(self):
     "addUnexpectedSuccess adds a test correctly"
     ptr = ProtoTestResult()
     test = proto_test(MagicMock())
     ptr.addUnexpectedSuccess(test)
     self.assertEqual(test, ptr.unexpectedSuccesses[0])
开发者ID:eavilesmejia,项目名称:green,代码行数:6,代码来源:test_result.py

示例8: test_addProtoTestResult

    def test_addProtoTestResult(self):
        "addProtoTestResult adds the correct things to the correct places"
        ptr = ProtoTestResult()

        err_t = proto_test(MagicMock())
        try:
            raise Exception
        except:
            err_e = proto_error(sys.exc_info())
        ptr.addError(err_t, err_e)

        ef_t = proto_test(MagicMock())
        try:
            raise Exception
        except:
            ef_e = proto_error(sys.exc_info())
        ptr.addExpectedFailure(ef_t, ef_e)

        fail_t = proto_test(MagicMock())
        try:
            raise Exception
        except:
            fail_e = proto_error(sys.exc_info())
        ptr.addFailure(fail_t, fail_e)

        pass_t = proto_test(MagicMock())
        ptr.addSuccess(pass_t)

        skip_t = proto_test(MagicMock())
        skip_r = proto_test(MagicMock())
        ptr.addSkip(skip_t, skip_r)

        us_t = proto_test(MagicMock())
        ptr.addUnexpectedSuccess(us_t)

        gtr = GreenTestResult(GreenStream(self.stream), None, 0)
        gtr.addProtoTestResult(ptr)

        self.assertEqual(gtr.errors, [(err_t, err_e)])
        self.assertEqual(gtr.expectedFailures, [(ef_t, ef_e)])
        self.assertEqual(gtr.failures, [(fail_t, fail_e)])
        self.assertEqual(gtr.passing, [pass_t])
        self.assertEqual(gtr.skipped, [(skip_t, skip_r)])
        self.assertEqual(gtr.unexpectedSuccesses, [us_t])
开发者ID:eavilesmejia,项目名称:green,代码行数:44,代码来源:test_result.py

示例9: poolRunner

def poolRunner(target, queue, coverage_number=None, omit_patterns=[]): # pragma: no cover
    """
    I am the function that pool worker processes run.  I run one unit test.
    """
    # Each pool worker gets his own temp directory, to avoid having tests that
    # are used to taking turns using the same temp file name from interfering
    # with eachother.  So long as the test doesn't use a hard-coded temp
    # directory, anyway.
    saved_tempdir = tempfile.tempdir
    tempfile.tempdir = tempfile.mkdtemp()

    def cleanup():
        # Restore the state of the temp directory
        shutil.rmtree(tempfile.tempdir, ignore_errors=True)
        tempfile.tempdir = saved_tempdir
        queue.put(None)
        # Finish coverage
        if coverage_number and coverage:
            cov.stop()
            cov.save()

    # Each pool starts its own coverage, later combined by the main process.
    if coverage_number and coverage:
        cov = coverage.coverage(
                data_file='.coverage.{}_{}'.format(
                    coverage_number, random.randint(0, 10000)),
                omit=omit_patterns)
        cov._warn_no_data = False
        cov.start()

    # What to do each time an individual test is started
    already_sent = set()
    def start_callback(test):
        # Let the main process know what test we are starting
        test = proto_test(test)
        if test not in already_sent:
            queue.put(test)
            already_sent.add(test)

    def finalize_callback(test_result):
        # Let the main process know what happened with the test run
        queue.put(test_result)

    result = ProtoTestResult(start_callback, finalize_callback)
    test = None
    try:
        test = loadTargets(target)
    except:
        err = sys.exc_info()
        t             = ProtoTest()
        t.module      = 'green.loader'
        t.class_name  = 'N/A'
        t.description = 'Green encountered an error loading the unit test.'
        t.method_name = 'poolRunner'
        result.startTest(t)
        result.addError(t, err)
        result.stopTest(t)
        queue.put(t)
        queue.put(result)
        cleanup()
        return

    if getattr(test, 'run', False):
        # Loading was successful, lets do this
        try:
            test.run(result)
        except:
            # Some frameworks like testtools record the error AND THEN let it
            # through to crash things.  So we only need to manufacture another error
            # if the underlying framework didn't, but either way we don't want to
            # crash.
            if result.errors:
                queue.put(result)
            else:
                err = sys.exc_info()
                result.startTest(test)
                result.addError(test, err)
                result.stopTest(test)
                queue.put(result)
    else:
        # loadTargets() returned an object without a run() method, probably None
        description = 'Test loader returned an un-runnable object.  Is "{}" importable from your current location?  Maybe you forgot an __init__.py in your directory?  Unrunnable object looks like: {} of type {} with dir {}'.format(
                target, str(test), type(test), dir(test))
        err = (TypeError, TypeError(description), None)
        t             = ProtoTest()
        target_list = target.split('.')
        t.module      = '.'.join(target_list[:-2]) if len(target_list) > 1 else target
        t.class_name  = target.split('.')[-2] if len(target_list) > 1 else 'UnknownClass'
        t.description = description
        t.method_name = target.split('.')[-1] if len(target_list) > 1 else 'unknown_method'
        result.startTest(t)
        result.addError(t, err)
        result.stopTest(t)

    cleanup()
开发者ID:LeoHuckvale,项目名称:green,代码行数:95,代码来源:process.py

示例10: poolRunner

def poolRunner(target, queue, coverage_number=None, omit_patterns=[], cov_config_file=True):  # pragma: no cover
    """
    I am the function that pool worker processes run.  I run one unit test.

    coverage_config_file is a special option that is either a string specifying
    the custom coverage config file or the special default value True (which
    causes coverage to search for it's standard config files).
    """
    # Each pool worker gets his own temp directory, to avoid having tests that
    # are used to taking turns using the same temp file name from interfering
    # with eachother.  So long as the test doesn't use a hard-coded temp
    # directory, anyway.
    saved_tempdir = tempfile.tempdir
    tempfile.tempdir = tempfile.mkdtemp()

    def cleanup():
        # Restore the state of the temp directory
        # TODO: Make this not necessary on macOS+Python3 (see #173)
        if sys.version_info[0] == 2:
            shutil.rmtree(tempfile.tempdir, ignore_errors=True)
        tempfile.tempdir = saved_tempdir
        queue.put(None)
        # Finish coverage
        if coverage_number:
            cov.stop()
            cov.save()

    # Each pool starts its own coverage, later combined by the main process.
    if coverage_number:
        cov = coverage.coverage(
                data_file='.coverage.{}_{}'.format(
                    coverage_number, random.randint(0, 10000)),
                omit=omit_patterns,
                config_file=cov_config_file)
        cov._warn_no_data = False
        cov.start()

    # What to do each time an individual test is started
    already_sent = set()

    def start_callback(test):
        # Let the main process know what test we are starting
        test = proto_test(test)
        if test not in already_sent:
            queue.put(test)
            already_sent.add(test)

    def finalize_callback(test_result):
        # Let the main process know what happened with the test run
        queue.put(test_result)

    result = ProtoTestResult(start_callback, finalize_callback)
    test = None
    try:
        loader = GreenTestLoader()
        test = loader.loadTargets(target)
    except:
        err = sys.exc_info()
        t             = ProtoTest()
        t.module      = 'green.loader'
        t.class_name  = 'N/A'
        t.description = 'Green encountered an error loading the unit test.'
        t.method_name = 'poolRunner'
        result.startTest(t)
        result.addError(t, err)
        result.stopTest(t)
        queue.put(result)
        cleanup()
        return

    if getattr(test, 'run', False):
        # Loading was successful, lets do this
        try:
            test.run(result)
            # If your class setUpClass(self) method crashes, the test doesn't
            # raise an exception, but it does add an entry to errors.  Some
            # other things add entries to errors as well, but they all call the
            # finalize callback.
            if result and (not result.finalize_callback_called) and getattr(result, 'errors', False):
                queue.put(test)
                queue.put(result)
        except:
            # Some frameworks like testtools record the error AND THEN let it
            # through to crash things.  So we only need to manufacture another
            # error if the underlying framework didn't, but either way we don't
            # want to crash.
            if result.errors:
                queue.put(result)
            else:
                err = sys.exc_info()
                result.startTest(test)
                result.addError(test, err)
                result.stopTest(test)
                queue.put(result)
    else:
        # loadTargets() returned an object without a run() method, probably
        # None
        description = ('Test loader returned an un-runnable object.  Is "{}" '
                       'importable from your current location?  Maybe you '
                       'forgot an __init__.py in your directory?  Unrunnable '
#.........这里部分代码省略.........
开发者ID:CleanCut,项目名称:green,代码行数:101,代码来源:process.py


注:本文中的green.result.ProtoTestResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。