Skip to content

Commit

Permalink
Add test for #5062
Browse files Browse the repository at this point in the history
```
	3730 - OpenStudioCLI.execute_ruby_script.forward_flags.forward_help (Failed)
	3731 - OpenStudioCLI.execute_python_script.forward_flags.forward_help (Failed)
```
  • Loading branch information
jmarrec committed Dec 20, 2023
1 parent 05c6076 commit 19cb730
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,17 @@ if(BUILD_TESTING)

# Test via optparse and check file exists
# Historical CLI versions
add_test(NAME OpenStudioCLI.Classic.execute_ruby_script.forward_flags.optparse.path_forwardslash
add_test(NAME OpenStudioCLI.Classic.execute_ruby_script.forward_flags.optparse.path_forwardslash
COMMAND $<TARGET_FILE:openstudio> classic execute_ruby_script execute_ruby_script_optparse_path.rb -x "./test_folder/hello.xml"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/test/"
)
add_test(NAME OpenStudioCLI.Classic.execute_ruby_script.forward_flags.forward_help
COMMAND $<TARGET_FILE:openstudio> classic execute_ruby_script ${CMAKE_CURRENT_SOURCE_DIR}/test/execute_ruby_script_optparse_path.rb --help
)
set_tests_properties(OpenStudioCLI.Classic.execute_ruby_script.forward_flags.forward_help PROPERTIES
PASS_REGULAR_EXPRESSION "The Ruby help description."
)

if (WIN32)
# Posix paths don't understand a backward slash anyways
add_test(NAME OpenStudioCLI.Classic.execute_ruby_script.forward_flags.optparse.path_backwardslash
Expand All @@ -313,6 +320,21 @@ if(BUILD_TESTING)
COMMAND $<TARGET_FILE:openstudio> execute_ruby_script execute_ruby_script_optparse_path.rb -x "./test_folder/hello.xml"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/test/"
)

add_test(NAME OpenStudioCLI.execute_ruby_script.forward_flags.forward_help
COMMAND $<TARGET_FILE:openstudio> execute_ruby_script ${CMAKE_CURRENT_SOURCE_DIR}/test/execute_ruby_script_optparse_path.rb --help
)
set_tests_properties(OpenStudioCLI.execute_ruby_script.forward_flags.forward_help PROPERTIES
PASS_REGULAR_EXPRESSION "The Ruby help description."
)

add_test(NAME OpenStudioCLI.execute_python_script.forward_flags.forward_help
COMMAND $<TARGET_FILE:openstudio> execute_python_script ${CMAKE_CURRENT_SOURCE_DIR}/test/execute_python_script_argparse_path.py --help
)
set_tests_properties(OpenStudioCLI.execute_python_script.forward_flags.forward_help PROPERTIES
PASS_REGULAR_EXPRESSION "The Python help description."
)

if (WIN32)
add_test(NAME OpenStudioCLI.execute_ruby_script.forward_flags.optparse.path_backwardslash
COMMAND $<TARGET_FILE:openstudio> execute_ruby_script execute_ruby_script_optparse_path.rb -x ".\\test_folder\\hello.xml"
Expand Down
21 changes: 21 additions & 0 deletions src/cli/test/execute_python_script_argparse_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import argparse
from pathlib import Path


def validate_file(arg):
if (filepath := Path(arg)).is_file():
return filepath
else:
raise FileNotFoundError(arg)

def validate_xml_file(arg):
filepath = validate_file(arg)
if (filepath.suffix != '.xml'):
raise FileNotFoundError(f"{arg} is not a .xml file")
return filepath

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="The Python help description.")
parser.add_argument("-x,--xml", metavar='FILE', required=True, type=validate_xml_file, help="HPXML file")
args = parser.parse_args()
print(args)
1 change: 1 addition & 0 deletions src/cli/test/execute_ruby_script_optparse_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: #{File.basename(__FILE__)} -x building.xml"
opts.banner += "\n\nThe Ruby help description.\n\n"

opts.on('-x', '--xml <FILE>', 'HPXML file') do |t|
options[:hpxml] = t
Expand Down

0 comments on commit 19cb730

Please sign in to comment.