summaryrefslogtreecommitdiff
path: root/t/unit/utils/test_imports.py
blob: 5dc95b75e6060d24cbcf68374abda52a549e15a6 (plain)
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
import pytest

from unittest.mock import Mock

from kombu import Exchange
from kombu.utils.imports import symbol_by_name


class test_symbol_by_name:

    def test_instance_returns_instance(self):
        instance = object()
        assert symbol_by_name(instance) is instance

    def test_returns_default(self):
        default = object()
        assert symbol_by_name(
            'xyz.ryx.qedoa.weq:foz', default=default) is default

    def test_no_default(self):
        with pytest.raises(ImportError):
            symbol_by_name('xyz.ryx.qedoa.weq:foz')

    def test_imp_reraises_ValueError(self):
        imp = Mock()
        imp.side_effect = ValueError()
        with pytest.raises(ValueError):
            symbol_by_name('kombu.Connection', imp=imp)

    def test_package(self):
        assert symbol_by_name('.entity:Exchange', package='kombu') is Exchange
        assert symbol_by_name(':Consumer', package='kombu')