Skip to content

Commit

Permalink
Updated integration tests and added some more unit tests around zero …
Browse files Browse the repository at this point in the history
…or more
  • Loading branch information
keiffster committed May 19, 2017
1 parent 45603df commit ccdfc44
Show file tree
Hide file tree
Showing 10 changed files with 402 additions and 230 deletions.
44 changes: 31 additions & 13 deletions bots/y-bot/aiml/core/datetime_convo.aiml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<category>
<pattern>
# WHAT # SEASON #
# THE SEASON ^
</pattern>
<template>
It is <srai>SEASON</srai>
Expand All @@ -34,7 +34,7 @@

<category>
<pattern>
# WHICH # SEASON #
# WHAT # SEASON ^
</pattern>
<template>
It is <srai>SEASON</srai>
Expand All @@ -43,7 +43,16 @@

<category>
<pattern>
# WHAT # MONTH #
# WHICH # SEASON ^
</pattern>
<template>
It is <srai>SEASON</srai>
</template>
</category>

<category>
<pattern>
# WHAT # MONTH ^
</pattern>
<template>
<srai>MONTH</srai>
Expand All @@ -52,7 +61,7 @@

<category>
<pattern>
# WHICH # MONTH #
# WHICH # MONTH ^
</pattern>
<template>
<srai>MONTH</srai>
Expand All @@ -61,7 +70,7 @@

<category>
<pattern>
# WHAT # DAY #
# WHAT # DAY ^
</pattern>
<template>
<srai>DAY</srai>
Expand All @@ -70,7 +79,7 @@

<category>
<pattern>
# WHICH # DAY #
# WHICH # DAY ^
</pattern>
<template>
<srai>DAY</srai>
Expand All @@ -88,10 +97,19 @@

<category>
<pattern>
# WHAT # TODAY
# WHAT # TODAY ^
</pattern>
<template>
<srai>TODAY</srai>
<srai>DAY</srai>
</template>
</category>

<category>
<pattern>
# WHICH # TODAY ^
</pattern>
<template>
<srai>DAY</srai>
</template>
</category>

Expand Down Expand Up @@ -124,7 +142,7 @@

<category>
<pattern>
# WHAT # YEAR #
# WHAT # YEAR ^
</pattern>
<template>
<srai>YEAR</srai>
Expand All @@ -133,7 +151,7 @@

<category>
<pattern>
# WHICH # YEAR #
# WHICH # YEAR ^
</pattern>
<template>
<srai>YEAR</srai>
Expand All @@ -142,7 +160,7 @@

<category>
<pattern>
# WHAT # TODAYS DATE #
# WHAT # TODAYS DATE ^
</pattern>
<template>
<srai>DATE</srai>
Expand All @@ -151,7 +169,7 @@

<category>
<pattern>
# WHAT # DATE #
# WHAT # DATE ^
</pattern>
<template>
<srai>DATE</srai>
Expand All @@ -160,7 +178,7 @@

<category>
<pattern>
# WHAT # TIME #
# WHAT # TIME ^
</pattern>
<template>
<srai>TIME</srai>
Expand Down
56 changes: 56 additions & 0 deletions bots/y-bot/tests/core/datetime_convo.tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# THE SEASON #
"THE SEASON", "Winter", "Spring", "Summer", "Autumn", "Fall"
"TELL ME THE SEASON", "Winter", "Spring", "Summer", "Autumn", "Fall"

# WHAT # SEASON #
"WHAT SEASON", "Winter", "Spring", "Summer", "Autumn", "Fall"
"WHAT SEASON IS IT", "Winter", "Spring", "Summer", "Autumn", "Fall"
"DO YOU KNOW WHAT SEASON IT IS", "Winter", "Spring", "Summer", "Autumn", "Fall"

# WHICH # SEASON #
"WHICH SEASON", "Winter", "Spring", "Summer", "Autumn", "Fall"
"WHICH SEASON IS IT", "Winter", "Spring", "Summer", "Autumn", "Fall"
"CAN YOU TELL ME WHICH SEASON IT IS", "Winter", "Spring", "Summer", "Autumn", "Fall"

# WHAT # MONTH #
"WHAT MONTH", "This is [January|February|March|April|May|June|July|August|September|October|November|December]"
"WHAT MONTH IS IT", "This is [January|February|March|April|May|June|July|August|September|October|November|December]"
"TELL ME WHAT MONTH IS IT", "This is [January|February|March|April|May|June|July|August|September|October|November|December]"

