Class: Debci::Status
- Inherits:
-
Object
- Object
- Debci::Status
- Includes:
- Test::Duration, Test::Expired, Test::Paths, Test::Prefix
- Defined in:
- lib/debci/status.rb
Overview
This class represents one test execution.
Instance Attribute Summary collapse
-
#architecture ⇒ Object
(also: #arch)
Returns the value of attribute architecture.
-
#date ⇒ Object
Returns the value of attribute date.
-
#duration_seconds ⇒ Object
Returns the value of attribute duration_seconds.
-
#last_pass_date ⇒ Object
Returns the value of attribute last_pass_date.
-
#last_pass_version ⇒ Object
Returns the value of attribute last_pass_version.
-
#message ⇒ Object
Returns the value of attribute message.
-
#package ⇒ Object
Returns the value of attribute package.
-
#previous_status ⇒ Object
Returns the value of attribute previous_status.
-
#requestor ⇒ Object
Returns the value of attribute requestor.
-
#run_id ⇒ Object
Returns the value of attribute run_id.
-
#status ⇒ Object
Returns the value of attribute status.
-
#suite ⇒ Object
Returns the value of attribute suite.
-
#trigger ⇒ Object
Returns the value of attribute trigger.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
-
.from_data(data, suite, architecture) ⇒ Object
Populates an object by reading from a data hash.
-
.from_file(file, suite, architecture) ⇒ Object
Constructs a new object by reading the JSON status
file
.
Instance Method Summary collapse
- #always_failing? ⇒ Boolean
- #blacklisted? ⇒ Boolean
-
#description ⇒ Object
A longer version of the headline for a new failure, include whether this version previously passed.
-
#extended_status ⇒ Object
a larger set of possible test result states, to show “at a glance” the package's test history potentially other attributes could be included here * partial or total failure if there are multiple tests * dependency failure vs test failure * guessed nondeterminism but probably too many combinations will make this unhelpful.
- #failmsg ⇒ Object
- #had_success? ⇒ Boolean
-
#headline ⇒ Object
Returns a headline for this status object, to be used as a short description of the event it represents.
- #inspect ⇒ Object
- #newer?(days) ⇒ Boolean
-
#newsworthy? ⇒ Boolean
Returns
true
if this status object represents an important event, such as a package that used to pass started failing, of vice versa. -
#time ⇒ Object
Returns the amount of time since the date for this status object.
- #title ⇒ Object
- #visible? ⇒ Boolean
Methods included from Test::Prefix
Methods included from Test::Paths
#autopkgtest_dir, #cleanup, #debci_log, #result_json, #root
Methods included from Test::Expired
Methods included from Test::Duration
Instance Attribute Details
#architecture ⇒ Object Also known as: arch
Returns the value of attribute architecture.
21 22 23 |
# File 'lib/debci/status.rb', line 21 def architecture @architecture end |
#date ⇒ Object
Returns the value of attribute date.
21 22 23 |
# File 'lib/debci/status.rb', line 21 def date @date end |
#duration_seconds ⇒ Object
Returns the value of attribute duration_seconds.
21 22 23 |
# File 'lib/debci/status.rb', line 21 def duration_seconds @duration_seconds end |
#last_pass_date ⇒ Object
Returns the value of attribute last_pass_date.
21 22 23 |
# File 'lib/debci/status.rb', line 21 def last_pass_date @last_pass_date end |
#last_pass_version ⇒ Object
Returns the value of attribute last_pass_version.
21 22 23 |
# File 'lib/debci/status.rb', line 21 def last_pass_version @last_pass_version end |
#message ⇒ Object
Returns the value of attribute message.
21 22 23 |
# File 'lib/debci/status.rb', line 21 def @message end |
#package ⇒ Object
Returns the value of attribute package.
21 22 23 |
# File 'lib/debci/status.rb', line 21 def package @package end |
#previous_status ⇒ Object
Returns the value of attribute previous_status.
21 22 23 |
# File 'lib/debci/status.rb', line 21 def previous_status @previous_status end |
#requestor ⇒ Object
Returns the value of attribute requestor.
21 22 23 |
# File 'lib/debci/status.rb', line 21 def requestor @requestor end |
#run_id ⇒ Object
Returns the value of attribute run_id.
21 22 23 |
# File 'lib/debci/status.rb', line 21 def run_id @run_id end |
#status ⇒ Object
Returns the value of attribute status.
21 22 23 |
# File 'lib/debci/status.rb', line 21 def status @status end |
#suite ⇒ Object
Returns the value of attribute suite.
21 22 23 |
# File 'lib/debci/status.rb', line 21 def suite @suite end |
#trigger ⇒ Object
Returns the value of attribute trigger.
21 22 23 |
# File 'lib/debci/status.rb', line 21 def trigger @trigger end |
#version ⇒ Object
Returns the value of attribute version.
21 22 23 |
# File 'lib/debci/status.rb', line 21 def version @version end |
Class Method Details
.from_data(data, suite, architecture) ⇒ Object
Populates an object by reading from a data hash
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/debci/status.rb', line 159 def self.from_data(data, suite, architecture) status = Debci::Status.new status.suite = suite status.architecture = architecture status.run_id = data['run_id'] || data['date'] status.package = data['package'] status.version = data['version'] status.requestor = data['requestor'] status.date = begin d = data['date'] d ||= data['created_at'] d ||= 'unknown' Time.parse(d + ' UTC') rescue ArgumentError nil end status.trigger = data['trigger'] status.status = (data['status'] || :unknown).to_sym status.previous_status = (data['previous_status'] || :unknown).to_sym status.duration_seconds = begin Integer(data['duration_seconds'] || 0) rescue ArgumentError nil end status. = data['message'] status.last_pass_version = data.fetch('last_pass_version', 'unknown') status.last_pass_date = begin Time.parse((data['last_pass_date'] || 'unknown') + ' UTC') rescue ArgumentError nil end status end |
.from_file(file, suite, architecture) ⇒ Object
Constructs a new object by reading the JSON status file
.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/debci/status.rb', line 132 def self.from_file(file, suite, architecture) status = new status.suite = suite status.architecture = architecture unless File.exists?(file) status.package = File.basename(File.dirname(file)) status.status = :no_test_data return status end data = nil begin File.open(file, 'r') do |f| data = JSON.parse(f.read) end rescue JSON::ParserError true # nothing really end return status unless data from_data(data, suite, architecture) end |
Instance Method Details
#always_failing? ⇒ Boolean
222 223 224 |
# File 'lib/debci/status.rb', line 222 def always_failing? !had_success end |
#blacklisted? ⇒ Boolean
211 212 213 214 215 |
# File 'lib/debci/status.rb', line 211 def blacklisted? Debci.blacklist.include?( package, suite: suite, arch: architecture, version: version ) end |
#description ⇒ Object
A longer version of the headline for a new failure, include whether this version previously passed
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/debci/status.rb', line 108 def description msg = "The tests for #{package} (version #{version}) resulted in #{status.upcase} on #{suite}/#{architecture}. Previously it was #{previous_status.upcase}" msg += case extended_status when :fail_passed_current " for the current version." when :fail_passed_old " for version #{last_pass_version}." else "." end end |
#extended_status ⇒ Object
a larger set of possible test result states, to show “at a glance” the package's test history potentially other attributes could be included here * partial or total failure if there are multiple tests * dependency failure vs test failure * guessed nondeterminism but probably too many combinations will make this unhelpful
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/debci/status.rb', line 55 def extended_status case status when :pass :pass # distinguish between always failing, and whether the test has # previously passed for this or older versions when :fail case last_pass_version when "never" :fail_passed_never when version :fail_passed_current when "unknown" :fail else :fail_passed_old end # tmpfail is usually not interesting to the observer, so provide # a hint if it is masking a previous pass or fail when :tmpfail case previous_status when :pass :tmpfail_pass when :fail :tmpfail_fail else :tmpfail end else status end end |
#failmsg ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/debci/status.rb', line 88 def failmsg { :fail_passed_never => "never passed", :fail_passed_current => "previously passed", :fail_passed_old => "#{last_pass_version} passed" }[extended_status] end |
#had_success? ⇒ Boolean
217 218 219 220 |
# File 'lib/debci/status.rb', line 217 def had_success? return true if status == :pass || status == :neutral ['unknown', 'never', ''].include?(last_pass_version) end |
#headline ⇒ Object
Returns a headline for this status object, to be used as a short description of the event it represents
98 99 100 101 102 103 104 |
# File 'lib/debci/status.rb', line 98 def headline msg = "#{package} #{version} #{status.upcase} on #{suite}/#{architecture}" if status == :fail && failmsg msg += " (#{failmsg})" end msg end |
#inspect ⇒ Object
207 208 209 |
# File 'lib/debci/status.rb', line 207 def inspect "<#{suite}/#{architecture} #{status}>" end |
#newer?(days) ⇒ Boolean
202 203 204 205 |
# File 'lib/debci/status.rb', line 202 def newer?(days) return true if days <= 0 (Time.now - date) < days * (24 * 60 * 60) end |
#newsworthy? ⇒ Boolean
Returns true
if this status object represents an important event, such as a package that used to pass started failing, of vice versa.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/debci/status.rb', line 27 def newsworthy? [ [:fail, :pass], [:pass, :fail], [:fail, :neutral], [:pass, :neutral], [:neutral, :pass], [:neutral, :fail], ].include?([status, previous_status]) end |
#time ⇒ Object
Returns the amount of time since the date for this status object
121 122 123 124 125 126 127 128 129 |
# File 'lib/debci/status.rb', line 121 def time days = (Time.now - date)/86400 if days >= 1 || days <= -1 "#{days.floor} day(s) ago" else "#{Time.at(Time.now - date).gmtime.strftime('%H')} hour(s) ago" end end |
#title ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/debci/status.rb', line 38 def title { :pass => "Pass", :fail => "Fail", :neutral => "No tests or all skipped", :tmpfail => "Temporary failure", :no_test_data => "No test data", }.fetch(status, "Unknown") end |