コード例 #1
0
    def evaluate_test_data(self, data):
        try:
            if self.collector is None:
                result = self.execute(data)
            else:  # pragma: no cover
                # This should always be a no-op, but the coverage tracer has
                # a bad habit of resurrecting itself.
                original = sys.gettrace()
                sys.settrace(None)
                try:
                    self.collector.data = {}
                    result = self.execute(data, collect=True)
                finally:
                    sys.settrace(original)
                    covdata = CoverageData()
                    self.collector.save_data(covdata)
                    self.coverage_data.update(covdata)
                    for filename in covdata.measured_files():
                        if is_hypothesis_file(filename):
                            continue
                        data.tags.update(
                            arc(filename, source, target)
                            for source, target in covdata.arcs(filename))
            if result is not None and self.settings.perform_health_check:
                fail_health_check(
                    self.settings,
                    ('Tests run under @given should return None, but '
                     '%s returned %r instead.') % (self.test.__name__, result),
                    HealthCheck.return_value)
            self.at_least_one_success = True
            return False
        except UnsatisfiedAssumption:
            data.mark_invalid()
        except (
                HypothesisDeprecationWarning,
                FailedHealthCheck,
                StopTest,
        ) + exceptions_to_reraise:
            raise
        except Exception as e:
            escalate_hypothesis_internal_error()
            data.__expected_traceback = traceback.format_exc()
            data.__expected_exception = e
            verbose_report(data.__expected_traceback)

            error_class, _, tb = sys.exc_info()

            origin = traceback.extract_tb(tb)[-1]
            filename = origin[0]
            lineno = origin[1]
            data.mark_interesting((error_class, filename, lineno))
コード例 #2
0
def print_coverage(coverage_data: CoverageData, coverage: Coverage):
    for f in coverage_data.measured_files():
        lines = coverage_data.lines(f)
        print('')
        print('')
        pprint(f)
        print('lines:')
        pprint(lines)
        print('')
        print('arcs:')
        pprint(coverage_data.arcs(f))
        print('')
        print('')
        zzz = coverage.analysis(f)
        pprint(zzz)
        print('')
        print()

    summary = coverage_data.line_counts()
    print('line_counts')
    pprint(summary)
コード例 #3
0
ファイル: constraint.py プロジェクト: spencerwuwu/PyEx-spoof
 def set_coverage(self, cov: coverage.CoverageData):
     for file in cov.measured_files():
         self.lines_covered[file] = frozenset(cov.lines(file))
         self.branches_covered[file] = frozenset(cov.arcs(file))
コード例 #4
0
ファイル: constraint.py プロジェクト: GroundPound/PyExZ3
 def set_coverage(self, cov: coverage.CoverageData):
     for file in cov.measured_files():
         self.lines_covered[file] = frozenset(cov.lines(file))
         self.branches_covered[file] = frozenset(cov.arcs(file))
コード例 #5
0
ファイル: core.py プロジェクト: rboulton/hypothesis
    def evaluate_test_data(self, data):
        if (
            time.time() - self.start_time >= HUNG_TEST_TIME_LIMIT
        ):
            fail_health_check(self.settings, (
                'Your test has been running for at least five minutes. This '
                'is probably not what you intended, so by default Hypothesis '
                'turns it into an error.'
            ), HealthCheck.hung_test)

        try:
            if self.collector is None:
                result = self.test_runner(data, reify_and_execute(
                    self.search_strategy, self.test,
                ))
            else:  # pragma: no cover
                # This should always be a no-op, but the coverage tracer has
                # a bad habit of resurrecting itself.
                original = sys.gettrace()
                sys.settrace(None)
                try:
                    self.collector.data = {}
                    result = self.test_runner(data, reify_and_execute(
                        self.search_strategy, self.test,
                        collector=self.collector
                    ))
                finally:
                    sys.settrace(original)
                    covdata = CoverageData()
                    self.collector.save_data(covdata)
                    self.coverage_data.update(covdata)
                    for filename in covdata.measured_files():
                        if is_hypothesis_file(filename):
                            continue
                        data.tags.update(
                            arc(filename, source, target)
                            for source, target in covdata.arcs(filename)
                        )
            if result is not None and self.settings.perform_health_check:
                fail_health_check(self.settings, (
                    'Tests run under @given should return None, but '
                    '%s returned %r instead.'
                ) % (self.test.__name__, result), HealthCheck.return_value)
            self.at_least_one_success = True
            return False
        except UnsatisfiedAssumption:
            data.mark_invalid()
        except (
            HypothesisDeprecationWarning, FailedHealthCheck,
            StopTest,
        ) + exceptions_to_reraise:
            raise
        except Exception as e:
            escalate_hypothesis_internal_error()
            data.__expected_traceback = traceback.format_exc()
            data.__expected_exception = e
            verbose_report(data.__expected_traceback)

            error_class, _, tb = sys.exc_info()

            origin = traceback.extract_tb(tb)[-1]
            filename = origin[0]
            lineno = origin[1]
            data.mark_interesting((error_class, filename, lineno))
コード例 #6
0
    def evaluate_test_data(self, data):
        if (time.time() - self.start_time >= HUNG_TEST_TIME_LIMIT):
            fail_health_check(
                self.settings,
                ('Your test has been running for at least five minutes. This '
                 'is probably not what you intended, so by default Hypothesis '
                 'turns it into an error.'), HealthCheck.hung_test)

        try:
            if self.collector is None:
                result = self.test_runner(
                    data, reify_and_execute(
                        self.search_strategy,
                        self.test,
                    ))
            else:  # pragma: no cover
                # This should always be a no-op, but the coverage tracer has
                # a bad habit of resurrecting itself.
                original = sys.gettrace()
                sys.settrace(None)
                try:
                    try:
                        self.collector.data = {}
                        self.collector.start()
                        result = self.test_runner(
                            data,
                            reify_and_execute(
                                self.search_strategy,
                                self.test,
                            ))
                    finally:
                        self.collector.stop()
                finally:
                    sys.settrace(original)
                    covdata = CoverageData()
                    self.collector.save_data(covdata)
                    self.coverage_data.update(covdata)
                    for filename in covdata.measured_files():
                        if is_hypothesis_file(filename):
                            continue
                        for lineno in covdata.lines(filename):
                            data.add_tag(Line(filename, lineno))
                        for source, target in covdata.arcs(filename):
                            data.add_tag(Arc(filename, source, target))
            if result is not None and self.settings.perform_health_check:
                fail_health_check(
                    self.settings,
                    ('Tests run under @given should return None, but '
                     '%s returned %r instead.') % (self.test.__name__, result),
                    HealthCheck.return_value)
            self.at_least_one_success = True
            return False
        except UnsatisfiedAssumption:
            data.mark_invalid()
        except (
                HypothesisDeprecationWarning,
                FailedHealthCheck,
                StopTest,
        ) + exceptions_to_reraise:
            raise
        except Exception:
            escalate_hypothesis_internal_error()
            data.__expected_exception = traceback.format_exc()
            verbose_report(data.__expected_exception)

            error_class, _, tb = sys.exc_info()

            origin = traceback.extract_tb(tb)[-1]
            filename = origin[0]
            lineno = origin[1]
            data.mark_interesting((error_class, filename, lineno))