Skip to content

Commit

Permalink
Fix #5147 - Adjust templates
Browse files Browse the repository at this point in the history
* make it clear that if you use runner.lastEnergyPlusSQLFile you need to reopen it potentially
* Use a chdir context
  • Loading branch information
jmarrec committed Apr 16, 2024
1 parent c6dd282 commit 2fa6841
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
require 'openstudio'
require 'openstudio/measure/ShowRunnerOutput'
require 'minitest/autorun'
require_relative '../measure.rb'
require 'fileutils'

require_relative '../measure'

class EnergyPlusMeasureNameTest < Minitest::Test
# def setup
# end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
require 'openstudio'
require 'openstudio/measure/ShowRunnerOutput'
require 'minitest/autorun'
require_relative '../measure.rb'
require 'fileutils'

require_relative '../measure'

class ModelMeasureNameTest < Minitest::Test
# def setup
# end
Expand Down Expand Up @@ -118,7 +119,7 @@ def test_good_argument_values
assert_equal(1, model.getSpaces.size - num_spaces_seed)

# save the model to test output directory
output_file_path = "#{File.dirname(__FILE__)}//output/test_output.osm"
output_file_path = "#{File.dirname(__FILE__)}/output/test_output.osm"
model.save(output_file_path, true)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
require 'openstudio'
require 'openstudio/measure/ShowRunnerOutput'
require 'minitest/autorun'
require_relative '../measure.rb'
require 'fileutils'

require_relative '../measure'

class ReportingMeasureNameTest < Minitest::Test
def model_in_path_default
return "#{File.dirname(__FILE__)}/example_model.osm"
Expand Down Expand Up @@ -142,20 +143,23 @@ def test_with_drybulb_temp
assert(!File.exist?(report_path(test_name)))

# temporarily change directory to the run directory and run the measure
start_dir = Dir.pwd
begin
Dir.chdir(run_dir(test_name))

# run the measure
Dir.chdir(run_dir(test_name)) do
measure.run(runner, argument_map)
result = runner.result
show_output(result)
assert_equal('Success', result.value.valueName)
assert(result.warnings.empty?)
ensure
Dir.chdir(start_dir)
end

result = runner.result
show_output(result)
assert_equal('Success', result.value.valueName)
assert(result.warnings.empty?)

sqlFile = runner.lastEnergyPlusSqlFile.get
if !sqlFile.connectionOpen
sqlFile.reopen
end
hours = sqlFile.hoursSimulated
refute_empty(hours)
assert_equal(8760.0, hours.get)

# make sure the report file exists
assert(File.exist?(report_path(test_name)))
end
Expand Down Expand Up @@ -189,7 +193,8 @@ def test_without_drybulb_temp
idf_output_requests = measure.energyPlusOutputRequests(runner, argument_map)
assert_equal(0, idf_output_requests.size)

# mimic the process of running this measure in OS App or PAT. Optionally set custom model_in_path and custom epw_path.
# mimic the process of running this measure in OS App or PAT.
# Optionally set custom model_in_path and custom epw_path.
epw_path = epw_path_default
setup_test(test_name, idf_output_requests)

Expand All @@ -209,20 +214,24 @@ def test_without_drybulb_temp
assert(!File.exist?(report_path(test_name)))

# temporarily change directory to the run directory and run the measure
start_dir = Dir.pwd
begin
Dir.chdir(run_dir(test_name))

# run the measure
Dir.chdir(run_dir(test_name)) do
measure.run(runner, argument_map)
result = runner.result
show_output(result)
assert_equal('Success', result.value.valueName)
assert(result.warnings.empty?)
ensure
Dir.chdir(start_dir)
end

result = runner.result
show_output(result)
assert_equal('Success', result.value.valueName)
assert(result.warnings.empty?)

# sqlFile = OpenStudio::SqlFile.new(OpenStudio::Path.new(sql_path(test_name)))
sqlFile = runner.lastEnergyPlusSqlFile.get
if !sqlFile.connectionOpen
sqlFile.reopen
end
hours = sqlFile.hoursSimulated
refute_empty(hours)
assert_equal(8760.0, hours.get)

# make sure the report file exists
assert(File.exist?(report_path(test_name)))
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import openstudio
import pytest

from measure import ReportingMeasureName

CURRENT_DIR_PATH = Path(__file__).parent.absolute()
Expand Down Expand Up @@ -151,18 +150,24 @@ def test_with_drybulb_temp(self):

# temporarily change directory to the run directory and run the measure
start_dir = Path.cwd()
# try:
os.chdir(TestReportingMeasureName.run_dir(test_name))
try:
# run the measure
measure.run(runner, argument_map)
finally:
os.chdir(start_dir)

# run the measure
measure.run(runner, argument_map)
result = runner.result()
print(result)
assert result.value().valueName() == "Success"
assert len(result.warnings()) == 0
os.chdir(start_dir)
# except:
# os.chdir(start_dir)

sqlFile = runner.lastEnergyPlusSqlFile().get()
if not sqlFile.connectionOpen():
sqlFile.reopen()
hours = sqlFile.hoursSimulated()
assert hours.is_initialized()
assert hours.get() == 8760.0

# make sure the report file exists
assert report_path.exists()
Expand Down Expand Up @@ -220,18 +225,24 @@ def test_without_drybulb_temp(self):

# temporarily change directory to the run directory and run the measure
start_dir = Path.cwd()
# try:
os.chdir(TestReportingMeasureName.run_dir(test_name))
try:
# run the measure
measure.run(runner, argument_map)
finally:
os.chdir(start_dir)

# run the measure
measure.run(runner, argument_map)
result = runner.result()
print(result)
assert result.value().valueName() == "Success"
assert len(result.warnings()) == 0
os.chdir(start_dir)
# except:
# os.chdir(start_dir)

sqlFile = runner.lastEnergyPlusSqlFile().get()
if not sqlFile.connectionOpen():
sqlFile.reopen()
hours = sqlFile.hoursSimulated()
assert hours.is_initialized()
assert hours.get() == 8760.0

# make sure the report file exists
assert report_path.exists()

0 comments on commit 2fa6841

Please sign in to comment.