2016-07-16 20:33:32 +00:00
|
|
|
from __future__ import absolute_import, unicode_literals
|
|
|
|
|
2016-08-22 18:17:59 +00:00
|
|
|
from case import Mock, mock, patch
|
2016-07-16 20:33:32 +00:00
|
|
|
|
2016-08-22 18:17:59 +00:00
|
|
|
from kombu.utils.compat import entrypoints, maybe_fileno
|
2016-07-16 20:33:32 +00:00
|
|
|
|
|
|
|
|
2016-08-22 18:17:59 +00:00
|
|
|
class test_entrypoints:
|
2016-07-16 20:33:32 +00:00
|
|
|
|
|
|
|
@mock.mask_modules('pkg_resources')
|
|
|
|
def test_without_pkg_resources(self):
|
2016-08-22 18:17:59 +00:00
|
|
|
assert list(entrypoints('kombu.test')) == []
|
2016-07-16 20:33:32 +00:00
|
|
|
|
|
|
|
@mock.module_exists('pkg_resources')
|
|
|
|
def test_with_pkg_resources(self):
|
|
|
|
with patch('pkg_resources.iter_entry_points', create=True) as iterep:
|
|
|
|
eps = iterep.return_value = [Mock(), Mock()]
|
|
|
|
|
2016-08-22 18:17:59 +00:00
|
|
|
assert list(entrypoints('kombu.test'))
|
2016-07-16 20:33:32 +00:00
|
|
|
iterep.assert_called_with('kombu.test')
|
|
|
|
eps[0].load.assert_called_with()
|
|
|
|
eps[1].load.assert_called_with()
|
|
|
|
|
|
|
|
|
2016-08-22 18:17:59 +00:00
|
|
|
def test_maybe_fileno():
|
|
|
|
assert maybe_fileno(3) == 3
|
|
|
|
f = Mock(name='file')
|
|
|
|
assert maybe_fileno(f) is f.fileno()
|
|
|
|
f.fileno.side_effect = ValueError()
|
|
|
|
assert maybe_fileno(f) is None
|