mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-02-14 18:40:52 +03:00
Fix repr
This commit is contained in:
parent
fd9c78c22d
commit
234f48df31
|
@ -3119,15 +3119,15 @@ static PyObject *__pyx_builtin_hex;
|
|||
static const char __pyx_k_[] = "_";
|
||||
static const char __pyx_k__4[] = "__";
|
||||
static const char __pyx_k__5[] = ".";
|
||||
static const char __pyx_k__8[] = "('";
|
||||
static const char __pyx_k__8[] = "(";
|
||||
static const char __pyx_k__9[] = ")";
|
||||
static const char __pyx_k_id[] = "id";
|
||||
static const char __pyx_k_os[] = "os";
|
||||
static const char __pyx_k_re[] = "re";
|
||||
static const char __pyx_k_0_1[] = "{0}={1}";
|
||||
static const char __pyx_k__10[] = ", ";
|
||||
static const char __pyx_k__11[] = "')";
|
||||
static const char __pyx_k__12[] = "(";
|
||||
static const char __pyx_k__11[] = "('";
|
||||
static const char __pyx_k__12[] = "')";
|
||||
static const char __pyx_k__13[] = "";
|
||||
static const char __pyx_k__16[] = "\\$\\{([^}^{]+)\\}";
|
||||
static const char __pyx_k_cls[] = "cls";
|
||||
|
@ -3299,7 +3299,7 @@ static const char __pyx_k_IS_PROVIDER[] = "__IS_PROVIDER__";
|
|||
static const char __pyx_k_ImportError[] = "ImportError";
|
||||
static const char __pyx_k_PickleError[] = "PickleError";
|
||||
static const char __pyx_k_config_file[] = "config_file";
|
||||
static const char __pyx_k_initialized[] = "', initialized=";
|
||||
static const char __pyx_k_initialized[] = ", initialized=";
|
||||
static const char __pyx_k_initializer[] = "initializer";
|
||||
static const char __pyx_k_instance_of[] = "instance_of";
|
||||
static const char __pyx_k_is_resource[] = "_is_resource";
|
||||
|
@ -46978,7 +46978,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Resource_2__deepcopy
|
|||
*
|
||||
* def __repr__(self): # <<<<<<<<<<<<<<
|
||||
* return (
|
||||
* f'{self.__class__.__name__}(\'{self.__initializer}\', '
|
||||
* f'{self.__class__.__name__}({self.__initializer}, '
|
||||
*/
|
||||
|
||||
/* Python wrapper */
|
||||
|
@ -47011,7 +47011,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Resource_4__repr__(s
|
|||
*
|
||||
* def __repr__(self):
|
||||
* return ( # <<<<<<<<<<<<<<
|
||||
* f'{self.__class__.__name__}(\'{self.__initializer}\', '
|
||||
* f'{self.__class__.__name__}({self.__initializer}, '
|
||||
* f'initialized={self.__initialized})'
|
||||
*/
|
||||
__Pyx_XDECREF(__pyx_r);
|
||||
|
@ -47019,7 +47019,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Resource_4__repr__(s
|
|||
/* "dependency_injector/providers.pyx":2595
|
||||
* def __repr__(self):
|
||||
* return (
|
||||
* f'{self.__class__.__name__}(\'{self.__initializer}\', ' # <<<<<<<<<<<<<<
|
||||
* f'{self.__class__.__name__}({self.__initializer}, ' # <<<<<<<<<<<<<<
|
||||
* f'initialized={self.__initialized})'
|
||||
* )
|
||||
*/
|
||||
|
@ -47041,7 +47041,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Resource_4__repr__(s
|
|||
PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
|
||||
__pyx_t_4 = 0;
|
||||
__Pyx_INCREF(__pyx_kp_u__8);
|
||||
__pyx_t_2 += 2;
|
||||
__pyx_t_2 += 1;
|
||||
__Pyx_GIVEREF(__pyx_kp_u__8);
|
||||
PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_kp_u__8);
|
||||
__pyx_t_4 = __Pyx_PyObject_FormatSimple(__pyx_v_self->__pyx___initializer, __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 2595, __pyx_L1_error)
|
||||
|
@ -47052,13 +47052,13 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Resource_4__repr__(s
|
|||
PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_4);
|
||||
__pyx_t_4 = 0;
|
||||
__Pyx_INCREF(__pyx_kp_u_initialized);
|
||||
__pyx_t_2 += 15;
|
||||
__pyx_t_2 += 14;
|
||||
__Pyx_GIVEREF(__pyx_kp_u_initialized);
|
||||
PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_kp_u_initialized);
|
||||
|
||||
/* "dependency_injector/providers.pyx":2596
|
||||
* return (
|
||||
* f'{self.__class__.__name__}(\'{self.__initializer}\', '
|
||||
* f'{self.__class__.__name__}({self.__initializer}, '
|
||||
* f'initialized={self.__initialized})' # <<<<<<<<<<<<<<
|
||||
* )
|
||||
*
|
||||
|
@ -47077,7 +47077,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Resource_4__repr__(s
|
|||
/* "dependency_injector/providers.pyx":2595
|
||||
* def __repr__(self):
|
||||
* return (
|
||||
* f'{self.__class__.__name__}(\'{self.__initializer}\', ' # <<<<<<<<<<<<<<
|
||||
* f'{self.__class__.__name__}({self.__initializer}, ' # <<<<<<<<<<<<<<
|
||||
* f'initialized={self.__initialized})'
|
||||
* )
|
||||
*/
|
||||
|
@ -47093,7 +47093,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Resource_4__repr__(s
|
|||
*
|
||||
* def __repr__(self): # <<<<<<<<<<<<<<
|
||||
* return (
|
||||
* f'{self.__class__.__name__}(\'{self.__initializer}\', '
|
||||
* f'{self.__class__.__name__}({self.__initializer}, '
|
||||
*/
|
||||
|
||||
/* function exit code */
|
||||
|
@ -52962,10 +52962,10 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_16ProvidedInstance_2_
|
|||
__Pyx_GIVEREF(__pyx_t_4);
|
||||
PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
|
||||
__pyx_t_4 = 0;
|
||||
__Pyx_INCREF(__pyx_kp_u__8);
|
||||
__Pyx_INCREF(__pyx_kp_u__11);
|
||||
__pyx_t_2 += 2;
|
||||
__Pyx_GIVEREF(__pyx_kp_u__8);
|
||||
PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_kp_u__8);
|
||||
__Pyx_GIVEREF(__pyx_kp_u__11);
|
||||
PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_kp_u__11);
|
||||
__pyx_t_4 = __Pyx_PyObject_FormatSimple(((PyObject *)__pyx_v_self->__pyx___provider), __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 2938, __pyx_L1_error)
|
||||
__Pyx_GOTREF(__pyx_t_4);
|
||||
__pyx_t_3 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_3) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_3;
|
||||
|
@ -52973,10 +52973,10 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_16ProvidedInstance_2_
|
|||
__Pyx_GIVEREF(__pyx_t_4);
|
||||
PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_4);
|
||||
__pyx_t_4 = 0;
|
||||
__Pyx_INCREF(__pyx_kp_u__11);
|
||||
__Pyx_INCREF(__pyx_kp_u__12);
|
||||
__pyx_t_2 += 2;
|
||||
__Pyx_GIVEREF(__pyx_kp_u__11);
|
||||
PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_kp_u__11);
|
||||
__Pyx_GIVEREF(__pyx_kp_u__12);
|
||||
PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_kp_u__12);
|
||||
__pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_1, 4, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 2938, __pyx_L1_error)
|
||||
__Pyx_GOTREF(__pyx_t_4);
|
||||
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
|
||||
|
@ -54296,10 +54296,10 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_15AttributeGetter_2__
|
|||
__Pyx_GIVEREF(__pyx_t_4);
|
||||
PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
|
||||
__pyx_t_4 = 0;
|
||||
__Pyx_INCREF(__pyx_kp_u__8);
|
||||
__Pyx_INCREF(__pyx_kp_u__11);
|
||||
__pyx_t_2 += 2;
|
||||
__Pyx_GIVEREF(__pyx_kp_u__8);
|
||||
PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_kp_u__8);
|
||||
__Pyx_GIVEREF(__pyx_kp_u__11);
|
||||
PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_kp_u__11);
|
||||
__pyx_t_4 = __Pyx_PyObject_FormatSimple(__pyx_v_self->__pyx___attribute, __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 2981, __pyx_L1_error)
|
||||
__Pyx_GOTREF(__pyx_t_4);
|
||||
__pyx_t_3 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_3) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_3;
|
||||
|
@ -54307,10 +54307,10 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_15AttributeGetter_2__
|
|||
__Pyx_GIVEREF(__pyx_t_4);
|
||||
PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_4);
|
||||
__pyx_t_4 = 0;
|
||||
__Pyx_INCREF(__pyx_kp_u__11);
|
||||
__Pyx_INCREF(__pyx_kp_u__12);
|
||||
__pyx_t_2 += 2;
|
||||
__Pyx_GIVEREF(__pyx_kp_u__11);
|
||||
PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_kp_u__11);
|
||||
__Pyx_GIVEREF(__pyx_kp_u__12);
|
||||
PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_kp_u__12);
|
||||
__pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_1, 4, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 2981, __pyx_L1_error)
|
||||
__Pyx_GOTREF(__pyx_t_4);
|
||||
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
|
||||
|
@ -55754,10 +55754,10 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_10ItemGetter_2__repr_
|
|||
__Pyx_GIVEREF(__pyx_t_4);
|
||||
PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
|
||||
__pyx_t_4 = 0;
|
||||
__Pyx_INCREF(__pyx_kp_u__8);
|
||||
__Pyx_INCREF(__pyx_kp_u__11);
|
||||
__pyx_t_2 += 2;
|
||||
__Pyx_GIVEREF(__pyx_kp_u__8);
|
||||
PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_kp_u__8);
|
||||
__Pyx_GIVEREF(__pyx_kp_u__11);
|
||||
PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_kp_u__11);
|
||||
__pyx_t_4 = __Pyx_PyObject_FormatSimple(__pyx_v_self->__pyx___item, __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 3031, __pyx_L1_error)
|
||||
__Pyx_GOTREF(__pyx_t_4);
|
||||
__pyx_t_3 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_3) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_3;
|
||||
|
@ -55765,10 +55765,10 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_10ItemGetter_2__repr_
|
|||
__Pyx_GIVEREF(__pyx_t_4);
|
||||
PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_4);
|
||||
__pyx_t_4 = 0;
|
||||
__Pyx_INCREF(__pyx_kp_u__11);
|
||||
__Pyx_INCREF(__pyx_kp_u__12);
|
||||
__pyx_t_2 += 2;
|
||||
__Pyx_GIVEREF(__pyx_kp_u__11);
|
||||
PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_kp_u__11);
|
||||
__Pyx_GIVEREF(__pyx_kp_u__12);
|
||||
PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_kp_u__12);
|
||||
__pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_1, 4, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 3031, __pyx_L1_error)
|
||||
__Pyx_GOTREF(__pyx_t_4);
|
||||
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
|
||||
|
@ -57268,10 +57268,10 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_12MethodCaller_2__rep
|
|||
__Pyx_GIVEREF(__pyx_t_4);
|
||||
PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
|
||||
__pyx_t_4 = 0;
|
||||
__Pyx_INCREF(__pyx_kp_u__12);
|
||||
__Pyx_INCREF(__pyx_kp_u__8);
|
||||
__pyx_t_2 += 1;
|
||||
__Pyx_GIVEREF(__pyx_kp_u__12);
|
||||
PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_kp_u__12);
|
||||
__Pyx_GIVEREF(__pyx_kp_u__8);
|
||||
PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_kp_u__8);
|
||||
__pyx_t_4 = __Pyx_PyObject_FormatSimple(((PyObject *)__pyx_v_self->__pyx___provider), __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 3087, __pyx_L1_error)
|
||||
__Pyx_GOTREF(__pyx_t_4);
|
||||
__pyx_t_3 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_3) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_3;
|
||||
|
|
|
@ -2592,7 +2592,7 @@ cdef class Resource(Provider):
|
|||
|
||||
def __repr__(self):
|
||||
return (
|
||||
f'{self.__class__.__name__}(\'{self.__initializer}\', '
|
||||
f'{self.__class__.__name__}({self.__initializer}, '
|
||||
f'initialized={self.__initialized})'
|
||||
)
|
||||
|
||||
|
|
161
tests/unit/providers/test_resource_py3.py
Normal file
161
tests/unit/providers/test_resource_py3.py
Normal file
|
@ -0,0 +1,161 @@
|
|||
"""Dependency injector resource provider unit tests."""
|
||||
|
||||
import sys
|
||||
|
||||
import unittest2 as unittest
|
||||
|
||||
from dependency_injector import providers
|
||||
|
||||
|
||||
def init_fn(*args, **kwargs):
|
||||
return args, kwargs
|
||||
|
||||
|
||||
def init_fn_return_none(*args, **kwargs):
|
||||
return None
|
||||
|
||||
|
||||
class ResourceTests(unittest.TestCase):
|
||||
|
||||
def test_is_provider(self):
|
||||
self.assertTrue(providers.is_provider(providers.Resource(init_fn)))
|
||||
|
||||
def test_provided_instance_provider(self):
|
||||
provider = providers.Resource(init_fn)
|
||||
self.assertIsInstance(provider.provided, providers.ProvidedInstance)
|
||||
|
||||
# Initialization and shutdown
|
||||
# Injection
|
||||
# Initializer: function
|
||||
# Initializer: generator
|
||||
# Initializer: base class
|
||||
# Args
|
||||
# Kwargs
|
||||
# Overridden
|
||||
# Deepcopy
|
||||
# Repr
|
||||
|
||||
# def test_call_with_init_positional_args(self):
|
||||
# provider = providers.List('i1', 'i2')
|
||||
#
|
||||
# list1 = provider()
|
||||
# list2 = provider()
|
||||
#
|
||||
# self.assertEqual(list1, ['i1', 'i2'])
|
||||
# self.assertEqual(list2, ['i1', 'i2'])
|
||||
#
|
||||
# self.assertIsNot(list1, list2)
|
||||
#
|
||||
# def test_call_with_context_args(self):
|
||||
# provider = providers.List('i1', 'i2')
|
||||
#
|
||||
# self.assertEqual(provider('i3', 'i4'), ['i1', 'i2', 'i3', 'i4'])
|
||||
#
|
||||
# def test_fluent_interface(self):
|
||||
# provider = providers.List() \
|
||||
# .add_args(1, 2)
|
||||
#
|
||||
# self.assertEqual(provider(), [1, 2])
|
||||
#
|
||||
# def test_set_args(self):
|
||||
# provider = providers.List() \
|
||||
# .add_args(1, 2) \
|
||||
# .set_args(3, 4)
|
||||
# self.assertEqual(provider.args, tuple([3, 4]))
|
||||
#
|
||||
# def test_clear_args(self):
|
||||
# provider = providers.List() \
|
||||
# .add_args(1, 2) \
|
||||
# .clear_args()
|
||||
# self.assertEqual(provider.args, tuple())
|
||||
#
|
||||
# def test_call_overridden(self):
|
||||
# provider = providers.List(1, 2)
|
||||
# overriding_provider1 = providers.List(2, 3)
|
||||
# overriding_provider2 = providers.List(3, 4)
|
||||
#
|
||||
# provider.override(overriding_provider1)
|
||||
# provider.override(overriding_provider2)
|
||||
#
|
||||
# instance1 = provider()
|
||||
# instance2 = provider()
|
||||
#
|
||||
# self.assertIsNot(instance1, instance2)
|
||||
# self.assertEqual(instance1, [3, 4])
|
||||
# self.assertEqual(instance2, [3, 4])
|
||||
#
|
||||
# def test_deepcopy(self):
|
||||
# provider = providers.List(1, 2)
|
||||
#
|
||||
# provider_copy = providers.deepcopy(provider)
|
||||
#
|
||||
# self.assertIsNot(provider, provider_copy)
|
||||
# self.assertEqual(provider.args, provider_copy.args)
|
||||
# self.assertIsInstance(provider, providers.List)
|
||||
#
|
||||
# def test_deepcopy_from_memo(self):
|
||||
# provider = providers.List(1, 2)
|
||||
# provider_copy_memo = providers.List(1, 2)
|
||||
#
|
||||
# provider_copy = providers.deepcopy(
|
||||
# provider, memo={id(provider): provider_copy_memo})
|
||||
#
|
||||
# self.assertIs(provider_copy, provider_copy_memo)
|
||||
#
|
||||
# def test_deepcopy_args(self):
|
||||
# provider = providers.List()
|
||||
# dependent_provider1 = providers.Factory(list)
|
||||
# dependent_provider2 = providers.Factory(dict)
|
||||
#
|
||||
# provider.add_args(dependent_provider1, dependent_provider2)
|
||||
#
|
||||
# provider_copy = providers.deepcopy(provider)
|
||||
# dependent_provider_copy1 = provider_copy.args[0]
|
||||
# dependent_provider_copy2 = provider_copy.args[1]
|
||||
#
|
||||
# self.assertNotEqual(provider.args, provider_copy.args)
|
||||
#
|
||||
# self.assertIs(dependent_provider1.cls, dependent_provider_copy1.cls)
|
||||
# self.assertIsNot(dependent_provider1, dependent_provider_copy1)
|
||||
#
|
||||
# self.assertIs(dependent_provider2.cls, dependent_provider_copy2.cls)
|
||||
# self.assertIsNot(dependent_provider2, dependent_provider_copy2)
|
||||
#
|
||||
# def test_deepcopy_overridden(self):
|
||||
# provider = providers.List()
|
||||
# object_provider = providers.Object(object())
|
||||
#
|
||||
# provider.override(object_provider)
|
||||
#
|
||||
# provider_copy = providers.deepcopy(provider)
|
||||
# object_provider_copy = provider_copy.overridden[0]
|
||||
#
|
||||
# self.assertIsNot(provider, provider_copy)
|
||||
# self.assertEqual(provider.args, provider_copy.args)
|
||||
# self.assertIsInstance(provider, providers.List)
|
||||
#
|
||||
# self.assertIsNot(object_provider, object_provider_copy)
|
||||
# self.assertIsInstance(object_provider_copy, providers.Object)
|
||||
#
|
||||
# def test_deepcopy_with_sys_streams(self):
|
||||
# provider = providers.List()
|
||||
# provider.add_args(sys.stdin, sys.stdout, sys.stderr)
|
||||
#
|
||||
# provider_copy = providers.deepcopy(provider)
|
||||
#
|
||||
# self.assertIsNot(provider, provider_copy)
|
||||
# self.assertIsInstance(provider_copy, providers.List)
|
||||
# self.assertIs(provider.args[0], sys.stdin)
|
||||
# self.assertIs(provider.args[1], sys.stdout)
|
||||
# self.assertIs(provider.args[2], sys.stderr)
|
||||
#
|
||||
def test_repr(self):
|
||||
provider = providers.Resource(init_fn)
|
||||
|
||||
self.assertEqual(
|
||||
repr(provider),
|
||||
'Resource({0}, initialized={1})'.format(
|
||||
init_fn,
|
||||
provider.initialized,
|
||||
)
|
||||
)
|
Loading…
Reference in New Issue
Block a user