Skip to content

Commit 671d955

Browse files
authored
Merge pull request #168 from cognitive-catalyst/167_json_dialogtest_support
#167 allow JSON or TSV input files
2 parents 25c07b8 + 88b7899 commit 671d955

File tree

3 files changed

+108
-79
lines changed

3 files changed

+108
-79
lines changed

dialog_test/README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,28 @@ Check the `results` folder for test output. If any MATCH column has a 'FALSE' v
2323
Additionally, each test will print a single PASS or FAIL marker to standard out upon completion.
2424

2525
## Building tests with configuration
26-
Build test files in the tests subfolder. Each test should be a tab separated file.
26+
Build test files in the tests subfolder. Each test should be a tab separated file or a JSON file.
2727

28-
The columns are
28+
For a tab-separated file, the column headers are the following ("Turn number" is NOT specified as a column header)
2929
(Turn number) User Input Match Output Match Intent Match Entity Alternate Intents Intents Object Entities Object Context Variables System Object
3030

31+
For a JSON test file, the file contents are an array of JSON objects. For example:
32+
```
33+
[
34+
{
35+
"Turn": "0",
36+
"Context Variables": {
37+
"user_type": "GOLD"
38+
}
39+
},
40+
{
41+
"Turn": "1",
42+
"User Input": "I need to reset my password",
43+
"Match Output": "I can help you reset your password"
44+
}
45+
]
46+
```
47+
3148
All fields are optional
3249

3350
* Match Output indicates a substring that must be present in the Watson Assistant response. It is not necessary to provide the full output string. Regular Expressions can be enclosed with forward slashes (e.g. `/The reservation is for *. PM/`). `<br>` can be used to join lines when specifyig multiline ouputs (e.g. `The reservation is for 6 guests<br>What day would you like to come in?`).

dialog_test/flowtest.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ def processPath(inputPath:str):
6666
def processFile(flowfile:str, watsonSDKVersion:str):
6767
basefilename = os.path.basename(flowfile).split('.')[0]
6868

69-
flow = pd.read_csv(flowfile, delimiter='\t' )
69+
if flowfile.endswith("json"):
70+
flow = json.load(open(flowfile))
71+
flow = pd.DataFrame(flow)
72+
else:
73+
flow = pd.read_csv(flowfile, delimiter='\t' )
7074

7175
# This bit widens the output on screen.
7276
pd.set_option('display.max_columns', 10000)
@@ -89,7 +93,7 @@ def processFile(flowfile:str, watsonSDKVersion:str):
8993
# print()
9094

9195
print()
92-
print('Running Conversational Flow: {} ({})'.format(flowfile, flow.shape[0]))
96+
print('Running Conversational Flow: {} ({})'.format(flowfile, len(flow)))
9397
results = ft.runFlowTest(workspace_id=workspace_id, flow=flow, show_progress=True, version=watsonSDKVersion)
9498
print()
9599
#Full esults are hard to read, instead we let step by step progress report failures as they happen

0 commit comments

Comments
 (0)