File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ import unittest
2
+
3
+ from dependency_injector import providers
4
+
5
+ from . import Example , _BaseSingletonTestCase
6
+
7
+
8
+ class ContextLocalSingletonTests (_BaseSingletonTestCase , unittest .TestCase ):
9
+
10
+ singleton_cls = providers .ContextLocalSingleton
11
+
12
+ def test_repr (self ):
13
+ provider = providers .ContextLocalSingleton (Example )
14
+
15
+ self .assertEqual (repr (provider ),
16
+ '<dependency_injector.providers.'
17
+ 'ContextLocalSingleton({0}) at {1}>' .format (
18
+ repr (Example ),
19
+ hex (id (provider ))))
20
+
21
+ def test_reset (self ):
22
+ provider = providers .ContextLocalSingleton (Example )
23
+
24
+ instance1 = provider ()
25
+ self .assertIsInstance (instance1 , Example )
26
+
27
+ provider .reset ()
28
+
29
+ instance2 = provider ()
30
+ self .assertIsInstance (instance2 , Example )
31
+
32
+ self .assertIsNot (instance1 , instance2 )
33
+
34
+ def test_reset_clean (self ):
35
+ provider = providers .ContextLocalSingleton (Example )
36
+ instance1 = provider ()
37
+
38
+ provider .reset ()
39
+ provider .reset ()
40
+
41
+ instance2 = provider ()
42
+ self .assertIsNot (instance1 , instance2 )
You can’t perform that action at this time.
0 commit comments