python-dependency-injector/tests/unit/providers/test_utils_py2_py3.py
Roman Mogylatov 9a785de4b5
Coroutine provider (#206)
* Add coroutine provider examples

* Add coroutine provier

* Update changelog

* Update static analysis travis jobs to python 3.7

* Update coroutine provider implementation for python 3.4

* Update static analysis travis jobs to python 3.6

* Make pycode style happy

* Add tests for coroutine providers

* Make coroutine tests python 2 syntax friendly

* Split tests to python2 and python3

* Refactor coroutine provider tests

* Modify pypy tests running command

* Update coroutine provider docs
2018-10-18 19:39:19 +03:00

57 lines
1.6 KiB
Python

"""Dependency injector provider utils unit tests."""
import unittest2 as unittest
from dependency_injector import (
providers,
errors,
)
class IsProviderTests(unittest.TestCase):
def test_with_instance(self):
self.assertTrue(providers.is_provider(providers.Provider()))
def test_with_class(self):
self.assertFalse(providers.is_provider(providers.Provider))
def test_with_string(self):
self.assertFalse(providers.is_provider('some_string'))
def test_with_object(self):
self.assertFalse(providers.is_provider(object()))
def test_with_subclass_instance(self):
class SomeProvider(providers.Provider):
pass
self.assertTrue(providers.is_provider(SomeProvider()))
def test_with_class_with_getattr(self):
class SomeClass(object):
def __getattr__(self, _):
return False
self.assertFalse(providers.is_provider(SomeClass()))
class EnsureIsProviderTests(unittest.TestCase):
def test_with_instance(self):
provider = providers.Provider()
self.assertIs(providers.ensure_is_provider(provider), provider)
def test_with_class(self):
self.assertRaises(errors.Error,
providers.ensure_is_provider,
providers.Provider)
def test_with_string(self):
self.assertRaises(errors.Error,
providers.ensure_is_provider,
'some_string')
def test_with_object(self):
self.assertRaises(errors.Error, providers.ensure_is_provider, object())