File: testcase.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 (46 lines) | stat: -rw-r--r-- 1,207 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
# frozen_string_literal: true

module Hypothesis
  # A TestCase class provides a concrete representation of
  # an executing test case. You do not normally need to use this
  # within the body of the test, but it exists to be used as
  # an argument to {Hypothesis::Possibilities::built_as}.
  # @!visibility private
  class TestCase
    # @!visibility private
    attr_reader :draws, :print_log, :print_draws, :wrapped_data

    # @!visibility private
    def initialize(wrapped_data, print_draws: false, record_draws: false)
      @wrapped_data = wrapped_data

      @draws = [] if record_draws
      @print_log = [] if print_draws
      @depth = 0
    end

    def assume(condition)
      raise UnsatisfiedAssumption unless condition
    end

    # @!visibility private
    def any(possible = nil, name: nil, &block)
      top_level = @depth.zero?

      begin
        @depth += 1
        possible ||= block
        @wrapped_data.start_draw
        result = possible.provide(&block)
        @wrapped_data.stop_draw
        if top_level
          draws&.push(result)
          print_log&.push([name, result.inspect])
        end
        result
      ensure
        @depth -= 1
      end
    end
  end
end