From 6df9577722b58d4dfd83701e597c4c16e00b99bb Mon Sep 17 00:00:00 2001 From: keithsterling Date: Mon, 11 Sep 2017 15:18:30 +0100 Subject: [PATCH] Fixed some minor Windows only issues on units tests --- bots/professor/config.windows.yaml | 4 +- bots/y-bot/config.windows.yaml | 5 +- src/programy/bot.py | 2 +- src/programy/parser/pattern/graph.py | 2 +- src/programy/parser/pattern/matcher.py | 2 +- test/programytest/clients/config.windows.yaml | 19 + .../programytest/clients/logging.windows.yaml | 20 + test/programytest/clients/test_client.py | 43 +- test/programytest/clients/test_sanicrest.py | 484 +++++++++--------- test/programytest/clients/test_twitter.py | 5 +- test/programytest/test_bot.py | 12 +- 11 files changed, 340 insertions(+), 258 deletions(-) create mode 100644 test/programytest/clients/config.windows.yaml create mode 100644 test/programytest/clients/logging.windows.yaml diff --git a/bots/professor/config.windows.yaml b/bots/professor/config.windows.yaml index 37cf418ad..2977f78cb 100644 --- a/bots/professor/config.windows.yaml +++ b/bots/professor/config.windows.yaml @@ -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: diff --git a/bots/y-bot/config.windows.yaml b/bots/y-bot/config.windows.yaml index 36b61b987..f13dbbc95 100644 --- a/bots/y-bot/config.windows.yaml +++ b/bots/y-bot/config.windows.yaml @@ -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 diff --git a/src/programy/bot.py b/src/programy/bot.py index 106ec7d36..92e300e76 100644 --- a/src/programy/bot.py +++ b/src/programy/bot.py @@ -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): diff --git a/src/programy/parser/pattern/graph.py b/src/programy/parser/pattern/graph.py index ac796e1f7..20d01039e 100644 --- a/src/programy/parser/pattern/graph.py +++ b/src/programy/parser/pattern/graph.py @@ -252,7 +252,7 @@ def save_braintree(self, bot, clientid, filename, content): braintree += '\n' braintree += self.root.to_xml(bot, clientid) braintree += '\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( diff --git a/src/programy/parser/pattern/matcher.py b/src/programy/parser/pattern/matcher.py index ad5e840b3..65c782ac3 100644 --- a/src/programy/parser/pattern/matcher.py +++ b/src/programy/parser/pattern/matcher.py @@ -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) diff --git a/test/programytest/clients/config.windows.yaml b/test/programytest/clients/config.windows.yaml new file mode 100644 index 000000000..dccda5ea0 --- /dev/null +++ b/test/programytest/clients/config.windows.yaml @@ -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 diff --git a/test/programytest/clients/logging.windows.yaml b/test/programytest/clients/logging.windows.yaml new file mode 100644 index 000000000..494198f2b --- /dev/null +++ b/test/programytest/clients/logging.windows.yaml @@ -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 diff --git a/test/programytest/clients/test_client.py b/test/programytest/clients/test_client.py index 8b8fec32a..aeb63a024 100644 --- a/test/programytest/clients/test_client.py +++ b/test/programytest/clients/test_client.py @@ -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): @@ -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) @@ -52,9 +67,18 @@ 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) @@ -62,8 +86,15 @@ def test_sub_classed_client_no_bot_root(self): 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) diff --git a/test/programytest/clients/test_sanicrest.py b/test/programytest/clients/test_sanicrest.py index 32775b5ac..905f97273 100644 --- a/test/programytest/clients/test_sanicrest.py +++ b/test/programytest/clients/test_sanicrest.py @@ -2,259 +2,259 @@ import unittest.mock import os -from programy.clients.sanicrest import SanicRestBotClient - - from programytest.clients.arguments import MockArgumentParser -class MockSanicRestBotClient(SanicRestBotClient): - - def __init__(self, argument_parser=None): - SanicRestBotClient.__init__(self, argument_parser) - self.aborted = False - self.answer = None - self.ask_question_exception = False - - def server_abort(self, message, status_code): - self.aborted = True - raise Exception("Pretending to abort!") - - def ask_question(self, sessionid, question): - if self.ask_question_exception is True: - raise Exception("Something bad happened") - return self.answer - -class SanicBotClientTests(unittest.TestCase): - - def test_rest_client_init(self): - arguments = MockArgumentParser() - client = SanicRestBotClient(arguments) - self.assertIsNotNone(client) - - def test_verify_api_key_usage_inactive(self): - arguments = MockArgumentParser() - client = SanicRestBotClient(arguments) - self.assertIsNotNone(client) - client.configuration.client_configuration._use_api_keys = False - request = unittest.mock.Mock() - self.assertEquals((None, None),client.verify_api_key_usage(request)) - - def test_get_api_key(self): - arguments = MockArgumentParser() - client = SanicRestBotClient(arguments) - - request = unittest.mock.Mock() - request.raw_args = {} - request.raw_args['apikey'] = '11111111' - - self.assertEquals('11111111', client.get_api_key(request)) - - def test_verify_api_key_usage_active(self): - arguments = MockArgumentParser() - client = SanicRestBotClient(arguments) - self.assertIsNotNone(client) - client.configuration.client_configuration._use_api_keys = True - client.configuration.client_configuration._api_key_file = os.path.dirname(__file__) + os.sep + "api_keys.txt" - client.load_api_keys() - request = unittest.mock.Mock() - request.raw_args = {} - request.raw_args['apikey'] = '11111111' - self.assertEquals((None, None),client.verify_api_key_usage(request)) - - def test_verify_api_key_usage_active_no_apikey(self): - arguments = MockArgumentParser() - client = MockSanicRestBotClient(arguments) - client.configuration.client_configuration._use_api_keys = True - - request = unittest.mock.Mock() - request.raw_args = {} - - response = client.verify_api_key_usage(request) - self.assertIsNotNone(response) - - def test_verify_api_key_usage_active_invalid_apikey(self): - arguments = MockArgumentParser() - client = MockSanicRestBotClient(arguments) - client.configuration.client_configuration._use_api_keys = True - - request = unittest.mock.Mock() - request.raw_args = {} - request.raw_args['apikey'] = 'invalid' - - response = client.verify_api_key_usage(request) - self.assertIsNotNone(response) - - def test_get_question(self): - arguments = MockArgumentParser() - client = SanicRestBotClient(arguments) - self.assertIsNotNone(client) - - request = unittest.mock.Mock() - request.raw_args = {} - request.raw_args['question'] = 'Hello' - - self.assertEquals("Hello", client.get_question(request)) - - def test_get_question_no_question(self): - arguments = MockArgumentParser() - client = MockSanicRestBotClient(arguments) - self.assertIsNotNone(client) - - request = unittest.mock.Mock() - request.raw_args = {} - request.raw_args['question'] = None - - self.assertFalse(client.aborted) - with self.assertRaises(Exception): - self.assertEquals("Hello", client.get_question(request)) - self.assertTrue(client.aborted) - - def test_get_question_none_question(self): - arguments = MockArgumentParser() - client = MockSanicRestBotClient(arguments) - self.assertIsNotNone(client) +if os.name != "nt": + from programy.clients.sanicrest import SanicRestBotClient + + class MockSanicRestBotClient(SanicRestBotClient): + + def __init__(self, argument_parser=None): + SanicRestBotClient.__init__(self, argument_parser) + self.aborted = False + self.answer = None + self.ask_question_exception = False + + def server_abort(self, message, status_code): + self.aborted = True + raise Exception("Pretending to abort!") + + def ask_question(self, sessionid, question): + if self.ask_question_exception is True: + raise Exception("Something bad happened") + return self.answer + + class SanicBotClientTests(unittest.TestCase): + + def test_rest_client_init(self): + arguments = MockArgumentParser() + client = SanicRestBotClient(arguments) + self.assertIsNotNone(client) + + def test_verify_api_key_usage_inactive(self): + arguments = MockArgumentParser() + client = SanicRestBotClient(arguments) + self.assertIsNotNone(client) + client.configuration.client_configuration._use_api_keys = False + request = unittest.mock.Mock() + self.assertEquals((None, None),client.verify_api_key_usage(request)) + + def test_get_api_key(self): + arguments = MockArgumentParser() + client = SanicRestBotClient(arguments) + + request = unittest.mock.Mock() + request.raw_args = {} + request.raw_args['apikey'] = '11111111' + + self.assertEquals('11111111', client.get_api_key(request)) + + def test_verify_api_key_usage_active(self): + arguments = MockArgumentParser() + client = SanicRestBotClient(arguments) + self.assertIsNotNone(client) + client.configuration.client_configuration._use_api_keys = True + client.configuration.client_configuration._api_key_file = os.path.dirname(__file__) + os.sep + "api_keys.txt" + client.load_api_keys() + request = unittest.mock.Mock() + request.raw_args = {} + request.raw_args['apikey'] = '11111111' + self.assertEquals((None, None),client.verify_api_key_usage(request)) + + def test_verify_api_key_usage_active_no_apikey(self): + arguments = MockArgumentParser() + client = MockSanicRestBotClient(arguments) + client.configuration.client_configuration._use_api_keys = True + + request = unittest.mock.Mock() + request.raw_args = {} + + response = client.verify_api_key_usage(request) + self.assertIsNotNone(response) + + def test_verify_api_key_usage_active_invalid_apikey(self): + arguments = MockArgumentParser() + client = MockSanicRestBotClient(arguments) + client.configuration.client_configuration._use_api_keys = True + + request = unittest.mock.Mock() + request.raw_args = {} + request.raw_args['apikey'] = 'invalid' + + response = client.verify_api_key_usage(request) + self.assertIsNotNone(response) + + def test_get_question(self): + arguments = MockArgumentParser() + client = SanicRestBotClient(arguments) + self.assertIsNotNone(client) + + request = unittest.mock.Mock() + request.raw_args = {} + request.raw_args['question'] = 'Hello' - request = unittest.mock.Mock() - request.raw_args = {} - - self.assertFalse(client.aborted) - with self.assertRaises(Exception): self.assertEquals("Hello", client.get_question(request)) - self.assertTrue(client.aborted) - def test_get_sessionid(self): - arguments = MockArgumentParser() - client = SanicRestBotClient(arguments) - self.assertIsNotNone(client) + def test_get_question_no_question(self): + arguments = MockArgumentParser() + client = MockSanicRestBotClient(arguments) + self.assertIsNotNone(client) - request = unittest.mock.Mock() - request.raw_args = {} - request.raw_args['sessionid'] = '1234567890' + request = unittest.mock.Mock() + request.raw_args = {} + request.raw_args['question'] = None - self.assertEquals("1234567890", client.get_sessionid(request)) + self.assertFalse(client.aborted) + with self.assertRaises(Exception): + self.assertEquals("Hello", client.get_question(request)) + self.assertTrue(client.aborted) - def test_get_sessionid_no_sessionid(self): - arguments = MockArgumentParser() - client = MockSanicRestBotClient(arguments) - self.assertIsNotNone(client) + def test_get_question_none_question(self): + arguments = MockArgumentParser() + client = MockSanicRestBotClient(arguments) + self.assertIsNotNone(client) - request = unittest.mock.Mock() - request.raw_args = {} + request = unittest.mock.Mock() + request.raw_args = {} - self.assertFalse(client.aborted) - with self.assertRaises(Exception): - self.assertEquals("1234567890", client.get_sessionid(request)) - self.assertTrue(client.aborted) + self.assertFalse(client.aborted) + with self.assertRaises(Exception): + self.assertEquals("Hello", client.get_question(request)) + self.assertTrue(client.aborted) - def test_get_sessionid_none_sessionid(self): - arguments = MockArgumentParser() - client = MockSanicRestBotClient(arguments) - self.assertIsNotNone(client) + def test_get_sessionid(self): + arguments = MockArgumentParser() + client = SanicRestBotClient(arguments) + self.assertIsNotNone(client) - request = unittest.mock.Mock() - request.raw_args = {} - request.raw_args['sessionid'] = None + request = unittest.mock.Mock() + request.raw_args = {} + request.raw_args['sessionid'] = '1234567890' - self.assertFalse(client.aborted) - with self.assertRaises(Exception): self.assertEquals("1234567890", client.get_sessionid(request)) - self.assertTrue(client.aborted) - - def test_format_success_response(self): - arguments = MockArgumentParser() - client = SanicRestBotClient(arguments) - self.assertIsNotNone(client) - - response = client.format_success_response("1234567890", "Hello", "Hi") - self.assertIsNotNone(response) - self.assertEquals("1234567890", response['sessionid']) - self.assertEquals("Hello", response['question']) - self.assertEquals("Hi", response['answer']) - - def test_format_error_response(self): - arguments = MockArgumentParser() - client = SanicRestBotClient(arguments) - self.assertIsNotNone(client) - - response = client.format_error_response("1234567890", "Hello", "Something Bad") - self.assertIsNotNone(response) - self.assertEquals("1234567890", response['sessionid']) - self.assertEquals("Hello", response['question']) - self.assertEquals("", response['answer']) - self.assertEquals("Something Bad", response['error']) - - def test_process_response(self): - arguments = MockArgumentParser() - client = SanicRestBotClient(arguments) - self.assertIsNotNone(client) - - response = client.process_response("1234567890", "Hello", "Hi") - self.assertIsNotNone(response) - self.assertEquals("1234567890", response['sessionid']) - self.assertEquals("Hello", response['question']) - self.assertEquals("Hi", response['answer']) - - def test_process_response_no_anwser(self): - arguments = MockArgumentParser() - client = SanicRestBotClient(arguments) - self.assertIsNotNone(client) - - response = client.process_response("1234567890", "Hello", None) - self.assertIsNotNone(response) - self.assertEquals("1234567890", response['sessionid']) - self.assertEquals("Hello", response['question']) - self.assertEquals("", response['answer']) - - def test_process_request(self): - arguments = MockArgumentParser() - client = MockSanicRestBotClient(arguments) - self.assertIsNotNone(client) - client.configuration.client_configuration._use_api_keys = False - - request = unittest.mock.Mock() - request.raw_args = {} - request.raw_args['question'] = 'Hello' - request.raw_args['sessionid'] = '1234567890' - - client.answer = "Hi" - - response, status = client.process_request(request) - self.assertIsNotNone(response) - self.assertEquals("1234567890", response['sessionid']) - self.assertEquals("Hello", response['question']) - self.assertEquals("Hi", response['answer']) - - def test_process_request_no_api_key(self): - arguments = MockArgumentParser() - client = MockSanicRestBotClient(arguments) - self.assertIsNotNone(client) - client.configuration.client_configuration._use_api_keys = True - - request = unittest.mock.Mock() - request.raw_args = {} - request.raw_args['question'] = 'Hello' - request.raw_args['sessionid'] = '1234567890' - - client.answer = "Hi" - - response, status = client.process_request(request) - self.assertIsNotNone(response) - self.assertEquals(status, 401) - - def test_process_request_exception(self): - arguments = MockArgumentParser() - client = MockSanicRestBotClient(arguments) - self.assertIsNotNone(client) - client.configuration.client_configuration._use_api_keys = False - - request = unittest.mock.Mock() - request.raw_args = {} - request.raw_args['question'] = 'Hello' - request.raw_args['sessionid'] = '1234567890' - - client.answer = "Hi" - client.ask_question_exception = True - - response, status = client.process_request(request) - self.assertIsNotNone(response) - self.assertEquals(status, 500) + + def test_get_sessionid_no_sessionid(self): + arguments = MockArgumentParser() + client = MockSanicRestBotClient(arguments) + self.assertIsNotNone(client) + + request = unittest.mock.Mock() + request.raw_args = {} + + self.assertFalse(client.aborted) + with self.assertRaises(Exception): + self.assertEquals("1234567890", client.get_sessionid(request)) + self.assertTrue(client.aborted) + + def test_get_sessionid_none_sessionid(self): + arguments = MockArgumentParser() + client = MockSanicRestBotClient(arguments) + self.assertIsNotNone(client) + + request = unittest.mock.Mock() + request.raw_args = {} + request.raw_args['sessionid'] = None + + self.assertFalse(client.aborted) + with self.assertRaises(Exception): + self.assertEquals("1234567890", client.get_sessionid(request)) + self.assertTrue(client.aborted) + + def test_format_success_response(self): + arguments = MockArgumentParser() + client = SanicRestBotClient(arguments) + self.assertIsNotNone(client) + + response = client.format_success_response("1234567890", "Hello", "Hi") + self.assertIsNotNone(response) + self.assertEquals("1234567890", response['sessionid']) + self.assertEquals("Hello", response['question']) + self.assertEquals("Hi", response['answer']) + + def test_format_error_response(self): + arguments = MockArgumentParser() + client = SanicRestBotClient(arguments) + self.assertIsNotNone(client) + + response = client.format_error_response("1234567890", "Hello", "Something Bad") + self.assertIsNotNone(response) + self.assertEquals("1234567890", response['sessionid']) + self.assertEquals("Hello", response['question']) + self.assertEquals("", response['answer']) + self.assertEquals("Something Bad", response['error']) + + def test_process_response(self): + arguments = MockArgumentParser() + client = SanicRestBotClient(arguments) + self.assertIsNotNone(client) + + response = client.process_response("1234567890", "Hello", "Hi") + self.assertIsNotNone(response) + self.assertEquals("1234567890", response['sessionid']) + self.assertEquals("Hello", response['question']) + self.assertEquals("Hi", response['answer']) + + def test_process_response_no_anwser(self): + arguments = MockArgumentParser() + client = SanicRestBotClient(arguments) + self.assertIsNotNone(client) + + response = client.process_response("1234567890", "Hello", None) + self.assertIsNotNone(response) + self.assertEquals("1234567890", response['sessionid']) + self.assertEquals("Hello", response['question']) + self.assertEquals("", response['answer']) + + def test_process_request(self): + arguments = MockArgumentParser() + client = MockSanicRestBotClient(arguments) + self.assertIsNotNone(client) + client.configuration.client_configuration._use_api_keys = False + + request = unittest.mock.Mock() + request.raw_args = {} + request.raw_args['question'] = 'Hello' + request.raw_args['sessionid'] = '1234567890' + + client.answer = "Hi" + + response, status = client.process_request(request) + self.assertIsNotNone(response) + self.assertEquals("1234567890", response['sessionid']) + self.assertEquals("Hello", response['question']) + self.assertEquals("Hi", response['answer']) + + def test_process_request_no_api_key(self): + arguments = MockArgumentParser() + client = MockSanicRestBotClient(arguments) + self.assertIsNotNone(client) + client.configuration.client_configuration._use_api_keys = True + + request = unittest.mock.Mock() + request.raw_args = {} + request.raw_args['question'] = 'Hello' + request.raw_args['sessionid'] = '1234567890' + + client.answer = "Hi" + + response, status = client.process_request(request) + self.assertIsNotNone(response) + self.assertEquals(status, 401) + + def test_process_request_exception(self): + arguments = MockArgumentParser() + client = MockSanicRestBotClient(arguments) + self.assertIsNotNone(client) + client.configuration.client_configuration._use_api_keys = False + + request = unittest.mock.Mock() + request.raw_args = {} + request.raw_args['question'] = 'Hello' + request.raw_args['sessionid'] = '1234567890' + + client.answer = "Hi" + client.ask_question_exception = True + + response, status = client.process_request(request) + self.assertIsNotNone(response) + self.assertEquals(status, 500) diff --git a/test/programytest/clients/test_twitter.py b/test/programytest/clients/test_twitter.py index ef9a5ac50..5a552ac75 100644 --- a/test/programytest/clients/test_twitter.py +++ b/test/programytest/clients/test_twitter.py @@ -427,7 +427,10 @@ def test_message_ids_save_load(self): self.assertIsNotNone(client) client.configuration.client_configuration._storage = 'file' - client.configuration.client_configuration._storage_location = "/tmp/twitter.txt" + if os.name == 'posix': + client.configuration.client_configuration._storage_location = "/tmp/twitter.txt" + else: + client.configuration.client_configuration._storage_location = "C:\Windows\Temp/twitter.txt" if os.path.exists(client.configuration.client_configuration.storage_location): os.remove(client.configuration.client_configuration.storage_location) diff --git a/test/programytest/test_bot.py b/test/programytest/test_bot.py index deffce42a..116d3a90f 100644 --- a/test/programytest/test_bot.py +++ b/test/programytest/test_bot.py @@ -222,8 +222,7 @@ def test_total_search_time(self): self.assertIsNotNone(bot) bot._question_start_time = datetime.datetime.now() - self.assertTrue(bot.total_search_time() > 0) - + self.assertTrue(bot.total_search_time() >= 0) bot.configuration._max_question_timeout = -1 bot.check_max_timeout() @@ -235,7 +234,14 @@ def test_total_search_time(self): def test_log_question_and_answer(self): brain_config = BrainConfiguration() - brain_config.files.aiml_files._conversation = "/tmp/tmp-conversation.txt" + + if os.name == 'posix': + brain_config.files.aiml_files._conversation = "/tmp/tmp-conversation.txt" + elif os.name == 'nt': + brain_config.files.aiml_files._conversation = 'C:\Windows\Temp\\tmp-conversation.txt' + else: + raise Exception("Unknown os [%s]" % os.name) + test_brain = Brain(brain_config) bot = Bot(test_brain, BotConfiguration())