Skip to content

Commit

Permalink
Fixed some minor Windows only issues on units tests
Browse files Browse the repository at this point in the history
  • Loading branch information
keiffster committed Sep 11, 2017
1 parent 8098a3d commit 6df9577
Show file tree
Hide file tree
Showing 11 changed files with 340 additions and 258 deletions.
4 changes: 2 additions & 2 deletions bots/professor/config.windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ brain:

# Braintree
braintree:
file: C:\Windows\Temp\braintree.xml
content: xml
file: C:\Windows\Temp\braintree.txt
content: txt

files:
aiml:
Expand Down
5 changes: 4 additions & 1 deletion bots/y-bot/config.windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ brain:
person: $BOT_ROOT\config\person.txt
person2: $BOT_ROOT\config\person2.txt
properties: $BOT_ROOT\config\properties.txt
triples: $BOT_ROOT\config\triples.txt
rdf:
files: $BOT_ROOT\rdf
extension: .txt
directories: false
preprocessors: $BOT_ROOT\config\preprocessors.conf
postprocessors: $BOT_ROOT\config\postprocessors.conf

Expand Down
2 changes: 1 addition & 1 deletion src/programy/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def total_search_time(self):

def check_max_timeout(self):
if self._configuration.max_question_timeout != -1:
if self.total_search_time() > self._configuration.max_question_timeout:
if self.total_search_time() >= self._configuration.max_question_timeout:
raise Exception ("Maximum search time limit [%d] exceeded"%(self._configuration.max_question_timeout))

def check_spelling_before(self, each_sentence):
Expand Down
2 changes: 1 addition & 1 deletion src/programy/parser/pattern/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def save_braintree(self, bot, clientid, filename, content):
braintree += '<aiml>\n'
braintree += self.root.to_xml(bot, clientid)
braintree += '</aiml>\n'
with open('/tmp/braintree.xml', "w+") as dump_file:
with open(filename, "w+") as dump_file:
dump_file.write(braintree)
else:
if logging.getLogger().isEnabledFor(logging.ERROR): logging.error(
Expand Down
2 changes: 1 addition & 1 deletion src/programy/parser/pattern/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def search_time_exceeded(self):
if self._max_search_timeout == -1:
return False
else:
return bool(self.total_search_time() > self._max_search_timeout)
return bool(self.total_search_time() >= self._max_search_timeout)

def add_match(self, match):
self._matched_nodes.append(match)
Expand Down
19 changes: 19 additions & 0 deletions test/programytest/clients/config.windows.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

brain:

allow_system_aiml: true
allow_learn_aiml: true
allow_learnf_aiml: true

bot:
prompt: ">>>"
initial_question: Hi, how can I help you today?
default_response: Sorry, I don't have an answer for that!
empty_string_srai: YEMPTY
exit_response: So long, and thanks for the fish!
override_properties: true

max_question_recursion: 1000
max_question_timeout: 60
max_search_depth: 100
max_search_timeout: 60
20 changes: 20 additions & 0 deletions test/programytest/clients/logging.windows.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 1
disable_existing_loggers: False

formatters:
simple:
format: '%(asctime)s %(name)-10s %(levelname)-7s %(message)s'

handlers:
file:
class: logging.handlers.RotatingFileHandler
formatter: simple
filename: C:\Windows\Temp\y-bot.log
maxBytes: 20972152
backupCount: 10
encoding: utf-8

root:
level: DEBUG
handlers:
- file
43 changes: 37 additions & 6 deletions test/programytest/clients/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ def get_client_configuration(self):

def load_configuration(self, arguments):
super(MockBotClient, self).load_configuration(arguments)
self.configuration.brain_configuration.braintree._file = "/tmp/tmp_braintree.txt"
if os.name == 'posix':
self.configuration.brain_configuration.braintree._file = "/tmp/tmp_braintree.txt"
elif os.name == 'nt':
self.configuration.brain_configuration.braintree._file = "C:\Windows\Temp\tmp_braintree.txt"
else:
raise Exception("Unknown os [%s]" % os.name)

class BotClientTests(unittest.TestCase):

Expand All @@ -35,9 +40,19 @@ def test_client_init(self):
client = BotClient(arguments)

def test_sub_classed_client(self):

if os.name == 'posix':
logging_file = os.path.dirname(__file__) + os.sep + "logging.yaml"
config_file = os.path.dirname(__file__) + os.sep + "config.yaml"
elif os.name == 'nt':
logging_file = os.path.dirname(__file__) + os.sep + "logging.windows.yaml"
config_file = os.path.dirname(__file__) + os.sep + "config.windows.yaml"
else:
raise Exception("Unknown os [%s]" % os.name)

arguments = MockArgumentParser(bot_root = ".",
logging=os.path.dirname(__file__)+os.sep+"logging.yaml",
config=os.path.dirname(__file__)+os.sep+"config.yaml",
logging=logging_file,
config=config_file,
cformat="yaml",
noloop=False)
client = MockBotClient(arguments)
Expand All @@ -52,18 +67,34 @@ def test_sub_classed_client(self):
client.log_unknown_response(None)

def test_sub_classed_client_no_bot_root(self):
if os.name == 'posix':
logging_file = os.path.dirname(__file__) + os.sep + "logging.yaml"
config_file = os.path.dirname(__file__) + os.sep + "config.yaml"
elif os.name == 'nt':
logging_file = os.path.dirname(__file__) + os.sep + "logging.windows.yaml"
config_file = os.path.dirname(__file__) + os.sep + "config.windows.yaml"
else:
raise Exception("Unknown os [%s]" % os.name)

arguments = MockArgumentParser(bot_root=None,
logging=os.path.dirname(__file__)+os.sep+"logging.yaml",
config=os.path.dirname(__file__)+os.sep+"config.yaml",
logging=logging_file,
config=config_file,
cformat="yaml",
noloop=False)
client = MockBotClient(arguments)
self.assertIsNotNone(client)
self.assertIsNotNone(client.arguments)

def test_sub_classed_client_no_bot_root_no_config(self):
if os.name == 'posix':
logging_file = os.path.dirname(__file__) + os.sep + "logging.yaml"
elif os.name == 'nt':
logging_file = os.path.dirname(__file__) + os.sep + "logging.windows.yaml"
else:
raise Exception("Unknown os [%s]" % os.name)

arguments = MockArgumentParser(bot_root=None,
logging=os.path.dirname(__file__)+os.sep+"logging.yaml",
logging=logging_file,
config=None,
cformat="yaml",
noloop=False)
Expand Down
Loading

0 comments on commit 6df9577

Please sign in to comment.