Ejemplo n.º 1
0
    def test_save_learnf(self):
        config = FileStorageConfiguration()
        tmpdir = os.path.dirname(__file__) + os.sep + "learnf"
        config.learnf_storage._dirs = [tmpdir]
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileLearnfStore(engine)

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

        learnf_path = store._get_storage_path()
        learnf_fullpath = store.create_learnf_path(client_context, learnf_path)

        if os.path.exists(learnf_fullpath):
            os.remove(learnf_fullpath)
        self.assertFalse(os.path.exists(learnf_fullpath))

        template = TemplateNode()
        template.append(TemplateWordNode("Hello"))

        category = LearnCategory("HELLO *", "*", "*", template)

        store.save_learnf(client_context, category)

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

        shutil.rmtree(tmpdir)
        self.assertFalse(os.path.exists(tmpdir))
Ejemplo n.º 2
0
    def test_save_learnf_with_exception(self):
        config = FileStorageConfiguration()
        tmpdir = os.path.dirname(__file__) + os.sep + "learnf"
        config.learnf_storage._dirs = [tmpdir]
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileLearnfStore(engine)

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

        learnf_path = store._get_storage_path()
        learnf_fullpath = store.create_learnf_path(client_context, learnf_path)

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

        self.assertFalse(os.path.exists(learnf_fullpath))

        pattern = ET.Element('pattern')
        pattern.text = "HELLO"
        topic = ET.Element('topic')
        topic.text = '*'
        that = ET.Element('that')
        that.text = '*'
        template = TemplateNode()
        template.append(TemplateWordNode("Hello"))

        category = LearnCategory(pattern, topic, that, template)

        self.assertFalse(store.save_learnf(client_context, category))
Ejemplo n.º 3
0
    def test_storage_path(self):
        config = FileStorageConfiguration()
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileLearnfStore(engine)

        self.assertEquals('/tmp/categories/learnf', store._get_storage_path())
        self.assertIsInstance(store.get_storage(), FileStoreConfiguration)
Ejemplo n.º 4
0
    def test_storage_path_multi_paths(self):
        config = FileStorageConfiguration()
        tmpdir = FileStorageConfiguration.get_temp_dir()
        config._learnf_storage = FileStoreConfiguration(dirs=[tmpdir + os.sep + "categories/learnf", tmpdir + os.sep + "categories/learnf2"], extension="aiml",
                                                      subdirs=False, fileformat="xml", encoding="utf-8",
                                                      delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileLearnfStore(engine)

        self.assertEquals('/tmp/categories/learnf', store._get_storage_path())
        self.assertIsInstance(store.get_storage(), FileStoreConfiguration)