Пример #1
0
    def test_properties_from_text(self):

        properties = PropertiesCollection()
        self.assertIsNotNone(properties)

        properties.load_from_text("""
            url:http://www.keithsterling.com/aiml
            name:KeiffBot 1.0
            firstname:Keiff
            middlename:AIML
            lastname:BoT
            fullname:KeiffBot
            email:[email protected]
            gender:male
            botmaster:Keith Sterling
            organization:keithsterling.com
            version:0.0.1
            birthplace:Edinburgh, Scotland
            job:mobile virtual assistant
            species:robot
            birthday:September 9th
            birthdate:September 9th, 2016
            sign:Virgo
            logo:<img src="http://www.keithsterling.com/aiml/logo.png" width="128"/>
            religion:Atheist
            default-get:unknown
            default-property:unknown
            default-map:unknown
            learn-filename:keiffbot-learn.aiml
        """)

        self.assertEqual(properties.property('url'), "http://www.keithsterling.com/aiml")
        self.assertEqual(properties.property('job'), "mobile virtual assistant")
        self.assertEqual(properties.property('learn-filename'), "keiffbot-learn.aiml")
Пример #2
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"))
Пример #3
0
    def test_load_variables(self):
        config = FileStorageConfiguration()
        config._defaults_storage = FileStoreConfiguration(file=os.path.dirname(__file__) + os.sep + "data" + os.sep + "lookups" + os.sep + "text" + os.sep + "defaults.txt",
                                                          format="text", encoding="utf-8", delete_on_start=False)
        engine = FileStorageEngine(config)
        engine.initialise()
        store = FileDefaultVariablesStore(engine)

        collection = PropertiesCollection()
        store.load(collection)

        self.assertTrue(collection.has_property("var1"))
        self.assertTrue("val1", collection.property("var1"))
        self.assertTrue(collection.has_property("var2"))
        self.assertTrue("val2", collection.property("val2"))
Пример #4
0
    def test_properties_operations(self):
        collection = PropertiesCollection()
        self.assertIsNotNone(collection)

        collection.add_property("name", "KeiffBot 1.0")
        collection.add_property("firstname", "Keiff")
        collection.add_property("middlename", "AIML")
        collection.add_property("lastname", "BoT")
        collection.add_property("fullname", "KeiffBot")

        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"))
Пример #5
0
    def test_properties_from_text(self):

        properties = PropertiesCollection()
        self.assertIsNotNone(properties)

        properties.load_from_text("""
            url:http://www.keithsterling.com/aiml
            name:KeiffBot 1.0
            firstname:Keiff
            middlename:AIML
            lastname:BoT
            fullname:KeiffBot
            email:[email protected]
            gender:male
            botmaster:Keith Sterling
            organization:keithsterling.com
            version:0.0.1
            birthplace:Edinburgh, Scotland
            job:mobile virtual assistant
            species:robot
            birthday:September 9th
            birthdate:September 9th, 2016
            sign:Virgo
            logo:<img src="http://www.keithsterling.com/aiml/logo.png" width="128"/>
            religion:Atheist
            default-get:unknown
            default-property:unknown
            default-map:unknown
            learn-filename:keiffbot-learn.aiml
        """)

        self.assertEqual(properties.property('url'),
                         "http://www.keithsterling.com/aiml")
        self.assertEqual(properties.property('job'),
                         "mobile virtual assistant")
        self.assertEqual(properties.property('learn-filename'),
                         "keiffbot-learn.aiml")