当 tk_messageBox 出现在 tcl 中时进入
entering when tk_messageBox appear in tcl
所以我想在 tcl gui 中做一些单元测试,在单元测试的某些部分,会弹出一个 tk_messageBox,如果我不按 enter,单元测试不会继续
你们中有人知道如何复制输入按钮(击键)吗?或者更好的是,注入 tk_messageBox 使其消失的命令
已尝试调用命令,但 tk_messageBox 没有任何名称
tk_messageBox -icon error -title TEST -message "this is a test tkbox" -type ok -parent .
这取决于您使用的平台。如果你在 Unix 上,你可以这样做:
# Widget name depends on what is the parent widget and message box type
# This is correct for -parent . -type ok
.__tk__messagebox.ok invoke
这不适用于 Windows 或 OSX,因为这两个平台使用本机系统对话框。如果您在那里,您需要调整代码以不首先显示消息框对话框或让通用自动化工具为您单击按钮。
由于您不需要测试 Tk 的 tk_messageBox,您可以跳过该部分代码。在您的测试单元中设置一个变量:
set ::_testmode true
在您的代码中:
if { ! [info exists ::_testmode] } {
tk_messageBox ...
} else {
# if you are using the return code from tk_messageBox, you
# can set it here.
}
当然,这会使源代码有点混乱,但测试会起作用。我不得不围绕 tk_getSaveFile 和 tk_getOpenFile 做类似的 if-blocks,就像 Donal 为 tk_messageBox 指出的那样,这些不能轻易跳过 Windows 和 Mac OS X.
所以我想在 tcl gui 中做一些单元测试,在单元测试的某些部分,会弹出一个 tk_messageBox,如果我不按 enter,单元测试不会继续
你们中有人知道如何复制输入按钮(击键)吗?或者更好的是,注入 tk_messageBox 使其消失的命令
已尝试调用命令,但 tk_messageBox 没有任何名称
tk_messageBox -icon error -title TEST -message "this is a test tkbox" -type ok -parent .
这取决于您使用的平台。如果你在 Unix 上,你可以这样做:
# Widget name depends on what is the parent widget and message box type
# This is correct for -parent . -type ok
.__tk__messagebox.ok invoke
这不适用于 Windows 或 OSX,因为这两个平台使用本机系统对话框。如果您在那里,您需要调整代码以不首先显示消息框对话框或让通用自动化工具为您单击按钮。
由于您不需要测试 Tk 的 tk_messageBox,您可以跳过该部分代码。在您的测试单元中设置一个变量:
set ::_testmode true
在您的代码中:
if { ! [info exists ::_testmode] } {
tk_messageBox ...
} else {
# if you are using the return code from tk_messageBox, you
# can set it here.
}
当然,这会使源代码有点混乱,但测试会起作用。我不得不围绕 tk_getSaveFile 和 tk_getOpenFile 做类似的 if-blocks,就像 Donal 为 tk_messageBox 指出的那样,这些不能轻易跳过 Windows 和 Mac OS X.