Beispiel #1
0
    def test_storage_path(self):
        config = FileStorageConfiguration()
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileBinariesStore(engine)

        self.assertEquals('/tmp/binaries/binaries.bin', store._get_storage_path())
        self.assertIsInstance(store.get_storage(), FileStoreConfiguration)
Beispiel #2
0
    def test_load_binaries_exception(self):
        config = FileStorageConfiguration()
        tmpdir = os.path.dirname(__file__) + os.sep + "binaries"
        tmpfile = tmpdir + os.sep + "binaries.bin"
        config.binaries_storage._dirs = [tmpfile]
        config.binaries_storage._has_single_file = True
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileBinariesStore(engine)

        aiml_parser2 = store.load_binary()
        self.assertIsNone(aiml_parser2)
Beispiel #3
0
    def test_save_load_binaries(self):
        config = FileStorageConfiguration()
        tmpdir = os.path.dirname(__file__) + os.sep + "braintree"
        tmpfile = tmpdir + os.sep + "braintree.bin"
        config.binaries_storage._dirs = [tmpfile]
        config.binaries_storage._has_single_file = True
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileBinariesStore(engine)

        aiml_parser = PretendAimlParser("pretend1")

        path = store._get_dir_from_path(store._get_storage_path())
        if os.path.exists(path):
            shutil.rmtree(path)
        self.assertFalse(os.path.exists(path))

        store.save_binary(aiml_parser)

        self.assertTrue(os.path.exists(store._get_storage_path()))

        aiml_parser2 = store.load_binary()
        self.assertIsNotNone(aiml_parser2)

        self.assertEqual(aiml_parser2._name, "pretend1")

        shutil.rmtree(tmpdir)
        self.assertFalse(os.path.exists(tmpdir))
Beispiel #4
0
    def test_save_binaries_exception(self):
        config = FileStorageConfiguration()
        tmpdir = os.path.dirname(__file__) + os.sep + "binaries"
        tmpfile = tmpdir + os.sep + "binaries.bin"
        config.binaries_storage._dirs = [tmpfile]
        config.binaries_storage._has_single_file = True
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileBinariesStore(engine)

        aiml_parser = PretendAimlParser("pretend1")

        path = store._get_dir_from_path(store._get_storage_path())
        if os.path.exists(path):
            shutil.rmtree(path)
        self.assertFalse(os.path.exists(path))

        store.save_binary(aiml_parser)
Beispiel #5
0
 def binaries_store(self):
     return FileBinariesStore(self)
Beispiel #6
0
 def test_initialise(self):
     config = FileStorageConfiguration()
     engine = FileStorageEngine(config)
     engine.initialise()
     store = FileBinariesStore(engine)
     self.assertEqual(store.storage_engine, engine)