我想檢查該值是否"train-again-v1-16k"出現在任何"model_name".
我能夠得到回應,然后我想通過使用來確保串列包含值 Dictionary Should Contain Value。
測驗用例失敗:
AttributeError: 'list' object has no attribute 'values'
請告知檢查串列中值的正確語法是什么。
*** Settings ***
Library Browser
Library String
Library RequestsLibrary
Library Collections
Library RPA.JSON
*** Test Cases ***
001-Models-Deploy
Create Session mysession ${SRS-API-Host}
${response}= GET ${SRS-API-Host}/models_list
${models}= Get values from JSON ${response.json()} $..model_name
Log To Console models is${models}
Dictionary Should Contain Value ${models} 'train-again-v1-16k'
獲取回應:
{
"message": "",
"status": "ok",
"valid_model_list": [
{
"corpus_list": [
"test1"
],
"display_name": "16000samplerate-60train-40test-v1-16k",
"language": "NO INFO",
"lexicon": "001_Lex_one_using_001_wav_stm_only",
"model_name": "16000samplerate-60train-40test-v1-16k",
"status": true,
"train_duration": "1.0 Hrs"
},
{
"corpus_list": [
"Corpus3397"
],
"display_name": "train-again-v1-16k",
"language": "NO INFO",
"lexicon": "NTU",
"model_name": "train-again-v1-16k",
"status": true,
"train_duration": "1.33 Hrs"
}
]
}
uj5u.com熱心網友回復:
Get values from JSON回傳一個包含所有匹配值的串列,同時Dictionary Should Contain Value使用并期望一個字典物件。
只需更改關鍵字以斷言存在與串列一起使用的值 - List Should Contain Value,或者只是Should Contain:
List Should Contain Value ${models} train-again-v1-16k
uj5u.com熱心網友回復:
通過使用Should Contain,從 獲得的串列Get values from JSON,特定值被斷言。
*** Settings ***
Library Browser
Library String
Library RequestsLibrary
Library Collections
Library RPA.JSON
Resource ../Resources/BrowserFunctions.robot
Suite Setup Start New Browser
Suite Teardown Close Browser
*** Test Cases ***
001-Models-Deploy
#Verify model appear at SRS API Model List
Create Session mysession ${SRS-API-Host}
${response}= GET ${SRS-API-Host}/models_list
${models}= Get values from JSON ${response.json()} $..model_name
Log To Console models is${models}
Should Contain ${models} sourcemodel8k8020-v1-8k
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/465329.html
上一篇:從獲取資料中拆分陣列資料
下一篇:Python-合并API分頁資料
