-
Notifications
You must be signed in to change notification settings - Fork 222
Measure manager fixups and improvements #5304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| execute_process(COMMAND ${Python_EXECUTABLE} -c "import requests; print(requests.__version__)" | ||
| RESULT_VARIABLE _PyRequests_STATUS | ||
| OUTPUT_VARIABLE PyRequests_Version | ||
| ERROR_QUIET | ||
| OUTPUT_STRIP_TRAILING_WHITESPACE | ||
| ) | ||
| if(_PyRequests_STATUS AND NOT _PyRequests_STATUS EQUAL 0) | ||
| message(AUTHOR_WARNING "requests isn't installed on your system python, so some tests won't be run. Run `pip install requests`") | ||
| set(PyRequests_AVAILABLE OFF) | ||
| else() | ||
| message("Found Python requests: ${PyRequests_Version}") | ||
| set(PyRequests_AVAILABLE ON) | ||
| endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Detect if requests is installed on the system python
| if (PyRequests_AVAILABLE) | ||
| add_test(NAME OpenStudioCLI.test_measure_manager | ||
| COMMAND ${Python_EXECUTABLE} -m pytest --verbose --os-cli-path $<TARGET_FILE:openstudio> "${CMAKE_CURRENT_SOURCE_DIR}/test/test_measure_manager.py" | ||
| WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/Testing/" | ||
| ) | ||
| add_test(NAME OpenStudioCLI.Classic.test_measure_manager | ||
| COMMAND ${Python_EXECUTABLE} -m pytest --verbose --use-classic --os-cli-path $<TARGET_FILE:openstudio> "${CMAKE_CURRENT_SOURCE_DIR}/test/test_measure_manager.py" | ||
| WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/Testing/" | ||
| ) | ||
| endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Register the Classic (Ruby) and C++ version of the test_measure_manager.py
| def pytest_addoption(parser): | ||
| parser.addoption("--os-cli-path", type=validate_file, help="Path to the OS CLI") # , required=True | ||
|
|
||
| parser.addoption("--use-classic", action="store_true", help="Force use the Classic CLI") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need addopt
|
|
||
| @pytest.fixture(scope="module") | ||
| def use_classic_cli(request): | ||
| use_classic = request.config.getoption("--use-classic") | ||
| return use_classic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set it as a fixture for use
| } | ||
|
|
||
| BASE_INTERNAL_STATE_LABS: Dict[str, Any] = { | ||
| "idfs": [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only key that the C++ CLI added in /internal_state
| } | ||
|
|
||
| auto& measureInfos = result["measure_info"]; | ||
| measureInfos = Json::arrayValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
| return; | ||
| } | ||
|
|
||
| message.reply(web::http::status_codes::BadRequest, toWebJSON(fmt::format("Error, unknown path '{}'", uri))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Get, was returning a 400 instead of a 404 when unknown endpoint
| void MeasureManagerServer::unknown_endpoint(web::http::http_request& message) { | ||
| const std::string uri = toString(web::http::uri::decode(message.relative_uri().path())); | ||
| message.reply(web::http::status_codes::BadRequest, toWebJSON(fmt::format("Error, unknown path '{}'", uri))); | ||
| print_feedback(message, web::http::status_codes::NotFound); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use a function for both GET and POST when 404
| void MeasureManagerServer::print_feedback(const web::http::http_request& message, web::http::status_code status_code) { | ||
| const std::string uri = toString(web::http::uri::decode(message.relative_uri().path())); | ||
| const std::string method = toString(message.method()); | ||
| const std::string http_version = message.http_version().to_utf8string(); | ||
| const std::string timestamp = openstudio::DateTime::now().toXsdDateTime(); | ||
| fmt::print(status_code == web::http::status_codes::OK ? stdout : stderr, "[{}] \"{} {} {}\" {}\n", openstudio::DateTime::now().toXsdDateTime(), | ||
| method, uri, http_version, status_code); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Print log
| result = {} | ||
|
|
||
| data = JSON.parse(request.body, {:symbolize_names=>true}) | ||
| data = JSON.parse(request.body || "{}", {:symbolize_names=>true}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor tweaks in ruby CLI. When body is empty, you don't want to get bad error on JSON.parse with an ugly backtrace and No implicit conversion of nil into String isn't a good error message
c4fb845 to
417a930
Compare
417a930 to
27df95b
Compare
27df95b to
bc47e96
Compare
|
@DavidGoldwasser @kbenne this has been opened since November, can someone take a look please? I just rebased onto develop |
bc47e96 to
cde06b3
Compare
… with classic cli and find differences
…running, kinda like Webbrick was doing success, on stdout: [2024-11-14T10:21:46+01:00] "POST /reset HTTP/1.1" 200 failure, on stderr: [2024-11-14T10:22:09+01:00] "GET /dsd HTTP/1.1" 400
…e on JSON.parse No implicit conversion of nil into String isn't a good error message
cde06b3 to
dfc7305
Compare
|
CI Results for dfc7305:
|
|
@kbenne can you take a quick look here please? I'd like to merge it in. |
Pull request overview
Pull Request Author
src/model/test)src/energyplus/Test)src/osversion/VersionTranslator.cpp)Labels:
IDDChangeAPIChangePull Request - Ready for CIso that CI builds your PRReview Checklist
This will not be exhaustively relevant to every PR.