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

        logging.info("******** delayed")

        store = MemoryStore()

        class MyBot(FakeBot):

            def say(self, message):
                self.engine.set('said', message)

        self.bot = MyBot(engine=self.engine, store=store)
        self.bot.subscriber = self.engine.bus.subscribe('*id')
        self.bot.publisher = self.engine.publisher

        machine = Input(bot=self.bot,
                        question="What's up, Doc?",
                        key='my.input')

        machine.RETRY_DELAY = 0.01
        p = machine.start(tick=0.001)

        time.sleep(0.03)
        self.bot.fan.put('here we go')
        p.join()

        self.assertEqual(self.bot.recall('input'), {u'my.input': u'here we go'})
        self.assertEqual(self.engine.get('said'), machine.ANSWER_MESSAGE)
Пример #2
0
    def test_cycle(self):

        logging.info("******** life cycle")

        store = MemoryStore()

        class MyBot(FakeBot):

            def say(self, message):
                self.engine.set('said', message)

        self.bot = MyBot(engine=self.engine, store=store)
        self.bot.subscriber = self.engine.bus.subscribe('*id')
        self.bot.publisher = self.engine.publisher

        class MyInput(Input):

            def on_input(self, value):
                assert value == 'here we go'

        machine = MyInput(bot=self.bot,
                        question="What's up, Doc?",
                        key='my.input')

        p = machine.start(tick=0.001)

        time.sleep(0.01)
        self.bot.fan.put('here we go')
        p.join()

        self.assertEqual(machine.get('answer'), 'here we go')
        self.assertEqual(self.bot.recall('input'), {u'my.input': u'here we go'})

        self.assertEqual(self.engine.get('said'), machine.ANSWER_MESSAGE)
Пример #3
0
 def setUp(self):
     self.context = Context()
     self.engine = Engine(context=self.context, mouth=Queue())
     self.space = LocalSpace(context=self.context, ears=self.engine.ears)
     self.store = MemoryStore(context=self.context)
     self.machine = MyMachine()
     self.bot = MyBot(engine=self.engine)
     self.bot.machine = None
Пример #4
0
 def setUp(self):
     self.context = Context()
     self.engine = Engine(context=self.context, ears=Queue(), mouth=Queue())
     self.engine.bus = Bus(self.context)
     self.engine.bus.check()
     self.engine.publisher = self.engine.bus.publish()
     self.space = LocalSpace(context=self.context, ears=self.engine.ears)
     self.store = MemoryStore(context=self.context)
     self.bot = ShellBot(engine=self.engine,
                         space=self.space,
                         store=self.store)
     self.channel = Channel({'id': '*id', 'title': '*title'})
Пример #5
0
    def test__clear(self):

        logging.info('***** _clear')

        store = MemoryStore()

        # set the key and then forget it
        store._set('hello', 'world')
        self.assertEqual(store._get('hello'), 'world')
        store._clear('hello')
        self.assertEqual(store._get('hello'), None)

        # set multiple keys and then forget all of them
        store._set('hello', 'world')
        store._set('bunny', "What'up, Doc?")
        self.assertEqual(store._get('hello'), 'world')
        self.assertEqual(store._get('bunny'), "What'up, Doc?")
        store._clear(key=None)
        self.assertEqual(store._get('hello'), None)
        self.assertEqual(store._get('bunny'), None)
Пример #6
0
    def test__get(self):

        logging.info('***** _get')

        store = MemoryStore()

        # undefined key
        self.assertEqual(store._get('hello'), None)

        # undefined key with default value
        whatever = 'whatever'
        self.assertEqual(store.recall('hello', whatever), whatever)

        # set the key
        store._set('hello', 'world')
        self.assertEqual(store._get('hello'), 'world')

        # default value is meaningless when key has been set
        store.remember('hello', 'world')
        self.assertEqual(store.recall('hello', 'whatever'), 'world')

        # except when set to None
        store._set('special', None)
        self.assertEqual(store._get('special'), None)
        self.assertEqual(store.recall('special', []), [])
