File: errors.rb

package info (click to toggle)
python-hypothesis 6.138.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,272 kB
  • sloc: python: 62,853; ruby: 1,107; sh: 253; makefile: 41; javascript: 6
file content (61 lines) | stat: -rw-r--r-- 1,589 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# frozen_string_literal: true

module Hypothesis
  # A generic superclass for all errors thrown by
  # Hypothesis.
  class HypothesisError < RuntimeError
  end

  # Indicates that Hypothesis was not able to find
  # enough valid examples for the test to be meaningful.
  # (Currently this is only thrown if Hypothesis did not
  # find *any* valid examples).
  class Unsatisfiable < HypothesisError
  end

  # Indicates that the Hypothesis API has been used
  # incorrectly in some manner.
  class UsageError < HypothesisError
  end

  # @!visibility private
  class UnsatisfiedAssumption < HypothesisError
  end

  # @!visibility private
  class DataOverflow < HypothesisError
  end

  if defined?(RSpec::Core::MultipleExceptionError)
    MultipleExceptionErrorParent = RSpec::Core::MultipleExceptionError
  # :nocov:
  else
    class MultipleExceptionErrorParent < StandardError
      def initialize(*exceptions)
        super()

        @all_exceptions = exceptions.to_a
      end

      attr_reader :all_exceptions
    end
  end

  class MultipleExceptionError < MultipleExceptionErrorParent
    def message
      jd = HypothesisJunkDrawer
      "Test raised #{all_exceptions.length} distinct errors:\n\n" +
        all_exceptions.map do |e|
          location = jd.find_first_relevant_line(e.backtrace).sub(/:in.+$/, '')
          backtrace = jd.prune_backtrace(e.backtrace)
          "#{e.class} at #{location}:\n" \
            "#{e.message}\n#{backtrace.map { |s| '  ' + s }
              .join("\n")}"
        end.join("\n\n")
    end

    def backtrace
      []
    end
  end
end