Skip to content

Commit 5efc8fd

Browse files
committed
add tests
1 parent a888fb4 commit 5efc8fd

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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)

0 commit comments

Comments
 (0)