This file is indexed.

/usr/lib/python2.7/dist-packages/stevedore/tests/test_dispatch.py is in python-stevedore 1:1.28.0-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
#  Licensed under the Apache License, Version 2.0 (the "License"); you may
#  not use this file except in compliance with the License. You may obtain
#  a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#  License for the specific language governing permissions and limitations
#  under the License.

from stevedore.tests import utils
from stevedore import dispatch


def check_dispatch(ep, *args, **kwds):
    return ep.name == 't2'


class TestDispatch(utils.TestCase):
    def check_dispatch(ep, *args, **kwds):
        return ep.name == 't2'

    def test_dispatch(self):

        def invoke(ep, *args, **kwds):
            return (ep.name, args, kwds)

        em = dispatch.DispatchExtensionManager('stevedore.test.extension',
                                               lambda *args, **kwds: True,
                                               invoke_on_load=True,
                                               invoke_args=('a',),
                                               invoke_kwds={'b': 'B'},
                                               )
        self.assertEqual(len(em.extensions), 2)
        self.assertEqual(set(em.names()), set(['t1', 't2']))

        results = em.map(check_dispatch,
                         invoke,
                         'first',
                         named='named value',
                         )
        expected = [('t2', ('first',), {'named': 'named value'})]
        self.assertEqual(results, expected)

    def test_dispatch_map_method(self):
        em = dispatch.DispatchExtensionManager('stevedore.test.extension',
                                               lambda *args, **kwds: True,
                                               invoke_on_load=True,
                                               invoke_args=('a',),
                                               invoke_kwds={'b': 'B'},
                                               )

        results = em.map_method(check_dispatch, 'get_args_and_data', 'first')
        self.assertEqual(results, [(('a',), {'b': 'B'}, 'first')])

    def test_name_dispatch(self):

        def invoke(ep, *args, **kwds):
            return (ep.name, args, kwds)

        em = dispatch.NameDispatchExtensionManager('stevedore.test.extension',
                                                   lambda *args, **kwds: True,
                                                   invoke_on_load=True,
                                                   invoke_args=('a',),
                                                   invoke_kwds={'b': 'B'},
                                                   )
        self.assertEqual(len(em.extensions), 2)
        self.assertEqual(set(em.names()), set(['t1', 't2']))

        results = em.map(['t2'], invoke, 'first', named='named value',)
        expected = [('t2', ('first',), {'named': 'named value'})]
        self.assertEqual(results, expected)

    def test_name_dispatch_ignore_missing(self):

        def invoke(ep, *args, **kwds):
            return (ep.name, args, kwds)

        em = dispatch.NameDispatchExtensionManager(
            'stevedore.test.extension',
            lambda *args, **kwds: True,
            invoke_on_load=True,
            invoke_args=('a',),
            invoke_kwds={'b': 'B'},
        )

        results = em.map(['t3', 't1'], invoke, 'first', named='named value',)
        expected = [('t1', ('first',), {'named': 'named value'})]
        self.assertEqual(results, expected)

    def test_name_dispatch_map_method(self):
        em = dispatch.NameDispatchExtensionManager(
            'stevedore.test.extension',
            lambda *args, **kwds: True,
            invoke_on_load=True,
            invoke_args=('a',),
            invoke_kwds={'b': 'B'},
        )

        results = em.map_method(['t3', 't1'], 'get_args_and_data', 'first')
        self.assertEqual(results, [(('a',), {'b': 'B'}, 'first')])