# WHICH # MONTH #
"WHICH MONTH", "This is [January|February|March|April|May|June|July|August|September|October|November|December]"
"WHICH MONTH IS IT", "This is [January|February|March|April|May|June|July|August|September|October|November|December]"
"TELL ME WHICH MONTH IS IT", "This is [January|February|March|April|May|June|July|August|September|October|November|December]"

# WHAT # DAY #
"WHAT DAY", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"

# WHICH # DAY #
"WHICH DAY", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"

# TODAY
"TODAY", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"

# WHAT # TODAY
"WHAT TODAY", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"

# WHAT # DAY # TOMORROW
"WHAT DAY TOMORROW", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"

# WHAT IS TOMORROW
"WHAT DAY IS TOMORROW", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"

# WHICH # DAY # TOMORROW
"WHICH DAY TOMORROW", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"

# WHAT # YEAR #
"WHAT YEAR", "20[0-9][0-9]"

# WHICH # YEAR #
"WHICH YEAR", "20[0-9][0-9]"

# WHAT # TODAYS DATE #

# WHAT # DATE #

# WHAT # TIME #
16 changes: 16 additions & 0 deletions bots/y-bot/tests/core/datetime_core.tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"SEASON", "Winter", "Spring", "Summer", "Autumn", "Fall"
"DAY", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"
"TOMORROW", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"
"YEAR", "This is [0-9]*"
"NEXT YEAR", "[0-9]*"
"LAST YEAR", "[0-9]*"
"MONTH", "This is [January|February|March|April|May|June|July|August|September|October|November|December]"
"TIME", "The time is [0-9]{2}:[0-9]{2} [AM|PM]"
"DATE", "Today is *. [0-9]{2},[0-9]{4}"
"DAY PHASE", "Morning", "Noon", "Afternoon", "Night", "Midnight"
"DATE AND TIME", "The date and time is .* .* [0-9]* [0-9]{2}:[0-9]{2}:[0-9]{2} [0-9]{4}"
"DAYS UNTIL CHRISTMAS", "[0-9]* days until Christmas."
"DAYS UNTIL JANUARY 01 2020", "[0-9]* days."
"DAYS UNTIL JANUARY 01", "-?[0-9]* days"
"DATE TOMORROW", "[0-9]{2},[0-9]{4}"

11 changes: 0 additions & 11 deletions pylint.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
# pygtk.require().
#init-hook=

# Profiled execution.
profile=no

# Add files or directories to the blacklist. They should be base names, not
# paths.
ignore=CVS
Expand Down Expand Up @@ -50,10 +47,6 @@ reports=yes
# (RP0004).
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)

# Add a comment according to your evaluation note. This is used by the global
# evaluation report (RP0004).
comment=no

# Template used to display messages. This is a python new-style format string
# used to format the message information. See doc for all details
#msg-template=
Expand Down Expand Up @@ -236,10 +229,6 @@ ignored-modules=
# (useful for classes with attributes dynamically set).
ignored-classes=SQLObject

# When zope mode is activated, add a predefined set of Zope acquired attributes
# to generated-members.
zope=no

# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E0201 when accessed. Python regular
# expressions are accepted.
Expand Down
11 changes: 9 additions & 2 deletions src/programy/clients/test_runner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import csv
import re
import datetime

from programy.clients.clients import BotClient
from programy.utils.files.filefinder import FileFinder
Expand Down Expand Up @@ -92,13 +93,14 @@ def set_environment(self):
def run(self):
print ("Loading Tests from directory [%s]" % self.test_dir)
file_finder = TestFileFileFinder()
collection = file_finder.load_dir_contents(self.test_dir, extension=".tests")
collection = file_finder.load_dir_contents(self.test_dir, extension=".tests", subdir=True)
successes = []
failures = []
start = datetime.datetime.now()
for category in collection.keys():
for test in collection[category]:
test.category = category
response = self.bot.ask_question(self.clientid, test.question).upper()
response = self.bot.ask_question(self.clientid, test.question)
success = False
test.response = response
if len(test.answers_regex) == 0:
Expand All @@ -114,11 +116,16 @@ def run(self):
successes.append(test)
else:
failures.append(test)
stop = datetime.datetime.now()
diff = stop-start
total_tests = len(successes)+len(failures)