Пример #7
0
    def test__set(self):

        logging.info('***** _set')

        store = MemoryStore()

        self.assertEqual(store._get('sca.lar'), None)
        store._set('sca.lar', 'test')
        self.assertEqual(store._get('sca.lar'), 'test')

        self.assertEqual(store._get('list'), None)
        store._set('list', ['hello', 'world'])
        self.assertEqual(store._get('list'), ['hello', 'world'])

        self.assertEqual(store._get('dict'), None)
        store._set('dict', {'hello': 'world'})
        self.assertEqual(store._get('dict'), {'hello': 'world'})
Пример #8
0
    def test_init(self):

        logging.info('***** init')

        store = MemoryStore()
        self.assertEqual(str(store.values), "{}")
Пример #9
0
    def test_unicode(self):

        logging.info('***** unicode')

        store = MemoryStore()

        store._set('hello', 'world')
        self.assertEqual(store._get('hello'), 'world')
        self.assertEqual(store._get(u'hello'), 'world')

        store._set('hello', u'wôrld')
        self.assertEqual(store._get('hello'), u'wôrld')

        store._set(u'hello', u'wôrld')
        self.assertEqual(store._get(u'hello'), u'wôrld')
Пример #10
0
    def setUp(self):
        self.engine = Engine()
        self.store = MemoryStore()
        self.bot = ShellBot(engine=self.engine, store=self.store)

        self.raw_steps = [
            {
                'label':
                u'Level 1',
                'message':
                u'Initial capture of information',
                'content':
                u'**Initial** `capture` of _information_',
                'file':
                "https://upload.wikimedia.org/wikipedia/en/c/c6/Bat-signal_1989_film.jpg",
            },
            {
                'label': u'Level 2',
                'message': u'Escalation to technical experts',
                'participants': '*****@*****.**',
            },
            {
                'label': u'Level 3',
                'message': u'Escalation to decision stakeholders',
                'participants': '*****@*****.**',
            },
            {
                'label': u'Terminated',
                'message': u'Process is closed, yet conversation can continue',
            },
        ]

        self.steps = [
            Step(
                {
                    'label':
                    u'Level 1',
                    'message':
                    u'Initial capture of information',
                    'content':
                    u'**Initial** `capture` of _information_',
                    'file':
                    "https://upload.wikimedia.org/wikipedia/en/c/c6/Bat-signal_1989_film.jpg",
                }, 1),
            Step(
                {
                    'label': u'Level 2',
                    'message': u'Escalation to technical experts',
                    'participants': '*****@*****.**',
                    'machine': FakeMachine(running=False),
                }, 2),
            Step(
                {
                    'label': u'Level 3',
                    'message': u'Escalation to decision stakeholders',
                    'participants': '*****@*****.**',
                    'machine': FakeMachine(running=False),
                }, 3),
            Step(
                {
                    'label': u'Terminated',
                    'message':
                    u'Process is closed, yet conversation can continue',
                    'machine': FakeMachine(running=False),
                }, 4),
        ]

        self.running_steps = [
            Step(
                {
                    'label':
                    u'Level 1',
                    'message':
                    u'Initial capture of information',
                    'content':
                    u'**Initial** `capture` of _information_',
                    'file':
                    "https://upload.wikimedia.org/wikipedia/en/c/c6/Bat-signal_1989_film.jpg",
                }, 1),
            Step(
                {
                    'label': u'Level 2',
                    'message': u'Escalation to technical experts',
                    'participants': '*****@*****.**',
                    'machine': FakeMachine(running=True),
                }, 2),
            Step(
                {
                    'label': u'Level 3',
                    'message': u'Escalation to decision stakeholders',
                    'participants': '*****@*****.**',
                    'machine': FakeMachine(running=True),
                }, 3),
            Step(
                {
                    'label': u'Terminated',
                    'message':
                    u'Process is closed, yet conversation can continue',
                    'machine': FakeMachine(running=True),
                }, 4),
        ]
Пример #11
0
 def setUp(self):
     self.context = Context()
     self.engine = Engine(context=self.context, mouth=Queue())
     self.store = MemoryStore(context=self.context)
     self.bot = Bot(engine=self.engine)