Skip to content

Commit

Permalink
Add test for NREL/OpenStudio#864
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarrec committed Nov 21, 2019
1 parent a37cedd commit 0619aea
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions spec/openstudio/workflow/workflow_analysis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,59 @@
# even if it fails, make sure that we save off the datapoint.zip
zip_path = osw_path.gsub(File.basename(osw_path), 'data_point.zip')
expect(File.exist?(zip_path)).to eq false
it 'should error out while copying html reports' do
osw_path = File.expand_path('./../../../files/reporting_measure_raise/reporting_measure_raise.osw', __FILE__)
osw_out_path = osw_path.gsub(File.basename(osw_path), 'out.osw')

FileUtils.rm_rf(osw_out_path) if File.exist?(osw_out_path)
expect(File.exist?(osw_out_path)).to eq false

run_options = {
debug: true
}
k = OpenStudio::Workflow::Run.new osw_path, run_options
expect(k).to be_instance_of OpenStudio::Workflow::Run
expect(k.run).to eq :errored

expect(File.exist?(osw_out_path)).to eq true

osw_out = nil
File.open(osw_out_path, 'r') do |file|
osw_out = JSON.parse(file.read, symbolize_names: true)
end

expect(osw_out).to be_instance_of Hash
expect(osw_out[:completed_status]).to eq 'Fail'
expect(osw_out[:steps]).to be_instance_of Array
expect(osw_out[:steps].size).to be > 0
osw_out[:steps].each do |step|
expect(step[:result]).to_not be_nil
# Only the broken reporting measure step is supposed to have failed
if (step[:measure_dir_name] == "purposefully_broken_reporting_measure")
expect(step[:result][:step_result]).to eq 'Fail'
else
expect(step[:result][:step_result]).to eq 'Success'
end
end

expected_r = /I'm purposefully breaking the reporting! Before the report was already created!/
expect(osw_out[:steps].last[:result][:step_errors].last).to match expected_r

idf_out_path = File.join(File.dirname(osw_path), 'run', 'in.idf')
expect(File.exist?(idf_out_path)).to eq true

zip_path = File.join(File.dirname(osw_path), 'run', 'data_point.zip')
expect(File.exist?(zip_path)).to eq true

# Tests that we find the two reports that actually worked fine:
# eplus + openstudio_results.
# The broken one shouldn't be there since I raise before it
reports_dir_path = File.join(File.dirname(osw_path), 'reports')
html_reports = Dir.glob(File.join(reports_dir_path, "*.html"))
html_reports_names = html_reports.map{|f| File.basename(f)}
expect(html_reports_names.size).to eq 2
expect(html_reports_names.include?('eplustbl.html')).to eq true
expect(html_reports_names.include?('openstudio_results_report.html')).to eq true
end

it 'should associate results with the correct step' do
Expand Down

0 comments on commit 0619aea

Please sign in to comment.