Skip to content

Commit 25c07b8

Browse files
authored
Merge pull request #159 from xverges/XV_dialog_test_line_breaks
make use of regexp patterns explicit + friendlier multiline
2 parents f97d7e2 + 7008d9d commit 25c07b8

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

dialog_test/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ The columns are
3030

3131
All fields are optional
3232

33-
* Match Output indicates a substring that must be present in the Watson Assistant response. It is not necessary to provide the full input string.
33+
* 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?`).
3434

3535
If the User Input column is exactly 'NEWCONVERSATION' (no quotes) then a new conversation is started. This allows multiple tests in the same file.

dialog_test/flowtest_v1.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,10 @@ def runFlowTest(self, workspace_id=None, flow=None,json_dump=False,alternate_int
194194
if 'text' in r['output']:
195195
innerText = r['output']['text']
196196
if row['Match Output'] != '':
197-
matchedOutput = bool(re.search(row['Match Output'], '\n'.join(innerText)))
197+
row['Match Output'] = '<br>'.join(row['Match Output'].splitlines())
198+
ouput_pattern = row['Match Output']
199+
ouput_pattern = re.escape(ouput_pattern) if not ouput_pattern.startswith('/') else ouput_pattern[1:-1]
200+
matchedOutput = bool(re.search(ouput_pattern, '<br>'.join(innerText), re.MULTILINE))
198201
if matchedOutput == False:
199202
self.reportFailure()
200203
else:
@@ -226,7 +229,7 @@ def runFlowTest(self, workspace_id=None, flow=None,json_dump=False,alternate_int
226229

227230
record = {
228231
'User Input': row['User Input'],
229-
'Output Text': '\n'.join(r['output']['text']),
232+
'Output Text': '<br>'.join(r['output']['text']),
230233
'Alternate Intents': ai,
231234
'Conversation ID': r['context']['conversation_id'],
232235
'Context': r['context'],
@@ -300,4 +303,4 @@ def convertReportToIntentPerRow(self, report=None,input_all_lines=True):
300303

301304
return df
302305

303-
306+

0 commit comments

Comments
 (0)