Exemplo n.º 1
0
    def test_save_then_load(self):

        tmpdir = FileStorageConfiguration.get_temp_dir()

        fullpath = tmpdir + os.sep + "braintree/braintree.bin"

        if os.path.exists(fullpath):
            os.remove(fullpath)

        factory = self.create_storage_factory(fullpath)

        config = BrainBinariesConfiguration()
        manager = BinariesManager(config)
        self.assertIsNotNone(manager)

        test_client = TestClient()
        client_context = test_client.create_client_context("test1")

        self.assertTrue(
            manager.save_binary(factory, client_context.bot.brain.aiml_parser))

        self.assertTrue(os.path.exists(fullpath))

        aiml_parser2 = manager.load_binary(factory)
        self.assertIsNotNone(aiml_parser2)

        if os.path.exists(fullpath):
            os.remove(fullpath)
Exemplo n.º 2
0
 def to_yaml(self, data, defaults=True):
     self.config_to_yaml(data, BrainOverridesConfiguration(), defaults)
     self.config_to_yaml(data, BrainDefaultsConfiguration(), defaults)
     self.config_to_yaml(data, BrainBinariesConfiguration(), defaults)
     self.config_to_yaml(data, BrainBraintreeConfiguration(), defaults)
     self.config_to_yaml(data, BrainSecuritiesConfiguration(), defaults)
     self.config_to_yaml(data, BrainDynamicsConfiguration(), defaults)
     self.config_to_yaml(data, BrainTokenizerConfiguration(), defaults)
     self.config_to_yaml(data, BrainDebugFilesConfiguration(), defaults)
Exemplo n.º 3
0
 def __init__(self, section_name="brain"):
     self._overrides = BrainOverridesConfiguration()
     self._defaults = BrainDefaultsConfiguration()
     self._binaries = BrainBinariesConfiguration()
     self._braintree = BrainBraintreeConfiguration()
     self._security = BrainSecuritiesConfiguration()
     self._dynamics = BrainDynamicsConfiguration()
     self._tokenizer = BrainTokenizerConfiguration()
     self._debugfiles = BrainDebugFilesConfiguration()
     BaseContainerConfigurationData.__init__(self, section_name)
Exemplo n.º 4
0
    def test_save_binary_no_storage(self):
        bin_config = BrainBinariesConfiguration()
        bin_manager = BinariesManager(bin_config)

        tmpdir = os.path.dirname(__file__) + os.sep + "tmp"
        binfile = tmpdir + os.sep + 'braintree.bin'

        client = TestClient(binfile)

        bot = client.bot_factory._bots['bot']
        brain = bot.brain

        bin_manager.set_aiml_parser(brain.aiml_parser)
        bin_manager.save_binary(client.storage_factory)
Exemplo n.º 5
0
    def test_with_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
        brain:
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")

        binaries_config = BrainBinariesConfiguration()
        binaries_config.load_config_section(yaml, brain_config, ".")

        self.assertFalse(binaries_config.save_binary)
        self.assertFalse(binaries_config.load_binary)
        self.assertFalse(binaries_config.load_aiml_on_binary_fail)
Exemplo n.º 6
0
    def __init__(self, section_name="brain"):
        self._bot_name = None
        self._manager_name = None

        self._overrides = BrainOverridesConfiguration()
        self._defaults = BrainDefaultsConfiguration()
        self._binaries = BrainBinariesConfiguration()
        self._braintree = BrainBraintreeConfiguration()
        self._services = BrainServicesConfiguration()
        self._security = BrainSecuritiesConfiguration()
        self._oob = BrainOOBSConfiguration()
        self._dynamics = BrainDynamicsConfiguration()
        self._tokenizer = BrainTokenizerConfiguration()
        self._debugfiles = BrainDebugFilesConfiguration()
        self._nlu = BrainNluConfiguration()
        BaseContainerConfigurationData.__init__(self, section_name)
Exemplo n.º 7
0
    def test_load_with_exception_and_not_raise(self):

        config = BrainBinariesConfiguration()
        config._load_aiml_on_binary_fail = True
        manager = BinariesManager(config)
        self.assertIsNotNone(manager)

        tmpdir = FileStorageConfiguration.get_temp_dir()

        fullpath = tmpdir + os.sep + "braintree/braintree.bin"

        if os.path.exists(fullpath):
            os.remove(fullpath)

        factory = self.create_storage_factory(fullpath)

        self.assertIsNone(manager.load_binary(factory))
Exemplo n.º 8
0
    def test_save_then_load_no_config(self):

        config = FileStorageConfiguration()
        factory = StorageFactory()
        storage_engine = FileStorageEngine(config)
        storage_engine.initialise()

        config = BrainBinariesConfiguration()
        manager = BinariesManager(config)
        self.assertIsNotNone(manager)

        test_client = TestClient()
        client_context = test_client.create_client_context("test1")

        self.assertFalse(
            manager.save_binary(factory, client_context.bot.brain.aiml_parser))

        self.assertIsNone(manager.load_binary(factory))
Exemplo n.º 9
0
    def test_with_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        brain:
            binaries:
              save_binary: true
              load_binary: true
              binary_filename: /tmp/y-bot.brain
              load_aiml_on_binary_fail: true
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")

        binaries_config = BrainBinariesConfiguration()
        binaries_config.load_config_section(yaml, brain_config, ".")

        self.assertTrue(binaries_config.save_binary)
        self.assertTrue(binaries_config.load_binary)
        self.assertEquals("/tmp/y-bot.brain", binaries_config.binary_filename)
        self.assertTrue(binaries_config.load_aiml_on_binary_fail)
Exemplo n.º 10
0
    def test_save_binary_no_parser(self):
        bin_config = BrainBinariesConfiguration()
        bin_manager = BinariesManager(bin_config)
        storage_factory = StorageFactory()

        bin_manager.save_binary(storage_factory)
Exemplo n.º 11
0
    def test_load_binary_no_storage(self):
        bin_config = BrainBinariesConfiguration()
        bin_manager = BinariesManager(bin_config)
        storage_factory = StorageFactory()

        bin_manager.load_binary(storage_factory)
Exemplo n.º 12
0
 def test_init_with_config(self):
     config = BrainBinariesConfiguration()
     manager = BinariesManager(config)
     self.assertIsNotNone(manager)
     self.assertEquals(config, manager._configuration)
Exemplo n.º 13
0
    def test_to_yaml_defaults(self):
        binaries_config = BrainBinariesConfiguration()
        data = {}
        binaries_config.to_yaml(data, True)

        BrainBinariesConfigurationTests.assert_defaults(self, data)