Example #1
0
    def test_callable_is_not_callable(self):
        """testing if the callable is not a callable will raise a TypeError
        """
        with self.assertRaises(TypeError) as cm:
            not_a_callable = 'this is not callable'
            register_publisher(not_a_callable, 'Test')

        self.assertEqual('str is not callable', str(cm.exception))
Example #2
0
    def test_callable_is_not_callable(self):
        """testing if the callable is not a callable will raise a TypeError
        """
        with self.assertRaises(TypeError) as cm:
            not_a_callable = 'this is not callable'
            register_publisher(not_a_callable, 'Test')

        self.assertEqual('str is not callable', str(cm.exception))
Example #3
0
    def test_registering_a_post_publisher(self):
        """testing if registering a post publisher is working properly
        """
        self.assertEqual(publishers, {PRE_PUBLISHER_TYPE: {},
                                      POST_PUBLISHER_TYPE: {}})

        def some_callable():
            pass

        register_publisher(some_callable, 'Test', POST_PUBLISHER_TYPE)

        self.assertTrue('test' in publishers[POST_PUBLISHER_TYPE])
        self.assertTrue(
            isinstance(publishers[POST_PUBLISHER_TYPE]['test'], list)
        )
        self.assertTrue(publishers[POST_PUBLISHER_TYPE]['test'][0],
                        some_callable)
Example #4
0
    def test_registering_a_post_publisher(self):
        """testing if registering a post publisher is working properly
        """
        self.assertEqual(publishers, {
            PRE_PUBLISHER_TYPE: {},
            POST_PUBLISHER_TYPE: {}
        })

        def some_callable():
            pass

        register_publisher(some_callable, 'Test', POST_PUBLISHER_TYPE)

        self.assertTrue('test' in publishers[POST_PUBLISHER_TYPE])
        self.assertTrue(
            isinstance(publishers[POST_PUBLISHER_TYPE]['test'], list))
        self.assertTrue(publishers[POST_PUBLISHER_TYPE]['test'][0],
                        some_callable)
Example #5
0
    def test_registering_a_callable_multiple_times(self):
        """testing if registering a callable multiple times will not call the
        function more than 1 time
        """
        called = []

        @publisher('Test')
        def func1():
            called.append('func1')

        @publisher('Test')
        def func2():
            called.append('func2')

        @publisher('Test2')
        def func3():
            """another publisher for some other type
            """
            called.append('func3')

        @publisher
        def func4():
            """this should run for everything
            """
            called.append('func4')

        # be sure that the called is still empty
        self.assertEqual(called, [])

        # register fun1 and func2 more than one times
        register_publisher(func1, 'Test')
        register_publisher(func2, 'Test')
        register_publisher(func1, 'Test')
        register_publisher(func2, 'Test')

        # now run all publishers
        run_publishers('Test')
        self.assertEqual(called, ['func4', 'func1', 'func2'])
Example #6
0
    def test_registering_a_callable_multiple_times(self):
        """testing if registering a callable multiple times will not call the
        function more than 1 time
        """
        called = []

        @publisher('Test')
        def func1():
            called.append('func1')

        @publisher('Test')
        def func2():
            called.append('func2')

        @publisher('Test2')
        def func3():
            """another publisher for some other type
            """
            called.append('func3')

        @publisher
        def func4():
            """this should run for everything
            """
            called.append('func4')

        # be sure that the called is still empty
        self.assertEqual(called, [])

        # register fun1 and func2 more than one times
        register_publisher(func1, 'Test')
        register_publisher(func2, 'Test')
        register_publisher(func1, 'Test')
        register_publisher(func2, 'Test')

        # now run all publishers
        run_publishers('Test')
        self.assertEqual(called, ['func4', 'func1', 'func2'])