print ("Successes: %d" % len(successes))
print ("Failures: %d" % len(failures))
for failure in failures:
print ("\t%s: [%s] expected [%s], got [%s]" % (failure.category, failure.question, failure.answers_string, failure.response))
print ("Total processing time %f.2 secs"%diff.total_seconds())
print ("Thats approx %f tests per sec"%(total_tests/diff.total_seconds()))

if __name__ == '__main__':

Expand Down
8 changes: 8 additions & 0 deletions src/programy/parser/pattern/nodes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ def consume(self, bot, clientid, context, words, word_no, type, depth):
if self._topic is not None:
match = self._topic.consume(bot, clientid, context, words, word_no, Match.TOPIC, depth+1)
if match is not None:
logging.debug("%sMatched topic, success!" % (tabs))
return match
if words.word(word_no) == PatternNode.TOPIC:
logging.debug("%s Looking for a %s, none give, no match found!" % (tabs, PatternNode.TOPIC))
Expand All @@ -376,6 +377,7 @@ def consume(self, bot, clientid, context, words, word_no, type, depth):
if self._that is not None:
match = self._that.consume(bot, clientid, context, words, word_no, Match.THAT, depth+1)
if match is not None:
logging.debug("%sMatched that, success!" % (tabs))
return match
if words.word(word_no) == PatternNode.THAT:
logging.debug("%s Looking for a %s, none give, no match found!" % (tabs, PatternNode.THAT))
Expand All @@ -392,20 +394,23 @@ def consume(self, bot, clientid, context, words, word_no, type, depth):

match = child.consume(bot, clientid, context, words, word_no + 1, type, depth+1)
if match is not None:
logging.debug("%sMatched child, success!" % (tabs))
return match
else:
context.pop_match ()

if self._0ormore_hash is not None:
match = self._0ormore_hash.consume(bot, clientid, context, words, word_no, type, depth+1)
if match is not None:
logging.debug("%sMatched 0 or more hash, success!" % (tabs))
return match
#else:
# context.pop_match ()

if self._1ormore_underline is not None:
match = self._1ormore_underline.consume(bot, clientid, context, words, word_no, type, depth+1)
if match is not None:
logging.debug("%sMatched 1 or more underline, success!" % (tabs))
return match
#else:
# context.pop_match ()
Expand All @@ -420,20 +425,23 @@ def consume(self, bot, clientid, context, words, word_no, type, depth):

match = child.consume(bot, clientid, context, words, word_no + 1, type, depth+1)
if match is not None:
logging.debug("%sMatched child, success!" % (tabs))
return match
else:
context.pop_match ()

if self._0ormore_arrow is not None:
match = self._0ormore_arrow.consume(bot, clientid, context, words, word_no, type, depth+1)
if match is not None:
logging.debug("%sMatched 0 or more arrow, success!" % (tabs))
return match
#else:
# context.pop_match ()

if self._1ormore_star is not None:
match = self._1ormore_star.consume(bot, clientid, context, words, word_no, type, depth+1)
if match is not None:
logging.debug("%sMatched 1 or more star, success!" % (tabs))
return match
#else:
# context.pop_match ()
Expand Down
18 changes: 14 additions & 4 deletions src/programy/parser/pattern/nodes/oneormore.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,13 @@ def consume(self, bot, clientid, context, words, word_no, type, depth):
if match is not None:
return match

if word == PatternTopicNode.TOPIC or word == PatternThatNode.THAT:
logging.debug ("Found a topic or that ar the wrong place....")
if word == PatternTopicNode.TOPIC:
logging.debug ("Found a topic at the wrong place....")
context.pop_matches(matches_add)
return None

if word == PatternThatNode.THAT:
logging.debug ("Found a that at the wrong place....")
context.pop_matches(matches_add)
return None

Expand All @@ -138,8 +143,13 @@ def consume(self, bot, clientid, context, words, word_no, type, depth):
if match is not None:
return match

if word == PatternTopicNode.TOPIC or word == PatternThatNode.THAT:
logging.debug ("Found a topic or that ar the wrong place....")
if word == PatternTopicNode.TOPIC:
logging.debug ("Found a topic at the wrong place....")
context.pop_matches(matches_add)
return None

if word == PatternThatNode.THAT:
logging.debug ("Found a that at the wrong place....")
context.pop_matches(matches_add)
return None

Expand Down
Loading

0 comments on commit ccdfc44

Please sign in to comment.