Class: Emendate::Examples::ExampleSet
- Inherits:
-
Object
- Object
- Emendate::Examples::ExampleSet
- Includes:
- Taggable
- Defined in:
- lib/emendate/examples/example_set.rb
Overview
Holder for a list of TestableExamples, with some convenience
methods
Instance Attribute Summary collapse
-
#examples ⇒ Object
readonly
Returns the value of attribute examples.
Instance Method Summary collapse
- #all_tags ⇒ Object
- #by_type_pattern(date_only: false, stage: :tokens) ⇒ Object
- #failures ⇒ Object
- #get_example_data(data_method:, examples_method: :examples) ⇒ Object
-
#initialize(data_sets: "", date_types: "", rows: nil) ⇒ ExampleSet
constructor
A new instance of ExampleSet.
- #not_run ⇒ Object
- #report_failures ⇒ Object
- #report_fingerprint(type) ⇒ Object
- #report_type_patterns(date_only: false, stage: :tokens) ⇒ Object
- #run_tests(tests: nil, fail_fast: false, mode: :normal) ⇒ Object
- #runnable_tests ⇒ Object
- #successes ⇒ Object
- #summary ⇒ Object
- #tags(type) ⇒ Object
- #to_s ⇒ Object (also: #inspect)
- #type_patterns(date_only: false, stage: :tokens) ⇒ Object
Methods included from Taggable
Constructor Details
#initialize(data_sets: "", date_types: "", rows: nil) ⇒ ExampleSet
Returns a new instance of ExampleSet.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/emendate/examples/example_set.rb', line 16 def initialize(data_sets: "", date_types: "", rows: nil) @rows = rows || Examples::RowSet.new(data_sets: data_sets, date_types: date_types) .rows .sort_by do |row| row.dateval_occurrence end (data_sets, date_types) @examples = @rows.group_by { |row| row.test_fingerprint } .values .map { |rows| Examples::TestableExample.new(rows) } end |
Instance Attribute Details
#examples ⇒ Object (readonly)
Returns the value of attribute examples.
14 15 16 |
# File 'lib/emendate/examples/example_set.rb', line 14 def examples @examples end |
Instance Method Details
#all_tags ⇒ Object
31 32 33 |
# File 'lib/emendate/examples/example_set.rb', line 31 def examples.map(&:all_tags).flatten.uniq.sort end |
#by_type_pattern(date_only: false, stage: :tokens) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/emendate/examples/example_set.rb', line 35 def by_type_pattern(date_only: false, stage: :tokens) examples.group_by do |example| example.type_pattern(date_only: date_only, stage: stage) end .sort_by { |pattern, data| pattern } end |
#failures ⇒ Object
42 43 44 |
# File 'lib/emendate/examples/example_set.rb', line 42 def failures grouped_by_test_status[:failure] end |
#get_example_data(data_method:, examples_method: :examples) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/emendate/examples/example_set.rb', line 50 def get_example_data(data_method:, examples_method: :examples) exobjs = send(examples_method) return [] if exobjs.empty? exobjs.map(&data_method).uniq.sort end |
#not_run ⇒ Object
57 58 59 |
# File 'lib/emendate/examples/example_set.rb', line 57 def not_run grouped_by_test_status[:no_tests_run] end |
#report_failures ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/emendate/examples/example_set.rb', line 61 def report_failures return unless failures return if failures.empty? puts "\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" puts "FAILURES" puts "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" failures.each { |failure| failure.report_failure } "" end |
#report_fingerprint(type) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/emendate/examples/example_set.rb', line 73 def report_fingerprint(type) array = send(type) return if array.blank? puts "\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" puts type.to_s.upcase puts "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" puts get_example_data(examples_method: type, data_method: :fingerprint) "" end |
#report_type_patterns(date_only: false, stage: :tokens) ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/emendate/examples/example_set.rb', line 84 def report_type_patterns(date_only: false, stage: :tokens) by_type_pattern(date_only: date_only, stage: stage).each do |pattern, exset| puts pattern.inspect exset.each { |ex| puts " #{ex.fingerprint}" } end puts "\n#{failures.length} examples could not be parsed" if failures end |
#run_tests(tests: nil, fail_fast: false, mode: :normal) ⇒ Object
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/emendate/examples/example_set.rb', line 107 def run_tests(tests: nil, fail_fast: false, mode: :normal) to_run = tests ? tests.intersection(runnable_tests) : runnable_tests examples.each do |example| example.run_tests(tests: to_run, fail_fast: fail_fast, mode: mode) end report_fingerprint(:successes) report_fingerprint(:not_run) report_failures puts summary end |
#runnable_tests ⇒ Object
118 119 120 |
# File 'lib/emendate/examples/example_set.rb', line 118 def runnable_tests @runnable_tests ||= determine_runnable_tests end |
#successes ⇒ Object
122 123 124 |
# File 'lib/emendate/examples/example_set.rb', line 122 def successes grouped_by_test_status[:success] end |
#summary ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/emendate/examples/example_set.rb', line 94 def summary puts "\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" puts "SUMMARY" puts "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" str = %i[successes failures not_run].map { |meth| [meth, send(meth)] } .to_h .compact .map { |meth, vals| "#{vals.length} #{meth}" } .join(" -- ") puts str end |
#tags(type) ⇒ Object
127 128 129 |
# File 'lib/emendate/examples/example_set.rb', line 127 def (type) examples.map { |example| example.(type) }.flatten.uniq.sort end |
#to_s ⇒ Object Also known as: inspect
138 139 140 141 142 |
# File 'lib/emendate/examples/example_set.rb', line 138 def to_s # rubocop:todo Layout/LineLength "#{self.class.name}: #{examples.length} examples from #{rows.length} rows #{}" # rubocop:enable Layout/LineLength end |
#type_patterns(date_only: false, stage: :tokens) ⇒ Object
131 132 133 134 135 136 |
# File 'lib/emendate/examples/example_set.rb', line 131 def type_patterns(date_only: false, stage: :tokens) by_type_pattern(date_only: date_only, stage: stage).keys.each do |key| puts key.inspect end "" end |