def _request(self): if not Container.hasBinding(self._identifier): return self._default obj = Container.resolve(self._identifier) self._assertion(obj) return obj
def testTransientInstance(self): Container.bind('Qux').to(Qux) test1 = Test1() test2 = Test2() self.assertIsNot(test1.qux, test2.qux)
def test1(self): config = { 'PathVars': { 'foo': 'yep [bar]', 'bar': 'result2', 'nest1': 'asdf [foo]', } } Container.bind('Config').toSingle(Config, [config]) Container.bind('VarManager').toSingle(VarManager) pathMgr = Container.resolve('VarManager') assertThat(pathMgr.hasKey('foo')) assertThat(not pathMgr.hasKey('asdf')) assertThat(pathMgr.tryGet('bobsdf') == None) assertThat( pathMgr.expand('before [bar] after') == 'before result2 after') assertThat( pathMgr.expand('before [foo] after') == 'before yep result2 after') assertThat(not pathMgr.hasKey('qux')) pathMgr.add('qux', 'sadf') assertThat(pathMgr.hasKey('qux')) assertThat(pathMgr.expand('[qux]') == 'sadf') assertThat(pathMgr.expand('[nest1]') == 'asdf yep result2') print('Done')
def testSingletonType(self): Container.bind('Qux').toSingle(Qux) test1 = Test1() test2 = Test2() self.assertIs(test1.qux, test2.qux)
def testSingletonMethodWithParam(self): Container.bind('Qux').toSingle(GetQux, 4) test1 = Test1() test2 = Test2() self.assertIs(test1.qux, test2.qux) self.assertEqual(test1.qux.GetValue(), 4)
def testUseDefault(self): Container.bind('Foo').to(1) Container.bind('Test1').toSingle(Test1) test1 = Container.resolve('Test1') self.assertEqual(test1.foo, 1) self.assertEqual(test1.bar, 5)
def testTransientInstanceWithParam(self): Container.bind('Qux').to(Qux, 5) test1 = Test1() test2 = Test2() self.assertIsNot(test1.qux, test2.qux) self.assertEqual(test1.qux.GetValue(), 5)
def testTransientMethod(self): Container.bind('Qux').to(GetQux, 6) test1 = Test1() test2 = Test2() self.assertIsNot(test1.qux, test2.qux) self.assertEqual(test1.qux.GetValue(), 6)
def test1(self): assertThat(False, "TODO") #Container.bind('Config').toSingle(ConfigXml) Container.bind('VarManager').toSingle(VarManager) Container.bind('SystemHelper').toSingle(SystemHelper) Container.bind('Logger').toSingle(Logger) self._test1(Container.resolve('SystemHelper'))
def testOverrideDefault(self): Container.bind('Foo').to(2) Container.bind('Test1').to(Test1) Container.bind('Bar').to(3) test1 = Container.resolve('Test1') self.assertEqual(test1.foo, 2) self.assertEqual(test1.bar, 3)
def testOutputToFile(self): assertThat(False) #Container.bind('Config').toSingle(ConfigXml) Container.bind('VarManager').toSingle( VarManager, { 'LogPath': ScriptDir + '/logtest.txt', 'LogPathPrevious': ScriptDir + '/logtest.prev.txt', }) log = Logger(False, True) log.heading("heading 1") log.info("info 1") log.error("error 1") log.good("good 1") log.info("info 2") log.heading("heading 2") log.info("info 3") log.finished("Done") log.dispose()
def setUp(self): Container.clear()
def test1(self): Container.bind('Foo1').to(Foo1, 7) Container.bind('Foo2').to(Foo2, 6) foo2 = Container.resolve('Foo2') foo2.Start()
def testIsInstanceSuccess(self): Container.bind('Title').to('yep') Test2().Run()
def testIsInstanceFailure(self): Container.bind('Title').to(2) Test2().Run()
def testHasMethodSuccess(self): Container.bind('Console').toSingle(Console1) Test1().Run()
def testHasMethodFail(self): # does not have WriteLine() Container.bind('Console').toSingle(Foo) Test1().Run()
def installBindings(): config = { 'PathVars': { 'ScriptDir': ScriptDir, 'RootDir': RootDir, 'TempDir': '[RootDir]/Temp', 'WebGlTemplate': '[ScriptDir]/web_config_template.xml', 'OutputRootDir': '[RootDir]/Builds', 'UnityExePath': 'D:/Utils/Unity/Installs/2018.2.2f1/Editor/Unity.exe', 'LogPath': '[RootDir]/Log.txt', 'UnityProjectPath': '[RootDir]/UnityProject', 'UnityProjectPathTempDir': '[TempDir]/UnityProject', 'MsBuildExePath': 'C:/Windows/Microsoft.NET/Framework/v4.0.30319/msbuild.exe' }, 'Compilation': { 'UseDevenv': False }, } Container.bind('Config').toSingle(Config, [config]) Container.bind('LogStream').toSingle(LogStreamFile) Container.bind('LogStream').toSingle(LogStreamConsole, True, False) Container.bind('ScriptRunner').toSingle(ScriptRunner) Container.bind('VarManager').toSingle(VarManager) Container.bind('SystemHelper').toSingle(SystemHelper) Container.bind('Logger').toSingle(Logger) Container.bind('ProcessRunner').toSingle(ProcessRunner) Container.bind('ZipHelper').toSingle(ZipHelper) Container.bind('VisualStudioHelper').toSingle(VisualStudioHelper) Container.bind('UnityHelper').toSingle(UnityHelper)
def _request(self): obj = Container.resolve(self._identifier) self._assertion(obj) return obj
def _request(self): objects = Container.resolveMany(self._identifier) for obj in objects: self._assertion(obj) return objects