示例#1
0
 def test_RegisterAndGetInstance(self):
     appScope = scope.Scope()
     childScope = scope.Scope(parent=appScope)
     childScope1 = scope.Scope(parent=appScope)
     appScope.runServices()
     self.assertEqual(2, len(appScope.children))
     appScope.remove()
     self.assertEqual(0, len(appScope.children))
     self.assertFalse(appScope.servicesStarted)
示例#2
0
 def test_find_instances(self):
     appScope = scope.Scope()
     appScope.registerBean(Bean(Dependency5), Bean(Dependency6))
     res = appScope.getInstances(Dependency4)
     assert len(res) == 2
     assert isinstance(res[0], Dependency5)
     assert isinstance(res[1], Dependency6)
示例#3
0
    def test_Inheritance_multi(self):
        appScope = scope.Scope()
        appScope.registerBean(Bean(Dependency5), Bean(Dependency7))
        dep3 = appScope.getInstance(Dependency3)
        self.assertTrue(dep3, Dependency7)

        dep4 = appScope.getInstance(Dependency5)
        self.assertTrue(dep3, Dependency7)
示例#4
0
 def test_RegisterAndGetInstanceError(self):
     appScope = scope.Scope()
     appScope.registerBean(Dependency1, Dependency4, Dependency5, Dependency7)
     try:
         instance = appScope.getInstance(Dependency5)
         self.fail("Exception expected")
     except ScopetonException as e:
         pass
示例#5
0
    def test_RegisterAndGetInstanceCustomNames(self):
        appScope = scope.Scope()
        appScope.registerBean(Bean(Dependency1, name=Dependency3),
                              Bean(Dependency4, name="aaa"))

        dep2 = appScope.getInstance(Dependency3)  # type: Dependency2
        dep3 = appScope.getInstance("aaa")
        self.assertNotEqual(dep2, dep3)
        self.assertEqual(Dependency1, dep2.__class__)
示例#6
0
 def test_Inheritance_err(self):
     appScope = scope.Scope()
     appScope.registerBean(Bean(Dependency5), Bean(Dependency7))
     try:
         dep4 = appScope.getInstance(Dependency4)
         ok = False
     except:
         ok = True
     self.assertTrue(ok)
示例#7
0
 def test_RegisterAndGetInstance(self):
     appScope = scope.Scope()
     appScope.registerBean(Bean(Dependency2), Bean(Dependency3))
     dep2 = appScope.getInstance(Dependency2)  # type: Dependency2
     dep3 = appScope.getInstance(Dependency3)
     dep3_single = appScope.getInstance(Dependency3)
     appScope.runServices()
     self.assertTrue(isinstance(dep3, Dependency3))
     self.assertEqual(dep3, dep3_single)
     self.assertEqual(dep2.dep3, dep3_single)
     self.assertTrue(isinstance(dep2, Dependency2))
     self.assertTrue(dep2.called)
     self.assertFalse(dep2.preDestroyCalled)
     appScope.stopServices()
     self.assertTrue(dep2.preDestroyCalled)
示例#8
0
 def test_same(self):
     appScope = scope.Scope()
     appScope.registerBean(Bean(Dependency7), Bean(Dependency7))
     appScope.getInstance(Dependency7)
示例#9
0
    def test_mock(self):
        appScope = scope.Scope()
        appScope.registerBean(Bean(Mock(Dependency7), name=Dependency7))

        appScope = scope.Scope()
        appScope.registerInstance(Dependency7, Mock(Dependency7))
示例#10
0
 def test_register_instance(self):
     appScope = scope.Scope()
     appScope.registerBean(Bean(Dependency7))
     a = appScope.getInstance(Dependency7)
     b = appScope.getInstance(Dependency4)
     self.assertEqual(a, b)
示例#11
0
 def test_RegisterAndGetInstance(self):
     appScope = scope.Scope()
     appScope.registerBean(Dependency1, Dependency4, Dependency5, Dependency7)
     instance = appScope.getInstance(Dependency7)
     self.assertTrue(instance.called, "Constructor is not called!")