Пример #1
0
    def test_load(self):
        storage_factory = StorageFactory()

        file_store_config = FileStorageConfiguration()
        file_store_config._person2_storage = FileStoreConfiguration(
            file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep +
            "person2.txt",
            fileformat="text",
            extension="txt",
            encoding="utf-8",
            delete_on_start=False)

        storage_engine = FileStorageEngine(file_store_config)

        storage_factory._storage_engines[
            StorageFactory.PERSON2] = storage_engine
        storage_factory._store_to_engine_map[
            StorageFactory.PERSON2] = storage_engine

        collection = Person2Collection()
        self.assertIsNotNone(collection)

        self.assertTrue(collection.load(storage_factory))

        self.assertEqual(collection.personalise_string("I was"),
                         "he or she was")
        self.assertEqual(
            collection.personalise_string("hello he was over there"),
            "hello i was over there")

        self.assertEquals([
            re.compile('(^I WAS | I WAS | I WAS$)', re.IGNORECASE),
            ' HE OR SHE WAS '
        ], collection.person(" I WAS "))
        self.assertEquals(None, collection.person(" I XXX "))
    def test_load_jp(self):
        storage_factory = StorageFactory()
        tokenizer = TokenizerJP()

        file_store_config = FileStorageConfiguration()
        file_store_config._denormal_storage = FileStoreConfiguration(
            file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep +
            "denormal_jp.txt",
            format="text",
            extension="txt",
            encoding="utf-8",
            delete_on_start=False)

        storage_engine = FileStorageEngine(file_store_config)

        storage_factory._storage_engines[
            StorageFactory.DENORMAL] = storage_engine
        storage_factory._store_to_engine_map[
            StorageFactory.DENORMAL] = storage_engine

        collection = DenormalCollection()
        self.assertIsNotNone(collection)

        collection.load(storage_factory)

        self.assertEqual(collection.denormalise_string(tokenizer, "丸1の回答"),
                         "①の回答")
        self.assertIsNone(collection.denormalise("丸"))
Пример #3
0
    def test_message_ids_save_load(self):
        arguments = MockArgumentParser()
        client = MockTwitterBotClient(arguments)
        self.assertIsNotNone(client)
        self.assertTrue(client.connect())

        #TODO this writes to local storage rather than /tmp
        file_store_config = FileStorageConfiguration()
        file_store_config._twitter_storage = FileStoreConfiguration(
            file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep +
            "gender.txt",
            fileformat="text",
            extension="txt",
            encoding="utf-8",
            delete_on_start=False)

        storage_engine = FileStorageEngine(file_store_config)

        client.storage_factory._storage_engines[
            StorageFactory.TWITTER] = storage_engine
        client.storage_factory._store_to_engine_map[
            StorageFactory.TWITTER] = storage_engine

        client._store_last_message_ids('666', '667')

        ids = client._get_last_message_ids()
        self.assertEqual(ids[0], '666')
        self.assertEqual(ids[1], '667')
Пример #4
0
    def test_reload(self):
        storage_factory = StorageFactory()

        file_store_config = FileStorageConfiguration()
        file_store_config._gender_storage = FileStoreConfiguration(
            file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep +
            "gender.txt",
            format="text",
            extension="txt",
            encoding="utf-8",
            delete_on_start=False)

        storage_engine = FileStorageEngine(file_store_config)

        storage_factory._storage_engines[
            StorageFactory.GENDER] = storage_engine
        storage_factory._store_to_engine_map[
            StorageFactory.GENDER] = storage_engine

        collection = GenderCollection()
        self.assertIsNotNone(collection)

        collection.load(storage_factory)

        self.assertEqual(collection.gender("WITH HIM"), 'with her')
        self.assertEqual(collection.genderise_string(None, "This is with him"),
                         "This is with her")

        collection.reload(storage_factory)

        self.assertEqual(collection.gender("WITH HIM"), 'with her')
        self.assertEqual(collection.genderise_string(None, "This is with him"),
                         "This is with her")
