Class: OpenStudioMeasureTester::MinitestResult

Inherits:
Object
  • Object
show all
Defined in:
lib/openstudio_measure_tester/minitest_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path_to_results) ⇒ MinitestResult

Returns a new instance of MinitestResult.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/openstudio_measure_tester/minitest_result.rb', line 12

def initialize(path_to_results)
  @path_to_results = path_to_results
  @error_status = false
  @total_tests = 0
  @total_assertions = 0
  @total_errors = 0
  @total_failures = 0
  @total_skipped = 0
  @total_compatibility_errors = 0
  @total_loaded = true
  @total_load_errors = []

  @measure_results = {}
  @summary = {}

  parse_results
  to_file
end

Instance Attribute Details

#error_statusObject (readonly)

Returns the value of attribute error_status.



10
11
12
# File 'lib/openstudio_measure_tester/minitest_result.rb', line 10

def error_status
  @error_status
end

#measure_resultsObject (readonly)

Returns the value of attribute measure_results.



10
11
12
# File 'lib/openstudio_measure_tester/minitest_result.rb', line 10

def measure_results
  @measure_results
end

#summaryObject (readonly)

Returns the value of attribute summary.



10
11
12
# File 'lib/openstudio_measure_tester/minitest_result.rb', line 10

def summary
  @summary
end

#total_assertionsObject (readonly)

Returns the value of attribute total_assertions.



10
11
12
# File 'lib/openstudio_measure_tester/minitest_result.rb', line 10

def total_assertions
  @total_assertions
end

#total_compatibility_errorsObject (readonly)

Returns the value of attribute total_compatibility_errors.



10
11
12
# File 'lib/openstudio_measure_tester/minitest_result.rb', line 10

def total_compatibility_errors
  @total_compatibility_errors
end

#total_errorsObject (readonly)

Returns the value of attribute total_errors.



10
11
12
# File 'lib/openstudio_measure_tester/minitest_result.rb', line 10

def total_errors
  @total_errors
end

#total_failuresObject (readonly)

Returns the value of attribute total_failures.



10
11
12
# File 'lib/openstudio_measure_tester/minitest_result.rb', line 10

def total_failures
  @total_failures
end

#total_skippedObject (readonly)

Returns the value of attribute total_skipped.



10
11
12
# File 'lib/openstudio_measure_tester/minitest_result.rb', line 10

def total_skipped
  @total_skipped
end

#total_testsObject (readonly)

Returns the value of attribute total_tests.



10
11
12
# File 'lib/openstudio_measure_tester/minitest_result.rb', line 10

def total_tests
  @total_tests
end

Instance Method Details

#parse_resultsObject



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
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
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/openstudio_measure_tester/minitest_result.rb', line 31

def parse_results
  # use the compatibility file to find the measure name and other files
  Dir["#{@path_to_results}/compatibility/*.json"].each do |file|
    puts "Parsing compatibility report #{file}"
    json_data = JSON.parse(File.read(file), symbolize_names: true)

    # Test if the measure has already been parse, if so, then continue
    next if @measure_results.key?(json_data[:measure_name])

    mhash = {}
    mhash[:tested_class] = json_data[:measure_name]
    mhash[:openstudio_version] = json_data[:openstudio_version]
    mhash[:measure_min_version] = json_data[:measure_min_version]
    mhash[:measure_max_version] = json_data[:measure_max_version]
    mhash[:loaded] = json_data[:loaded]
    if json_data[:load_errors].nil?
      mhash[:load_errors] = []
    else
      mhash[:load_errors] = json_data[:load_errors]
    end

    # initialize a bunch of data
    mhash[:measure_compatibility_errors] = json_data[:compatible] ? 0 : 1
    mhash[:measure_tests] = 0
    mhash[:measure_assertions] = 0
    mhash[:measure_errors] = 0
    mhash[:measure_failures] = 0
    mhash[:measure_skipped] = 0
    mhash[:issues] = {
      errors: [],
      failures: [],
      skipped: [],
      compatibility_error: json_data[:compatible] ? 0 : 1
    }

    # find the report XML - if it exists
    report_xmls = Dir["#{@path_to_results}/reports/TEST-#{json_data[:measure_name]}*.xml"]
    if report_xmls.count == 1
      puts "Parsing minitest report #{report_xmls[0]}"
      doc = REXML::Document.new(File.open(report_xmls[0])).root

      if doc
        # NOTE: only 1 failure and 1 error possible per test
        testsuite_element = doc.elements['testsuite']
        errors, failures, skipped = parse_measure(testsuite_element)

        mhash[:measure_tests] = testsuite_element.attributes['tests'].to_i
        mhash[:measure_assertions] = testsuite_element.attributes['assertions'].to_i
        mhash[:measure_errors] = testsuite_element.attributes['errors'].to_i
        mhash[:measure_failures] = testsuite_element.attributes['failures'].to_i
        mhash[:measure_skipped] = testsuite_element.attributes['skipped'].to_i

        mhash[:issues][:errors] = errors
        mhash[:issues][:failures] = failures
        mhash[:issues][:skipped] = skipped
      end
    else
      # There are more than one XMLs or there are no XML
      # No XMLs is typically because the measure was not applicable to then version of OpenStudio
    end

    @measure_results[mhash[:tested_class]] = mhash

    @total_tests += mhash[:measure_tests]
    @total_assertions += mhash[:measure_assertions]
    @total_errors += mhash[:measure_errors]
    @total_failures += mhash[:measure_failures]
    @total_skipped += mhash[:measure_skipped]
    @total_compatibility_errors += mhash[:measure_compatibility_errors]
    @total_loaded &&= mhash[:loaded]
    @total_load_errors.concat(mhash[:load_errors])
  end

  @error_status = true if @total_errors > 0
end

#to_fileObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/openstudio_measure_tester/minitest_result.rb', line 107

def to_file
  # save as a json and have something else parse it/plot it.

  @summary[:test_directory] = @path_to_results
  @summary[:total_tests] = @total_tests
  @summary[:total_assertions] = @total_assertions
  @summary[:total_errors] = @total_errors
  @summary[:total_failures] = @total_failures
  @summary[:total_skipped] = @total_skipped
  @summary[:total_compatibility_errors] = @total_compatibility_errors
  @summary[:total_loaded] = @total_loaded
  @summary[:total_load_errors] = @total_load_errors
  @summary[:by_measure] = @measure_results

  FileUtils.mkdir "#{@path_to_results}/" unless Dir.exist? "#{@path_to_results}/"
  File.open("#{@path_to_results}/minitest.json", 'w') do |file|
    file << JSON.pretty_generate(summary)
  end
end