Skip to content

Commit

Permalink
Try open3 instead of backticks.
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-robertson committed Apr 30, 2024
1 parent d8035e4 commit 9a3c363
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

source 'http://rubygems.org'

gem 'oga', '3.2'
gem 'oga'
gem 'rake'
gem 'matrix'
gem 'minitest', '5.15'
gem 'minitest-reporters'
gem 'msgpack', '1.7.2'
gem 'msgpack'
gem 'parallel'
gem 'simplecov'
gem 'simplecov-html'
Expand Down
22 changes: 19 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ GEM
ansi (1.5.0)
ast (2.4.2)
builder (3.2.4)
minitest (5.22.3)
docile (1.4.0)
matrix (0.4.2)
minitest (5.15.0)
minitest-reporters (1.6.1)
ansi
builder
Expand All @@ -14,20 +16,34 @@ GEM
oga (3.4)
ast
ruby-ll (~> 2.1)
parallel (1.24.0)
rake (13.2.1)
ruby-ll (2.1.3)
ansi
ast
ruby-progressbar (1.13.0)
rubyzip (2.3.2)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)

PLATFORMS
x64-mingw32
x64-mingw-ucrt

DEPENDENCIES
matrix
minitest (= 5.15)
minitest-reporters
msgpack
oga
parallel
rake
rubyzip
simplecov
simplecov-html

BUNDLED WITH
2.1.4
2.5.9
4 changes: 3 additions & 1 deletion resources/buildstock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ def get_data_for_sample(buildstock_csv_path, building_id, runner)
end

class RunOSWs
require 'open3'
require 'openstudio'
require 'csv'
require 'json'
Expand All @@ -455,7 +456,8 @@ def self.run(in_osw, parent_dir, run_output, upgrade, measures, reporting_measur
command += ' -m' if measures_only
command += " -w \"#{in_osw}\""

`#{command}` # suppresses "RunEnergyPlus: Completed Successfully with xxx" message
# `#{command}` # suppresses "RunEnergyPlus: Completed Successfully with xxx" message
Open3.capture3(command)
run_log = File.readlines(File.expand_path(File.join(parent_dir, 'run/run.log')))
run_log.each do |line|
next if line.include? 'Cannot find current Workflow Step'
Expand Down
25 changes: 13 additions & 12 deletions test/test_run_analysis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require_relative '../resources/hpxml-measures/HPXMLtoOpenStudio/resources/version'
require_relative '../resources/buildstock'
require_relative '../test/analysis'
require 'open3'
require 'openstudio'

class TestRunAnalysis < Minitest::Test
Expand Down Expand Up @@ -140,7 +141,7 @@ def _expected_warning_message(message, txt)
def test_version
@command += ' -v'

cli_output = `#{@command}`
cli_output, stderr_str, status = Open3.capture3(@command)

assert_includes(cli_output, "ResStock v#{Version::ResStock_Version}")
assert_includes(cli_output, "OpenStudio-HPXML v#{Version::OS_HPXML_Version}")
Expand All @@ -153,13 +154,13 @@ def test_errors_wrong_path
yml = ' -y test/yml_bad_value/testing_baseline.yml'
@command += yml

cli_output = `#{@command}`
cli_output, stderr_str, status = Open3.capture3(@command)

_assert_and_puts([cli_output], "Error: YML file does not exist at 'test/yml_bad_value/testing_baseline.yml'.")
end

def test_no_yml_argument
cli_output = `#{@command}`
cli_output, stderr_str, status = Open3.capture3(@command)

_assert_and_puts([cli_output], 'Error: YML argument is required. Call run_analysis.rb -h for usage.')
end
Expand All @@ -168,7 +169,7 @@ def test_errors_bad_value
yml = ' -y test/tests_yml_files/yml_bad_value/testing_baseline.yml'
@command += yml

cli_output = `#{@command}`
cli_output, stderr_str, status = Open3.capture3(@command)

_assert_and_puts([cli_output], 'Failures detected for: 1, 2.')

Expand All @@ -181,8 +182,8 @@ def test_errors_already_exists
yml = ' -y test/tests_yml_files/yml_bad_value/testing_baseline.yml'
@command += yml

`#{@command}`
cli_output = `#{@command}`
Open3.capture3(@command)
cli_output, stderr_str, status = Open3.capture3(@command)

_assert_and_puts([cli_output], "Error: Output directory 'testing_baseline' already exists.")
end
Expand All @@ -191,7 +192,7 @@ def test_errors_downselect_resample
yml = ' -y test/tests_yml_files/yml_resample/testing_baseline.yml'
@command += yml

cli_output = `#{@command}`
cli_output, stderr_str, status = Open3.capture3(@command)

_assert_and_puts([cli_output], "Error: Not supporting residential_quota_downselect's 'resample' at this time.")
end
Expand All @@ -202,7 +203,7 @@ def test_errors_weather_files

FileUtils.rm_rf(File.join(File.dirname(__FILE__), '../weather'))
assert(!File.exist?(File.join(File.dirname(__FILE__), '../weather')))
cli_output = `#{@command}`
cli_output, stderr_str, status = Open3.capture3(@command)

_assert_and_puts([cli_output], "Error: Must include 'weather_files_url' or 'weather_files_path' in yml.")
assert(!File.exist?(File.join(File.dirname(__FILE__), '../weather')))
Expand All @@ -212,7 +213,7 @@ def test_errors_downsampler
yml = ' -y test/tests_yml_files/yml_downsampler/testing_baseline.yml'
@command += yml

cli_output = `#{@command}`
cli_output, stderr_str, status = Open3.capture3(@command)

_assert_and_puts([cli_output], "Error: Sampler type 'residential_quota_downsampler' is invalid or not supported.")
end
Expand All @@ -221,7 +222,7 @@ def test_errors_missing_key
yml = ' -y test/tests_yml_files/yml_missing_key/testing_baseline.yml'
@command += yml

cli_output = `#{@command}`
cli_output, stderr_str, status = Open3.capture3(@command)

_assert_and_puts([cli_output], "Error: Both 'build_existing_model' and 'simulation_output_report' must be included in yml.")
end
Expand All @@ -230,7 +231,7 @@ def test_errors_precomputed_outdated_missing_parameter
yml = ' -y test/tests_yml_files/yml_precomputed_outdated/testing_baseline_missing.yml'
@command += yml

`#{@command}`
Open3.capture3(@command)
cli_output = File.readlines(File.join(@testing_baseline, 'cli_output.log'))

_assert_and_puts(cli_output, 'Mismatch between buildstock.csv and options_lookup.tsv. Missing parameters: HVAC Cooling Partial Space Conditioning.')
Expand All @@ -240,7 +241,7 @@ def test_errors_precomputed_outdated_extra_parameter
yml = ' -y test/tests_yml_files/yml_precomputed_outdated/testing_baseline_extra.yml'
@command += yml

`#{@command}`
Open3.capture3(@command)
cli_output = File.readlines(File.join(@testing_baseline, 'cli_output.log'))

_assert_and_puts(cli_output, 'Mismatch between buildstock.csv and options_lookup.tsv. Extra parameters: Extra Parameter.')
Expand Down

0 comments on commit 9a3c363

Please sign in to comment.