Class: OpenC3::SuiteResults

Inherits:
Object show all
Defined in:
lib/openc3/script/suite_results.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSuiteResults

Returns a new instance of SuiteResults.



22
23
24
25
26
27
28
29
30
# File 'lib/openc3/script/suite_results.rb', line 22

def initialize
  @report = nil
  @context = nil
  @start_time = nil
  @stop_time = nil
  @results = nil
  @settings = nil
  @metadata = nil
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



20
21
22
# File 'lib/openc3/script/suite_results.rb', line 20

def context
  @context
end

#metadataObject

Returns the value of attribute metadata.



20
21
22
# File 'lib/openc3/script/suite_results.rb', line 20

def 
  @metadata
end

Instance Method Details

#completeObject



96
97
98
99
# File 'lib/openc3/script/suite_results.rb', line 96

def complete
  @stop_time = Time.now.sys
  footer()
end


131
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
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/openc3/script/suite_results.rb', line 131

def footer
  self.puts "Completed #{@context}"

  @report << ''
  @report << "--- Test Summary ---"
  @report << ''

  pass_count = 0
  skip_count = 0
  fail_count = 0
  stopped    = false
  @results.each do |result|
    if result.result == :PASS
      pass_count += 1
    elsif result.result == :SKIP
      skip_count += 1
    elsif result.result == :FAIL
      fail_count += 1
    end

    if result.stopped
      stopped = true
    end
  end
  run_time = Time.format_seconds(@stop_time - @start_time)
  run_time << " (#{@stop_time - @start_time} seconds)" if @stop_time - @start_time > 60
  @report << "Run Time: #{run_time}"
  @report << "Total Tests: #{@results.length}"
  @report << "Pass: #{pass_count}"
  @report << "Skip: #{skip_count}"
  @report << "Fail: #{fail_count}"
  @report << ''
  if stopped
    @report << '*** Test was stopped prematurely ***'
    @report << ''
  end
end

#headerObject



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/openc3/script/suite_results.rb', line 105

def header
  @report << "--- Script Report ---"
  # @report << ''
  # if @metadata
  #   begin
  #     items = get_tlm_packet('SYSTEM', 'META')
  #     @report << ''
  #     @report << "Metadata:"
  #     items.each do |item_name, item_value, _|
  #       next if SetTlmDialog::IGNORED_ITEMS.include?(item_name)
  #       @report << "#{item_name} = #{item_value}"
  #     end
  #   rescue DRb::DRbConnError
  #     # Oh well
  #   end
  # end
  if @settings
    @report << ''
    @report << "Settings:"
    @settings.each { |setting_name, setting_value| @report << "#{setting_name} = #{setting_value}" }
  end
  @report << ''
  @report << "Results:"
  self.puts "Executing #{@context}"
end

#process_result(results) ⇒ Object

process_result can handle an array of OpenC3TestResult objects or a single OpenC3TestResult object



54
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
87
88
89
90
91
92
93
94
# File 'lib/openc3/script/suite_results.rb', line 54

def process_result(results)
  openc3_lib = Regexp.new(File.join(OpenC3::PATH, 'lib'))
  # If we were passed an array we concat it to the results global
  if results.is_a? Array
    @results.concat(results)
  # A single result is appended and then turned into an array
  else
    @results << results
    results = [results]
  end
  # Process all the results (may be just one)
  results.each do |result|
    self.puts("#{result.group}:#{result.script}:#{result.result}")
    if result.message
      result.message.each_line do |line|
        if /[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F-\xFF]/.match?(line)
          line.chomp!
          line = line.inspect.remove_quotes
        end
        @report << ('  ' + line.strip)
      end
    end
    if result.exceptions
      @report << "  Exceptions:"
      result.exceptions.each_with_index do |error, index|
        error.formatted().each_line do |line|
          next if /in run_text/.match?(line)
          next if /running_script.rb/.match?(line)
          next if line&.match?(openc3_lib)

          if /[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F-\xFF]/.match?(line)
            line.chomp!
            line = line.inspect.remove_quotes
          end
          @report << ('    ' + line.strip)
        end
        @report << '' if index != (result.exceptions.length - 1)
      end
    end
  end
end

#puts(string) ⇒ Object



173
174
175
# File 'lib/openc3/script/suite_results.rb', line 173

def puts(string)
  @report << (Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%6NZ") + ': ' + string)
end

#reportObject



101
102
103
# File 'lib/openc3/script/suite_results.rb', line 101

def report
  @report.join("\n")
end

#start(test_type, test_suite_class, test_class = nil, test_case = nil, settings = nil) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/openc3/script/suite_results.rb', line 32

def start(test_type, test_suite_class, test_class = nil, test_case = nil, settings = nil)
  @results = []
  @start_time = Time.now.sys
  @settings = settings
  @report = []

  if test_case
    # Executing a script
    @context = "#{test_suite_class.name}:#{test_class.name}:#{test_case} #{test_type}"
  elsif test_class
    # Executing a group
    @context = "#{test_suite_class.name}:#{test_class.name} #{test_type}"
  else
    # Executing a suite
    @context = "#{test_suite_class.name} #{test_type}"
  end

  header()
end

#write(string) ⇒ Object



169
170
171
# File 'lib/openc3/script/suite_results.rb', line 169

def write(string)
  @report << (Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%6NZ") + ': ' + string)
end