Ejemplo n.º 1
0
    def test_name_as_publisher_instance(self):
        pub = Publisher('clone me?')
        clone = Publisher(pub)

        self.assertEqual(pub.name, clone.name)
        self.assertEqual(pub.id, clone.id)
        self.assertIsNot(pub, clone)
Ejemplo n.º 2
0
    def test_unsubscribe_with_publisher(self):
        event = Event('unsubscribe nuke')

        # noinspection PyShadowingNames,PyUnusedLocal
        @event.subscribe(Publisher('nuke'))
        async def i_feel_no_regret(message, publisher, event):
            return ['received', publisher, event]

        self.assertEqual(len(event.pub_sub), 1)

        event.unsubscribe(i_feel_no_regret, Publisher('nuke'))
        self.assertEqual(len(event.pub_sub), 0)
Ejemplo n.º 3
0
    def test_standalone_decorator_with_set_publisher(self):
        event = Event('sub to specific publisher')
        self.assertEqual(len(event.pub_sub), 0)

        @event.subscribe(publisher='specific')
        async def nice_handler():
            return 'nice_handler'

        self.assertEqual(len(event.pub_sub), 1)
        self.assertEqual(event.pub_sub[0].publisher, 'specific')
        self.assertEqual(event.pub_sub[0].publisher, Publisher('specific'))
        self.assertIs(event.pub_sub[0].subscriber, nice_handler)
Ejemplo n.º 4
0
    def test_publish_to_all_but_specific(self):
        event = Event('publish to all but omit')

        # noinspection PyShadowingNames,PyUnusedLocal
        @event.subscribe(publisher=Publisher('omit'))
        async def first_sp(message, publisher, event):
            return ['omitted', publisher, event]

        # noinspection PyShadowingNames,PyUnusedLocal
        @event.subscribe()
        async def second_sp(message, publisher, event):
            return ['received', publisher, event]

        with Loop(event.publish('secret message',
                                Publisher('broadcast'))) as loop:
            result = loop.run_until_complete()

        self.assertEqual(len(result), 1)
        result = result.pop()
        self.assertEqual(result[0], 'received')
        self.assertEqual(result[1], Publisher('broadcast'))
        self.assertEqual(result[2], 'publish to all but omit')
Ejemplo n.º 5
0
 def test_comparison_not_equal(self):
     self.assertNotEqual(Publisher('None'), None)
     self.assertNotEqual(Publisher('123'), 123)
     self.assertNotEqual(Publisher('\'{"dict": true\'}'), {'dict': True})
Ejemplo n.º 6
0
 def test_comparison_the_same(self):
     self.assertEqual(Publisher('one another'), Publisher('one another'))
     self.assertEqual(Publisher('one another'), 'one another')
Ejemplo n.º 7
0
 def test_comparison_difference(self):
     self.assertNotEqual(Publisher('first'), Publisher('second'))
     self.assertNotEqual(Publisher('first'), 'second')
     self.assertIsNot(Publisher('first'), Publisher('first'))
Ejemplo n.º 8
0
 def test_identification(self):
     pub = Publisher('broadcaster')
     expected_id = "<class 'eeee.event.Publisher'>broadcaster</class>"
     self.assertEqual(pub.id, expected_id)
Ejemplo n.º 9
0
 def test_raise_eeee_exception(self):
     with self.assertRaises(exceptions.EeeeException):
         Publisher({'wrong name'})
Ejemplo n.º 10
0
 def test_raise_type_error(self):
     with self.assertRaises(exceptions.EeeeTypeError):
         Publisher({'wrong name'})
Ejemplo n.º 11
0
 def test_raise_naming_error(self):
     with self.assertRaises(exceptions.NamingError):
         Publisher(['wrong name'])
Ejemplo n.º 12
0
 def test_name_as_string(self):
     pub = Publisher('test name')
     self.assertEqual(pub.name, 'test name')