Пример #5
0
    def test_reload_jp(self):
        storage_factory = StorageFactory()
        tokenizer = TokenizerJP()

        file_store_config = FileStorageConfiguration()
        file_store_config._gender_storage = FileStoreConfiguration(
            file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep +
            "gender_jp.txt",
            format="text",
            extension="txt",
            encoding="utf-8",
            delete_on_start=False)

        storage_engine = FileStorageEngine(file_store_config)

        storage_factory._storage_engines[
            StorageFactory.GENDER] = storage_engine
        storage_factory._store_to_engine_map[
            StorageFactory.GENDER] = storage_engine

        collection = GenderCollection()
        self.assertIsNotNone(collection)

        collection.load(storage_factory)

        self.assertEqual(collection.gender("彼"), '彼女')
        self.assertEqual(collection.genderise_string(tokenizer, "彼が来た"),
                         "彼女が来た")

        collection.reload(storage_factory)

        self.assertEqual(collection.gender("彼"), '彼女')
        self.assertEqual(collection.genderise_string(tokenizer, "彼が来た"),
                         "彼女が来た")
Пример #6
0
    def test_load_jp(self):
        storage_factory = StorageFactory()
        tokenizer = TokenizerJP()

        file_store_config = FileStorageConfiguration()
        file_store_config._person_storage = FileStoreConfiguration(
            file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep +
            "person_jp.txt",
            format="text",
            extension="txt",
            encoding="utf-8",
            delete_on_start=False)

        storage_engine = FileStorageEngine(file_store_config)

        storage_factory._storage_engines[
            StorageFactory.PERSON] = storage_engine
        storage_factory._store_to_engine_map[
            StorageFactory.PERSON] = storage_engine

        collection = PersonCollection()
        self.assertIsNotNone(collection)

        collection.load(storage_factory)

        self.assertEqual(collection.personalise_string(tokenizer, "私が正しい"),
                         "貴方が正しい")
        self.assertEqual(collection.personalise_string(tokenizer, "あなたは変"),
                         "わたしは変")
Пример #7
0
    def test_load(self):
        storage_factory = StorageFactory()

        file_store_config = FileStorageConfiguration()
        file_store_config._person_storage = FileStoreConfiguration(
            file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep +
            "person.txt",
            format="text",
            extension="txt",
            encoding="utf-8",
            delete_on_start=False)

        storage_engine = FileStorageEngine(file_store_config)

        storage_factory._storage_engines[
            StorageFactory.PERSON] = storage_engine
        storage_factory._store_to_engine_map[
            StorageFactory.PERSON] = storage_engine

        collection = PersonCollection()
        self.assertIsNotNone(collection)

        collection.load(storage_factory)

        self.assertEqual(collection.personalise_string(None, "with me"),
                         "with you2")
        self.assertEqual(
            collection.personalise_string(None, "Hello are you with me"),
            "Hello am I2 with you2")
Пример #8
0
    def test_load_from_file(self):
        storage_factory = StorageFactory()

        file_store_config = FileStorageConfiguration()
        file_store_config._sets_storage = FileStoreConfiguration(dirs=[
            os.path.dirname(__file__) + os.sep + "test_files" + os.sep + "sets"
        ])
        storage_engine = FileStorageEngine(file_store_config)

        storage_factory._storage_engines[StorageFactory.SETS] = storage_engine
        storage_factory._store_to_engine_map[
            StorageFactory.SETS] = storage_engine

        collection = SetCollection()
        self.assertIsNotNone(collection)

        self.assertTrue(collection.load(storage_factory) > 0)

        self.assertIsNotNone(collection._sets)
        self.assertEqual(len(collection._sets), 1)

        self.assertIsNotNone(collection._stores)
        self.assertEqual(len(collection._stores), 1)

        self.assertTrue("TEST_SET" in collection._sets)
        self.assertTrue("TEST_SET" in collection._stores)

        self.assertTrue(collection.contains('TEST_SET'))

        aset = collection.set('TEST_SET')
        self.assertIsNotNone(aset)
        values = aset['AIR']
        self.assertIsNotNone(values)
        self.assertTrue(['Air', 'Force', 'blue'] in values)
Пример #9
0
    def test_reload(self):
        storage_factory = StorageFactory()

        file_store_config = FileStorageConfiguration()
        file_store_config._denormal_storage = FileStoreConfiguration(
            file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep +
            "denormal.txt",
            format="text",
            extension="txt",
            encoding="utf-8",
            delete_on_start=False)

        storage_engine = FileStorageEngine(file_store_config)

        storage_factory._storage_engines[
            StorageFactory.DENORMAL] = storage_engine
        storage_factory._store_to_engine_map[
            StorageFactory.DENORMAL] = storage_engine

        collection = DenormalCollection()
        self.assertIsNotNone(collection)

        collection.load(storage_factory)

        collection.reload(storage_factory)
