2016-07-16 20:33:32 +00:00
|
|
|
from __future__ import absolute_import, unicode_literals
|
|
|
|
|
2016-08-22 18:17:59 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from case import Mock
|
|
|
|
|
2016-07-16 20:33:32 +00:00
|
|
|
from kombu import Exchange
|
|
|
|
from kombu.utils.imports import symbol_by_name
|
|
|
|
|
|
|
|
|
2016-08-22 18:17:59 +00:00
|
|
|
class test_symbol_by_name:
|
2016-07-16 20:33:32 +00:00
|
|
|
|
|
|
|
def test_instance_returns_instance(self):
|
|
|
|
instance = object()
|
2016-08-22 18:17:59 +00:00
|
|
|
assert symbol_by_name(instance) is instance
|
2016-07-16 20:33:32 +00:00
|
|
|
|
|
|
|
def test_returns_default(self):
|
|
|
|
default = object()
|
2016-08-22 18:17:59 +00:00
|
|
|
assert symbol_by_name(
|
|
|
|
'xyz.ryx.qedoa.weq:foz', default=default) is default
|
2016-07-16 20:33:32 +00:00
|
|
|
|
|
|
|
def test_no_default(self):
|
2016-08-22 18:17:59 +00:00
|
|
|
with pytest.raises(ImportError):
|
2016-07-16 20:33:32 +00:00
|
|
|
symbol_by_name('xyz.ryx.qedoa.weq:foz')
|
|
|
|
|
|
|
|
def test_imp_reraises_ValueError(self):
|
|
|
|
imp = Mock()
|
|
|
|
imp.side_effect = ValueError()
|
2016-08-22 18:17:59 +00:00
|
|
|
with pytest.raises(ValueError):
|
2016-07-16 20:33:32 +00:00
|
|
|
symbol_by_name('kombu.Connection', imp=imp)
|
|
|
|
|
|
|
|
def test_package(self):
|
2016-08-22 18:17:59 +00:00
|
|
|
assert symbol_by_name('.entity:Exchange', package='kombu') is Exchange
|
|
|
|
assert symbol_by_name(':Consumer', package='kombu')
|