"""Commands are consumed once, outside the UI callback which caused the reconnect crash.""" from pathlib import Path import tempfile,subprocess,unittest ROOT=Path(__file__).resolve().parents[2] class CommandFileTest(unittest.TestCase): def test_consumption_and_failure(self): code=r''' #include "python_command_file.h" #include int main(){ std::string err;int calls=0; auto run=[&](const std::string& c){++calls;assert(c=="test()");return true;}; assert(mt_host::consume_python_command_file("",run,err) && calls==0); assert(mt_host::consume_python_command_file("command.py",run,err) && calls==0); {std::ofstream f("command.py");f<<"test()";} assert(mt_host::consume_python_command_file("command.py",run,err) && calls==1); assert(mt_host::consume_python_command_file("command.py",run,err) && calls==1); {std::ofstream f("command.py");f<<"fail()";} assert(!mt_host::consume_python_command_file("command.py",[&](const std::string&){++calls;return false;},err)); assert(!std::filesystem::exists("command.py") && calls==2); {std::ofstream f("command.py");f<