Пример #10
0
    def test_load_from_test_dir_with_subdir(self):
        config = FileStorageConfiguration()
        config._maps_storage = FileStoreConfiguration(dirs=[
            os.path.dirname(__file__) + os.sep + "data" + os.sep + "maps" +
            os.sep + "text"
        ],
                                                      extension="txt",
                                                      subdirs=True,
                                                      format="text",
                                                      encoding="utf-8",
                                                      delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileMapsStore(engine)

        map_collection = MapCollection()
        store.load_all(map_collection)

        self.assertTrue(map_collection.contains('TESTMAP'))
        the_map = map_collection.map('TESTMAP')
        self.assertIsNotNone(the_map)
        self.assertEqual("6", the_map['ANT'])

        self.assertTrue(map_collection.contains('TESTMAP2'))
        the_map = map_collection.map('TESTMAP2')
        self.assertIsNotNone(the_map)
        self.assertEqual("grrrrr", the_map['BEAR'])
Пример #11
0
    def test_load_from_file(self):
        storage_factory = StorageFactory()

        file_store_config = FileStorageConfiguration()
        file_store_config._properties_storage = FileStoreConfiguration(
            file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep +
            "properties.txt",
            format="text",
            extension="txt",
            encoding="utf-8",
            delete_on_start=False)

        storage_engine = FileStorageEngine(file_store_config)

        storage_factory._storage_engines[
            StorageFactory.PROPERTIES] = storage_engine
        storage_factory._store_to_engine_map[
            StorageFactory.PROPERTIES] = storage_engine

        collection = PropertiesCollection()
        self.assertIsNotNone(collection)

        collection.load(storage_factory)

        self.assertTrue(collection.has_property("name"))
        self.assertFalse(collection.has_property("age"))

        self.assertEqual("KeiffBot 1.0", collection.property("name"))
        self.assertIsNone(collection.property("age"))
Пример #12
0
    def test_reload_from_file(self):
        config = FileStorageConfiguration()
        config._rdf_storage = FileStoreConfiguration(dirs=[
            os.path.dirname(__file__) + os.sep + "test_files" + os.sep + "rdfs"
        ])

        factory = StorageFactory()

        storage_engine = FileStorageEngine(config)

        factory._storage_engines[StorageFactory.RDF] = storage_engine
        factory._store_to_engine_map[StorageFactory.RDF] = storage_engine

        storage_engine.initialise()

        collection = RDFCollection()
        self.assertIsNotNone(collection)

        collection.load(factory)

        self.assertTrue(collection.has_subject("TEST1"))
        self.assertTrue(collection.has_predicate("TEST1", "HASPURPOSE"))
        self.assertTrue(collection.has_object("TEST1", "HASPURPOSE",
                                              "to test"))

        collection.delete_entity("TEST1", "HASPURPOSE", "to test")
        self.assertFalse(
            collection.has_object("TEST1", "HASPURPOSE", "to test"))

        collection.reload(factory, "TESTDATA")

        self.assertTrue(collection.has_subject("TEST1"))
        self.assertTrue(collection.has_predicate("TEST1", "HASPURPOSE"))
        self.assertTrue(collection.has_object("TEST1", "HASPURPOSE",
                                              "to test"))
Пример #13
0
    def test_load_from_test_dir_with_subdir(self):
        config = FileStorageConfiguration()
        config._sets_storage = FileStoreConfiguration(dirs=[
            os.path.dirname(__file__) + os.sep + "data" + os.sep + "sets" +
            os.sep + "text"
        ],
                                                      extension="txt",
                                                      subdirs=True,
                                                      format="text",
                                                      encoding="utf-8",
                                                      delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileSetsStore(engine)

        set_collection = SetCollection()
        store.load_all(set_collection)

        self.assertTrue(set_collection.contains('TESTSET'))
        values = set_collection.set_list('TESTSET')
        self.assertTrue('VAL1' in values)
        self.assertTrue('VAL2' in values)
        self.assertTrue('VAL3' in values)
        self.assertTrue('VAL4' in values)

        self.assertTrue(set_collection.contains('TESTSET2'))
        values = set_collection.set_list('TESTSET2')
        self.assertEqual(4, len(values))
        self.assertTrue('VAL5' in values)
        self.assertTrue('VAL6' in values)
        self.assertTrue('VAL7' in values)
        self.assertTrue('VAL8' in values)
Пример #14
0
    def test_apply_updates(self):
        config = FileStorageConfiguration()
        config._rdf_storage = FileStoreConfiguration(dirs=[
            os.path.dirname(__file__) + os.sep + "test_files" + os.sep + "rdfs"
        ])
        tmpdir = os.path.dirname(__file__) + os.sep + "rdf_updates"
        config.rdf_updates_storage._dirs = [tmpdir]
        config.rdf_updates_storage._has_single_file = True

        factory = StorageFactory()

        storage_engine = FileStorageEngine(config)
        factory._storage_engines[StorageFactory.RDF] = storage_engine
        factory._store_to_engine_map[StorageFactory.RDF] = storage_engine
        factory._storage_engines[StorageFactory.RDF_UPDATES] = storage_engine
        factory._store_to_engine_map[
            StorageFactory.RDF_UPDATES] = storage_engine

        storage_engine.initialise()
        updates_engine = factory.entity_storage_engine(
            StorageFactory.RDF_UPDATES)
        updates_store = updates_engine.rdf_updates_store()
        updates_store.empty()

        collection = RDFCollection()
        self.assertIsNotNone(collection)

        collection.load(factory)

        self.assertTrue(collection.has_subject("TEST1"))
        self.assertTrue(collection.has_predicate("TEST1", "HASPURPOSE"))
        self.assertTrue(collection.has_object("TEST1", "HASPURPOSE",
                                              "to test"))

        collection.apply_updates()
Пример #15
0
    def test_load_triggers(self):
        config = TriggerConfiguration()
        config._manager = TriggerConfiguration.LOCAL_MANAGER

        mgr = TriggerManager.load_trigger_manager(config)

        trigger_file = os.path.dirname(__file__) + os.sep + "triggers.txt"
        self.assertTrue(os.path.exists(trigger_file))

        config = FileStorageConfiguration()
        config._triggers_storage = FileStoreConfiguration(file=trigger_file, format="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()

        storage_factory = StorageFactory()

        storage_factory._storage_engines[StorageFactory.TRIGGERS] = engine
        storage_factory._store_to_engine_map[StorageFactory.TRIGGERS] = engine

        mgr.load_triggers(storage_factory)

        triggers = mgr.get_triggers("SYSTEM_STARTUP")
        self.assertIsNotNone(triggers)
        self.assertEquals(2, len(triggers))

        triggers = mgr.get_triggers("SYSTEM_SHUTDOWN")
        self.assertIsNotNone(triggers)
        self.assertEquals(1, len(triggers))

        triggers = mgr.get_triggers("CONVERSATION_START")
        self.assertIsNotNone(triggers)
        self.assertEquals(1, len(triggers))
Пример #16
0
    def test_load(self):
        storage_factory = StorageFactory()

        file_store_config = FileStorageConfiguration()
        file_store_config._person2_storage = FileStoreConfiguration(
            file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep +
            "person2.txt",
            format="text",
            extension="txt",
            encoding="utf-8",
            delete_on_start=False)

        storage_engine = FileStorageEngine(file_store_config)

        storage_factory._storage_engines[
            StorageFactory.PERSON2] = storage_engine
        storage_factory._store_to_engine_map[
            StorageFactory.PERSON2] = storage_engine

        collection = Person2Collection()
        self.assertIsNotNone(collection)

        collection.load(storage_factory)

        self.assertEqual(collection.personalise_string("I was"),
                         "he or she was")
        self.assertEqual(
            collection.personalise_string("hello he was over there"),
            "hello i was over there")
Пример #17
0
    def test_reload(self):
        storage_factory = StorageFactory()

        file_store_config = FileStorageConfiguration()
        file_store_config._normal_storage = FileStoreConfiguration(
            file=os.path.dirname(__file__) + os.sep + "test_files" + os.sep +
            "normal.txt",
            fileformat="text",
            extension="txt",
            encoding="utf-8",
            delete_on_start=False)

        storage_engine = FileStorageEngine(file_store_config)

        storage_factory._storage_engines[
            StorageFactory.NORMAL] = storage_engine
        storage_factory._store_to_engine_map[
            StorageFactory.NORMAL] = storage_engine

        collection = NormalCollection()
        self.assertIsNotNone(collection)

        self.assertTrue(collection.load(storage_factory))

        self.assertEqual(collection.normalise_string("keithsterling.COM"),
                         "keithsterling dot com")

        self.assertTrue(collection.reload(storage_factory))

        self.assertEqual(collection.normalise_string("keithsterling.COM"),
                         "keithsterling dot com")
Пример #18
0
    def test_load_spelling_with_exception(self):
        config = FileStorageConfiguration()
        config._spelling_storage =  FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "spelling" + os.sep + "corpus.txt", fileformat="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileSpellingStore(engine)

        spelling_checker = NorvigSpellingChecker()
        self.assertFalse(store.load_spelling(spelling_checker))
Пример #19
0
    def test_load_spelling(self):
        config = FileStorageConfiguration()
        config._spelling_storage =  FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "spelling" + os.sep + "corpus.txt", fileformat="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileSpellingStore(engine)

        spelling_checker = NorvigSpellingChecker()
        self.assertTrue(store.load_spelling(spelling_checker))

        self.assertEqual("THESE ARE SOME WORDS", spelling_checker.correct("Thise ara sime wards"))
Пример #20
0
    def test_reload_from_file_jp(self):
        storage_factory = StorageFactory()

        file_store_config = FileStorageConfiguration()
        file_store_config._sets_storage = FileStoreConfiguration(dirs=[
            os.path.dirname(__file__) + os.sep + "test_files" + os.sep +
            "sets_jp"
        ])
        storage_engine = FileStorageEngine(file_store_config)

        storage_factory._storage_engines[StorageFactory.SETS] = storage_engine
        storage_factory._store_to_engine_map[
            StorageFactory.SETS] = storage_engine

        collection = SetCollection()
        self.assertIsNotNone(collection)

        collection.load(storage_factory)

        self.assertIsNotNone(collection._sets)
        self.assertEqual(len(collection._sets), 1)

        self.assertIsNotNone(collection._stores)
        self.assertEqual(len(collection._stores), 1)

        self.assertTrue("TEST_SET" in collection._sets)
        self.assertTrue("TEST_SET" in collection._stores)
        self.assertTrue("TEST_SET" in collection._is_cjk)

        self.assertTrue(collection.contains('TEST_SET'))
        self.assertTrue(collection.is_cjk('TEST_SET'))

        aset = collection.set_list('TEST_SET')
        self.assertIsNotNone(aset)
        values = aset['千']
        self.assertIsNotNone(values)
        self.assertEqual(['千葉', '千葉県', '千葉県下'], values)

        collection.reload(storage_factory, "TEST_SET")

        self.assertIsNotNone(collection._sets)
        self.assertEqual(len(collection._sets), 1)

        self.assertIsNotNone(collection._stores)
        self.assertEqual(len(collection._stores), 1)

        self.assertTrue("TEST_SET" in collection._sets)
        self.assertTrue("TEST_SET" in collection._stores)

        self.assertTrue(collection.contains('TEST_SET'))

        values = aset['千']
        self.assertIsNotNone(values)
        self.assertEqual(['千葉', '千葉県', '千葉県下'], values)
Пример #21
0
    def test_load_postprocessors(self):
        config = FileStorageConfiguration()
        config._postquestionprocessors_storage = FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "processors" + os.sep + "postquestionprocessors.conf", fileformat="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FilePostQuestionProcessorsStore(engine)

        collection = ProcessorCollection()
        store.load(collection)

        self.assertEqual(0, len(collection.processors))
Пример #22
0
    def test_load_from_test_dir_no_subdir(self):
        config = FileStorageConfiguration()
        config._rdf_storage = FileStoreConfiguration(dirs=[os.path.dirname(__file__) + os.sep + "data" + os.sep + "rdfs" + os.sep + "text"], extension="rdf", subdirs=False, format="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileRDFStore(engine)

        map_collection = RDFCollection()
        store.load_all(map_collection)

        self.assertTrue(map_collection.contains('ACTIVITY'))
Пример #23
0
    def test_reload_no_engine(self):
        storage_factory = StorageFactory()

        file_store_config = FileStorageConfiguration()
        file_store_config._maps_storage = FileStoreConfiguration(dirs=[
            os.path.dirname(__file__) + os.sep + "test_files" + os.sep + "maps"
        ])
        collection = MapCollection()
        self.assertIsNotNone(collection)

        self.assertTrue(collection.reload(storage_factory, "TEST_MAP") == 0)
Пример #24
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)
Пример #25
0
    def test_load_variables(self):
        config = FileStorageConfiguration()
        config._pattern_nodes_storage = FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "nodes" + os.sep + "pattern_nodes.conf", format="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FilePatternNodeStore(engine)

        collection = PatternNodeFactory()
        store.load(collection)

        self.assertEqual(12, len(collection.nodes))
        self.assertTrue(collection.exists("zeroormore"))
Пример #26
0
    def test_with_files_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        brain:
            files:
                sets:
                    dirs: $BOT_ROOT/sets
                    extension: .txt
                    subdirs: false
                    format: text
                    encoding: utf-8
                    delete_on_start: true
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")
        self.assertIsNotNone(brain_config)
        files_config = yaml.get_section("files", brain_config)
        self.assertIsNotNone(files_config)

        sets_config = FileStoreConfiguration("sets")
        sets_config.load_config_section(yaml, files_config, ".")

        self.assertFalse(sets_config.has_single_file())
        self.assertTrue(sets_config.has_multiple_dirs())

        self.assertEqual(["./sets"], sets_config.dirs)
        self.assertEqual(".txt", sets_config.extension)
        self.assertFalse(sets_config.subdirs)

        self.assertEqual("utf-8", sets_config.encoding)
        self.assertEqual("text", sets_config.format)

        self.assertTrue(sets_config.delete_on_start)
Пример #27
0
    def test_to_yaml_no_defaults(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        brain:
            files:
                sets:
                    dirs: $BOT_ROOT/sets
                    extension: .txt
                    subdirs: false
                    format: text
                    encoding: utf-8
                    delete_on_start: true
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")
        self.assertIsNotNone(brain_config)
        files_config = yaml.get_section("files", brain_config)
        self.assertIsNotNone(files_config)

        sets_config = FileStoreConfiguration("sets")
        sets_config.load_config_section(yaml, files_config, ".")

        data = {}
        sets_config.to_yaml(data, False)
        self.assertTrue(data['delete_on_start'])
        self.assertEqual(data['dirs'], ['./sets'])
        self.assertEqual(data['encoding'], 'utf-8')
        self.assertEqual(data['extension'], '.txt')
        self.assertEqual(data['format'], 'text')
        self.assertFalse(data['subdirs'])
Пример #28
0
    def test_load_from_file(self):
        config = FileStorageConfiguration()
        config._person_storage = FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "lookups" + os.sep + "text" + os.sep + "person.txt", format="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FilePersonStore(engine)

        person_collection = PersonCollection()
        
        store.load(person_collection)

        self.assertEqual(person_collection.person(" WITH YOU "), [re.compile('(^WITH YOU | WITH YOU | WITH YOU$)', re.IGNORECASE), ' WITH ME2 '])
        self.assertEqual(person_collection.personalise_string("Is he with you"), "Is he with me2")
Пример #29
0
    def test_load_from_file(self):
        config = FileStorageConfiguration()
        config._person2_storage = FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "lookups" + os.sep + "text" + os.sep + "person2.txt", fileformat="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FilePerson2Store(engine)

        person2_collection = PersonCollection()
        
        store.load(person2_collection)

        self.assertEqual(person2_collection.person(" I WAS "), [re.compile('(^I WAS | I WAS | I WAS$)', re.IGNORECASE), ' HE OR SHE WAS '])
        self.assertEqual(person2_collection.personalise_string("I was there"), "he or she was there")
Пример #30
0
    def test_load_from_file(self):
        config = FileStorageConfiguration()
        config._gender_storage = FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "lookups" + os.sep + "text" + os.sep + "gender.txt", fileformat="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileGenderStore(engine)

        gender_collection = GenderCollection()
        
        store.load(gender_collection)

        self.assertEqual(gender_collection.gender(" WITH HIM "), [re.compile('(^WITH HIM | WITH HIM | WITH HIM$)', re.IGNORECASE), ' WITH HER '])
        self.assertEqual(gender_collection.genderise_string("This is with him "), "This is with her")