mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-04-14 22:24:25 +03:00
Migrate container class custom string cls as atrribute name tests
This commit is contained in:
parent
c437610f7f
commit
602d9336e1
|
@ -1 +1 @@
|
|||
"""Dependency injector container unit tests."""
|
||||
"""Container tests."""
|
||||
|
|
36
tests/unit/containers/cls/test_custom_strings_py2_py3.py
Normal file
36
tests/unit/containers/cls/test_custom_strings_py2_py3.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
"""Tests for container cls with custom string classes as attribute names.
|
||||
|
||||
See: https://github.com/ets-labs/python-dependency-injector/issues/479
|
||||
"""
|
||||
|
||||
from dependency_injector import containers, providers
|
||||
from pytest import fixture, raises
|
||||
|
||||
|
||||
class CustomString(str):
|
||||
pass
|
||||
|
||||
|
||||
class CustomClass:
|
||||
thing = None
|
||||
|
||||
|
||||
class Container(containers.DeclarativeContainer):
|
||||
pass
|
||||
|
||||
|
||||
@fixture
|
||||
def provider():
|
||||
return providers.Provider()
|
||||
|
||||
|
||||
def test_setattr(provider):
|
||||
setattr(Container, CustomString("test_attr"), provider)
|
||||
assert Container.test_attr is provider
|
||||
|
||||
|
||||
def test_delattr():
|
||||
setattr(Container, CustomString("test_attr"), provider)
|
||||
delattr(Container, CustomString("test_attr"))
|
||||
with raises(AttributeError):
|
||||
Container.test_attr
|
|
@ -1,35 +0,0 @@
|
|||
"""Dependency injector declarative container unit tests."""
|
||||
|
||||
import unittest
|
||||
|
||||
from dependency_injector import (
|
||||
containers,
|
||||
providers,
|
||||
)
|
||||
|
||||
|
||||
class DeclarativeContainerWithCustomStringTests(unittest.TestCase):
|
||||
# See: https://github.com/ets-labs/python-dependency-injector/issues/479
|
||||
|
||||
class CustomString(str):
|
||||
pass
|
||||
|
||||
class CustomClass:
|
||||
thing = None
|
||||
|
||||
class CustomContainer(containers.DeclarativeContainer):
|
||||
pass
|
||||
|
||||
def setUp(self):
|
||||
self.container = self.CustomContainer
|
||||
self.provider = providers.Provider()
|
||||
|
||||
def test_setattr(self):
|
||||
setattr(self.container, self.CustomString("test_attr"), self.provider)
|
||||
self.assertIs(self.container.test_attr, self.provider)
|
||||
|
||||
def test_delattr(self):
|
||||
setattr(self.container, self.CustomString("test_attr"), self.provider)
|
||||
delattr(self.container, self.CustomString("test_attr"))
|
||||
with self.assertRaises(AttributeError):
|
||||
self.container.test_attr
|
Loading…
Reference in New Issue
Block a user