test_enabled.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  2. # not use this file except in compliance with the License. You may obtain
  3. # a copy of the License at
  4. #
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. #
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  9. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  10. # License for the specific language governing permissions and limitations
  11. # under the License.
  12. from stevedore import enabled
  13. from stevedore.tests import utils
  14. class TestEnabled(utils.TestCase):
  15. def test_enabled(self):
  16. def check_enabled(ep):
  17. return ep.name == 't2'
  18. em = enabled.EnabledExtensionManager(
  19. 'stevedore.test.extension',
  20. check_enabled,
  21. invoke_on_load=True,
  22. invoke_args=('a',),
  23. invoke_kwds={'b': 'B'},
  24. )
  25. self.assertEqual(len(em.extensions), 1)
  26. self.assertEqual(em.names(), ['t2'])
  27. def test_enabled_after_load(self):
  28. def check_enabled(ext):
  29. return ext.obj and ext.name == 't2'
  30. em = enabled.EnabledExtensionManager(
  31. 'stevedore.test.extension',
  32. check_enabled,
  33. invoke_on_load=True,
  34. invoke_args=('a',),
  35. invoke_kwds={'b': 'B'},
  36. )
  37. self.assertEqual(len(em.extensions), 1)
  38. self.assertEqual(em.names(), ['t2'])