diff options
Diffstat (limited to 'python')
105 files changed, 1472 insertions, 2108 deletions
diff --git a/python/test/Glacier2/application/Client.py b/python/test/Glacier2/application/Client.py index 32c08f5e8d6..dac74edf696 100644 --- a/python/test/Glacier2/application/Client.py +++ b/python/test/Glacier2/application/Client.py @@ -8,16 +8,21 @@ # # ********************************************************************** -import os, sys, traceback, threading, Ice, Glacier2 - -Ice.loadSlice("Callback.ice") +import sys +import threading +import Ice +import Glacier2 +from TestHelper import TestHelper +TestHelper.loadSlice("Callback.ice") import Test + def test(b): if not b: raise RuntimeError('test assertion failed') + class CallbackReceiverI(Test.CallbackReceiver): def __init__(self): @@ -35,6 +40,7 @@ class CallbackReceiverI(Test.CallbackReceiver): self._cond.wait() self._received = False; + class Application(Glacier2.Application): def __init__(self): @@ -76,37 +82,38 @@ class Application(Glacier2.Application): def sessionDestroyed(self): self._destroyed = True -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - initData.properties.setProperty("Ice.Default.Router", "Glacier2/router:default -p 12060") - - app = Application() - status = app.main(sys.argv, initData=initData) - test(app._restart == 5) - test(app._destroyed) - initData.properties.setProperty("Ice.Default.Router", ""); - with Ice.initialize(initData) as communicator: - sys.stdout.write("testing stringToProxy for process object... ") - sys.stdout.flush() - processBase = communicator.stringToProxy("Glacier2/admin -f Process:default -p 12061"); - print("ok") - sys.stdout.write("testing checked cast for admin object... ") - sys.stdout.flush() - process = Ice.ProcessPrx.checkedCast(processBase) - test(process) - print("ok") +class Client(TestHelper): + + def run(self, args): + initData = Ice.InitializationData() + initData.properties = self.createTestProperties(sys.argv) + initData.properties.setProperty("Ice.Default.Router", "Glacier2/router:default -p 12060") - sys.stdout.write("testing Glacier2 shutdown... ") - sys.stdout.flush() - process.shutdown() - try: - process.ice_ping() - test(False) - except Ice.LocalException: + app = Application() + status = app.main(sys.argv, initData=initData) + test(status == 0) + test(app._restart == 5) + test(app._destroyed) + + initData.properties.setProperty("Ice.Default.Router", "") + with self.initialize(initData=initData) as communicator: + sys.stdout.write("testing stringToProxy for process object... ") + sys.stdout.flush() + processBase = communicator.stringToProxy("Glacier2/admin -f Process:default -p 12061") print("ok") -except: - traceback.print_exc() - status = 1 -sys.exit(status) + + sys.stdout.write("testing checked cast for admin object... ") + sys.stdout.flush() + process = Ice.ProcessPrx.checkedCast(processBase) + test(process) + print("ok") + + sys.stdout.write("testing Glacier2 shutdown... ") + sys.stdout.flush() + process.shutdown() + try: + process.ice_ping() + test(False) + except Ice.LocalException: + print("ok") diff --git a/python/test/Glacier2/application/Server.py b/python/test/Glacier2/application/Server.py index 4de00da98b2..7b32c1689b9 100644 --- a/python/test/Glacier2/application/Server.py +++ b/python/test/Glacier2/application/Server.py @@ -8,10 +8,12 @@ # # ********************************************************************** -import os, sys, traceback, Ice -Ice.loadSlice('Callback.ice') +from TestHelper import TestHelper +TestHelper.loadSlice('Callback.ice') +import Ice import Test + class CallbackI(Test.Callback): def initiateCallback(self, proxy, current): @@ -20,19 +22,16 @@ class CallbackI(Test.Callback): def shutdown(self, current): current.adapter.getCommunicator().shutdown() -class Server(Ice.Application): + +class Server(TestHelper): def run(self, args): - self.communicator().getProperties().setProperty("DeactivatedAdapter.Endpoints", "default -p 12011") - self.communicator().createObjectAdapter("DeactivatedAdapter") - - self.communicator().getProperties().setProperty("CallbackAdapter.Endpoints", "default -p 12010") - adapter = self.communicator().createObjectAdapter("CallbackAdapter") - adapter.add(CallbackI(), Ice.stringToIdentity("callback")) - adapter.activate() - self.communicator().waitForShutdown() - return 0 - -app = Server() -status = app.main(sys.argv) -sys.exit(status) + with self.initialize(args=args) as communicator: + communicator.getProperties().setProperty("DeactivatedAdapter.Endpoints", "default -p 12011") + communicator.createObjectAdapter("DeactivatedAdapter") + + communicator.getProperties().setProperty("CallbackAdapter.Endpoints", "default -p 12010") + adapter = communicator.createObjectAdapter("CallbackAdapter") + adapter.add(CallbackI(), Ice.stringToIdentity("callback")) + adapter.activate() + communicator.waitForShutdown() diff --git a/python/test/Ice/acm/AllTests.py b/python/test/Ice/acm/AllTests.py index 29d3209b650..7d61d21147e 100644 --- a/python/test/Ice/acm/AllTests.py +++ b/python/test/Ice/acm/AllTests.py @@ -150,8 +150,8 @@ class TestCase(threading.Thread): self._serverACMClose = close self._serverACMHeartbeat = heartbeat -def allTests(communicator): - ref = "communicator:default -p 12010" +def allTests(helper, communicator): + ref = "communicator:{0}".format(helper.getTestEndpoint(num=0)) com = Test.RemoteCommunicatorPrx.uncheckedCast(communicator.stringToProxy(ref)) tests = [] diff --git a/python/test/Ice/acm/Client.py b/python/test/Ice/acm/Client.py index cd122cbd94a..637f7b7eb22 100755 --- a/python/test/Ice/acm/Client.py +++ b/python/test/Ice/acm/Client.py @@ -8,34 +8,15 @@ # # ********************************************************************** -import os, sys, traceback -import Ice - -import Ice -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) - -Ice.loadSlice("'-I" + slice_dir + "' Test.ice") +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import AllTests -def test(b): - if not b: - raise RuntimeError('test assertion failed') - -def run(args, communicator): - AllTests.allTests(communicator) - return True -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - initData.properties.setProperty('Ice.Warn.Connections', '0') - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False +class Client(TestHelper): -sys.exit(not status) + def run(self, args): + properties = self.createTestProperties(args) + properties.setProperty('Ice.Warn.Connections', '0') + with self.initialize(properties=properties) as communicator: + AllTests.allTests(self, communicator) diff --git a/python/test/Ice/acm/Server.py b/python/test/Ice/acm/Server.py index 792bc0a8c1f..fe276128ffc 100755 --- a/python/test/Ice/acm/Server.py +++ b/python/test/Ice/acm/Server.py @@ -8,39 +8,27 @@ # # ********************************************************************** -import os, sys, traceback import Ice -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") +import TestI -Ice.loadSlice('"-I' + slice_dir + '" Test.ice') -import Test, TestI -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - communicator.getProperties().setProperty("TestAdapter.ACM.Timeout", "0") - adapter = communicator.createObjectAdapter("TestAdapter") - id = Ice.stringToIdentity("communicator") - adapter.add(TestI.RemoteCommunicatorI(), id) - adapter.activate() +class Server(TestHelper): - # Disable ready print for further adapters. - communicator.getProperties().setProperty("Ice.PrintAdapterReady", "0") + def run(self, args): - communicator.waitForShutdown() - return True + properties = self.createTestProperties(args) + properties.setProperty("Ice.Warn.Connections", "0") + properties.setProperty("Ice.ACM.Timeout", "1") + with self.initialize(properties=properties) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") + communicator.getProperties().setProperty("TestAdapter.ACM.Timeout", "0") + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(TestI.RemoteCommunicatorI(), Ice.stringToIdentity("communicator")) + adapter.activate() -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - initData.properties.setProperty("Ice.Warn.Connections", "0"); - initData.properties.setProperty("Ice.ACM.Timeout", "1"); - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False + # Disable ready print for further adapters. + communicator.getProperties().setProperty("Ice.PrintAdapterReady", "0") -sys.exit(not status) + communicator.waitForShutdown() diff --git a/python/test/Ice/adapterDeactivation/AllTests.py b/python/test/Ice/adapterDeactivation/AllTests.py index 6129306fd8f..aabb403d2c1 100644 --- a/python/test/Ice/adapterDeactivation/AllTests.py +++ b/python/test/Ice/adapterDeactivation/AllTests.py @@ -13,10 +13,10 @@ def test(b): if not b: raise RuntimeError('test assertion failed') -def allTests(communicator): +def allTests(helper, communicator): sys.stdout.write("testing stringToProxy... ") sys.stdout.flush() - base = communicator.stringToProxy("test:default -p 12010") + base = communicator.stringToProxy("test:{0}".format(helper.getTestEndpoint())) test(base) print("ok") @@ -52,7 +52,7 @@ def allTests(communicator): initData = Ice.InitializationData() initData.properties = communicator.getProperties().clone() comm = Ice.initialize(initData) - comm.stringToProxy("test:default -p 12010").ice_pingAsync() + comm.stringToProxy("test:{0}".format(helper.getTestEndpoint())).ice_pingAsync() comm.destroy() print("ok") diff --git a/python/test/Ice/adapterDeactivation/Client.py b/python/test/Ice/adapterDeactivation/Client.py index 21deb0c2c9f..25e142b7337 100755 --- a/python/test/Ice/adapterDeactivation/Client.py +++ b/python/test/Ice/adapterDeactivation/Client.py @@ -8,16 +8,13 @@ # # ********************************************************************** -import os, sys +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") +import AllTests -import Ice -Ice.loadSlice('Test.ice') -import Test, AllTests -class TestClient(Ice.Application): - def run(self, args): - AllTests.allTests(self.communicator()) - return 0 +class Client(TestHelper): -app = TestClient() -sys.exit(app.main(sys.argv)) + def run(self, args): + with self.initialize(args=args) as communicator: + AllTests.allTests(self, communicator) diff --git a/python/test/Ice/adapterDeactivation/Collocated.py b/python/test/Ice/adapterDeactivation/Collocated.py index aead96a58e5..edede9c1301 100755 --- a/python/test/Ice/adapterDeactivation/Collocated.py +++ b/python/test/Ice/adapterDeactivation/Collocated.py @@ -8,25 +8,24 @@ # # ********************************************************************** -import os, sys, traceback, time +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") +import AllTests +import TestI -import Ice -Ice.loadSlice('Test.ice') -import Test, TestI, AllTests -class TestServer(Ice.Application): +class Collocated(TestHelper): + def run(self, args): - self.communicator().getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - adapter = self.communicator().createObjectAdapter("TestAdapter") - locator = TestI.ServantLocatorI() - adapter.addServantLocator(locator, "") - #adapter.activate() // Don't activate OA to ensure collocation is used. + with self.initialize(args=args) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + adapter = communicator.createObjectAdapter("TestAdapter") + locator = TestI.ServantLocatorI() - AllTests.allTests(self.communicator()) + adapter.addServantLocator(locator, "") + # adapter.activate() // Don't activate OA to ensure collocation is used. - adapter.waitForDeactivate() - return 0 + AllTests.allTests(self, communicator) -app = TestServer() -sys.exit(app.main(sys.argv)) + adapter.waitForDeactivate() diff --git a/python/test/Ice/adapterDeactivation/Server.py b/python/test/Ice/adapterDeactivation/Server.py index 73347fe8580..45483778e21 100755 --- a/python/test/Ice/adapterDeactivation/Server.py +++ b/python/test/Ice/adapterDeactivation/Server.py @@ -7,22 +7,18 @@ # # ********************************************************************** -import os, sys, traceback, time +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") +import TestI -import Ice -Ice.loadSlice('Test.ice') -import Test, TestI -class TestServer(Ice.Application): - def run(self, args): - self.communicator().getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - adapter = self.communicator().createObjectAdapter("TestAdapter") - locator = TestI.ServantLocatorI() - - adapter.addServantLocator(locator, "") - adapter.activate() - adapter.waitForDeactivate() - return 0 +class Server(TestHelper): -app = TestServer() -sys.exit(app.main(sys.argv)) + def run(self, args): + with self.initialize(args=args) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + adapter = communicator.createObjectAdapter("TestAdapter") + locator = TestI.ServantLocatorI() + adapter.addServantLocator(locator, "") + adapter.activate() + adapter.waitForDeactivate() diff --git a/python/test/Ice/admin/AllTests.py b/python/test/Ice/admin/AllTests.py index 7ef0e0a3fb9..e0457252850 100644 --- a/python/test/Ice/admin/AllTests.py +++ b/python/test/Ice/admin/AllTests.py @@ -71,7 +71,7 @@ def testFacets(com, builtInFacets = True): except Ice.NotRegisteredException: pass # Expected -def allTests(communicator): +def allTests(helper, communicator): sys.stdout.write("testing communicator operations... ") sys.stdout.flush() @@ -144,7 +144,7 @@ def allTests(communicator): com.destroy() print("ok") - ref = "factory:default -p 12010 -t 10000" + ref = "factory:{0} -t 10000".format(helper.getTestEndpoint()) factory = Test.RemoteCommunicatorFactoryPrx.uncheckedCast(communicator.stringToProxy(ref)) sys.stdout.write("testing process facet... ") diff --git a/python/test/Ice/admin/Client.py b/python/test/Ice/admin/Client.py index 76b723c5930..25e142b7337 100644 --- a/python/test/Ice/admin/Client.py +++ b/python/test/Ice/admin/Client.py @@ -8,30 +8,13 @@ # # ********************************************************************** -import os, sys, traceback -import Ice - -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) - -Ice.loadSlice("'-I" + slice_dir + "' Test.ice") +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import AllTests -def test(b): - if not b: - raise RuntimeError('test assertion failed') - -def run(args, communicator): - AllTests.allTests(communicator) - return True -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False +class Client(TestHelper): -sys.exit(not status) + def run(self, args): + with self.initialize(args=args) as communicator: + AllTests.allTests(self, communicator) diff --git a/python/test/Ice/admin/Server.py b/python/test/Ice/admin/Server.py index 0ded6f9744d..3ea0ad1c209 100644 --- a/python/test/Ice/admin/Server.py +++ b/python/test/Ice/admin/Server.py @@ -8,32 +8,19 @@ # # ********************************************************************** -import os, sys, traceback import Ice +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") +import TestI -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) -Ice.loadSlice("'-I" + slice_dir + "' Test.ice") -import Test, TestI +class Server(TestHelper): -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010 -t 10000"); - adapter = communicator.createObjectAdapter("TestAdapter"); - ident = Ice.stringToIdentity("factory"); - adapter.add(TestI.RemoteCommunicatorFactoryI(), ident); - adapter.activate(); + def run(self, args): + with self.initialize(args=args) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(TestI.RemoteCommunicatorFactoryI(), Ice.stringToIdentity("factory")) + adapter.activate() - communicator.waitForShutdown(); - return True; - -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False - -sys.exit(not status) + communicator.waitForShutdown() diff --git a/python/test/Ice/ami/AllTests.py b/python/test/Ice/ami/AllTests.py index 0e65a97e46b..d49b1820cd9 100644 --- a/python/test/Ice/ami/AllTests.py +++ b/python/test/Ice/ami/AllTests.py @@ -376,14 +376,14 @@ class Thrower(CallbackBase): self.called() throwEx(self._t) -def allTests(communicator, collocated): - sref = "test:default -p 12010" +def allTests(helper, communicator, collocated): + sref = "test:{0}".format(helper.getTestEndpoint(num=0)) obj = communicator.stringToProxy(sref) test(obj) p = Test.TestIntfPrx.uncheckedCast(obj) - sref = "testController:default -p 12011" + sref = "testController:{0}".format(helper.getTestEndpoint(num=1)) obj = communicator.stringToProxy(sref) test(obj) @@ -1303,14 +1303,14 @@ def allTests(communicator, collocated): print("ok") -def allTestsFuture(communicator, collocated): - sref = "test:default -p 12010" +def allTestsFuture(helper, communicator, collocated): + sref = "test:{0}".format(helper.getTestEndpoint(num=0)) obj = communicator.stringToProxy(sref) test(obj) p = Test.TestIntfPrx.uncheckedCast(obj) - sref = "testController:default -p 12011" + sref = "testController:{0}".format(helper.getTestEndpoint(num=1)) obj = communicator.stringToProxy(sref) test(obj) diff --git a/python/test/Ice/ami/Client.py b/python/test/Ice/ami/Client.py index a86843fe746..87654db0486 100755 --- a/python/test/Ice/ami/Client.py +++ b/python/test/Ice/ami/Client.py @@ -8,43 +8,24 @@ # # ********************************************************************** -import os, sys, traceback -import Ice - -import Ice -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) - -Ice.loadSlice("'-I" + slice_dir + "' Test.ice") +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import AllTests -def test(b): - if not b: - raise RuntimeError('test assertion failed') - -def run(args, communicator): - AllTests.allTests(communicator, False) - AllTests.allTestsFuture(communicator, False) - return True -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - initData.properties.setProperty('Ice.Warn.AMICallback', '0') - initData.properties.setProperty('Ice.Warn.Connections', '0') +class Client(TestHelper): - # - # Limit the send buffer size, this test relies on the socket - # send() blocking after sending a given amount of data. - # - initData.properties.setProperty("Ice.TCP.SndSize", "50000"); + def run(self, args): + properties = self.createTestProperties(args) + properties.setProperty('Ice.Warn.AMICallback', '0') + properties.setProperty('Ice.Warn.Connections', '0') - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False + # + # Limit the send buffer size, this test relies on the socket + # send() blocking after sending a given amount of data. + # + properties.setProperty("Ice.TCP.SndSize", "50000") -sys.exit(not status) + with self.initialize(properties=properties) as communicator: + AllTests.allTests(self, communicator, False) + AllTests.allTestsFuture(self, communicator, False) diff --git a/python/test/Ice/ami/Collocated.py b/python/test/Ice/ami/Collocated.py index e87e3ac7ea5..0b449be5866 100755 --- a/python/test/Ice/ami/Collocated.py +++ b/python/test/Ice/ami/Collocated.py @@ -8,53 +8,40 @@ # # ********************************************************************** -import os, sys, traceback - +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") +import AllTests +import TestI import Ice -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) - -Ice.loadSlice('"-I' + slice_dir + '" Test.ice') -import Test, TestI, AllTests - -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - communicator.getProperties().setProperty("ControllerAdapter.Endpoints", "default -p 12011") - communicator.getProperties().setProperty("ControllerAdapter.ThreadPool.Size", "1") - adapter = communicator.createObjectAdapter("TestAdapter") - adapter2 = communicator.createObjectAdapter("ControllerAdapter") - testController = TestI.TestIntfControllerI(adapter) +class Collocated(TestHelper): - adapter.add(TestI.TestIntfI(), Ice.stringToIdentity("test")) - adapter.add(TestI.TestIntfII(), Ice.stringToIdentity("test2")) - #adapter.activate() # Collocated test doesn't need to active the OA + def run(self, args): - adapter2.add(testController, Ice.stringToIdentity("testController")) - #adapter2.activate() # Collocated test doesn't need to active the OA + properties = self.createTestProperties(args) + properties.setProperty("Ice.Warn.AMICallback", "0") + # + # This test kills connections, so we don't want warnings. + # + properties.setProperty("Ice.Warn.Connections", "0") - AllTests.allTests(communicator, True) + with self.initialize(properties=properties) as communicator: - return True + communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") + communicator.getProperties().setProperty("ControllerAdapter.Endpoints", "default -p 12011") + communicator.getProperties().setProperty("ControllerAdapter.ThreadPool.Size", "1") -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter2 = communicator.createObjectAdapter("ControllerAdapter") - initData.properties.setProperty("Ice.Warn.AMICallback", "0"); + testController = TestI.TestIntfControllerI(adapter) - # - # This test kills connections, so we don't want warnings. - # - initData.properties.setProperty("Ice.Warn.Connections", "0"); + adapter.add(TestI.TestIntfI(), Ice.stringToIdentity("test")) + adapter.add(TestI.TestIntfII(), Ice.stringToIdentity("test2")) + # adapter.activate() # Collocated test doesn't need to active the OA - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False + adapter2.add(testController, Ice.stringToIdentity("testController")) + # adapter2.activate() # Collocated test doesn't need to active the OA -sys.exit(not status) + AllTests.allTests(self, communicator, True) diff --git a/python/test/Ice/ami/Server.py b/python/test/Ice/ami/Server.py index 28ef65b1b21..ed659708286 100755 --- a/python/test/Ice/ami/Server.py +++ b/python/test/Ice/ami/Server.py @@ -8,55 +8,44 @@ # # ********************************************************************** -import os, sys, traceback import Ice -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") +import TestI -Ice.loadSlice('"-I' + slice_dir + '" Test.ice') -import Test, TestI -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - communicator.getProperties().setProperty("ControllerAdapter.Endpoints", "default -p 12011") - communicator.getProperties().setProperty("ControllerAdapter.ThreadPool.Size", "1") +class Server(TestHelper): - adapter = communicator.createObjectAdapter("TestAdapter") - adapter2 = communicator.createObjectAdapter("ControllerAdapter") + def run(self, args): - testController = TestI.TestIntfControllerI(adapter) + properties = self.createTestProperties(args) + # + # This test kills connections, so we don't want warnings. + # + properties.setProperty("Ice.Warn.Connections", "0") - adapter.add(TestI.TestIntfI(), Ice.stringToIdentity("test")) - adapter.add(TestI.TestIntfII(), Ice.stringToIdentity("test2")) - adapter.activate() + # + # Limit the recv buffer size, this test relies on the socket + # send() blocking after sending a given amount of data. + # + properties.setProperty("Ice.TCP.RcvSize", "50000") - adapter2.add(testController, Ice.stringToIdentity("testController")) - adapter2.activate() + with self.initialize(properties=properties) as communicator: - communicator.waitForShutdown() - return True + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + communicator.getProperties().setProperty("ControllerAdapter.Endpoints", self.getTestEndpoint(num=1)) + communicator.getProperties().setProperty("ControllerAdapter.ThreadPool.Size", "1") -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter2 = communicator.createObjectAdapter("ControllerAdapter") - # - # This test kills connections, so we don't want warnings. - # - initData.properties.setProperty("Ice.Warn.Connections", "0") + testController = TestI.TestIntfControllerI(adapter) - # - # Limit the recv buffer size, this test relies on the socket - # send() blocking after sending a given amount of data. - # - initData.properties.setProperty("Ice.TCP.RcvSize", "50000") + adapter.add(TestI.TestIntfI(), Ice.stringToIdentity("test")) + adapter.add(TestI.TestIntfII(), Ice.stringToIdentity("test2")) + adapter.activate() - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False + adapter2.add(testController, Ice.stringToIdentity("testController")) + adapter2.activate() -sys.exit(not status) + communicator.waitForShutdown() diff --git a/python/test/Ice/binding/AllTests.py b/python/test/Ice/binding/AllTests.py index 3df81486dc7..9012a055705 100644 --- a/python/test/Ice/binding/AllTests.py +++ b/python/test/Ice/binding/AllTests.py @@ -50,8 +50,8 @@ def deactivate(com, adapters): for p in adapters: com.deactivateObjectAdapter(p) -def allTests(communicator): - ref = "communicator:default -p 12010" +def allTests(helper, communicator): + ref = "communicator:{0}".format(helper.getTestEndpoint()) com = Test.RemoteCommunicatorPrx.uncheckedCast(communicator.stringToProxy(ref)) sys.stdout.write("testing binding with single endpoint... ") diff --git a/python/test/Ice/binding/Client.py b/python/test/Ice/binding/Client.py index ad135d6ede6..74b7105bf20 100755 --- a/python/test/Ice/binding/Client.py +++ b/python/test/Ice/binding/Client.py @@ -8,22 +8,14 @@ # # ********************************************************************** -import os, sys, traceback - -import Ice - -Ice.loadSlice('Test.ice') +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import AllTests -def run(args, communicator): - AllTests.allTests(communicator) - return True -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False +class Client(TestHelper): + + def run(self, args): -sys.exit(not status) + with self.initialize(args) as communicator: + AllTests.allTests(self, communicator) diff --git a/python/test/Ice/binding/Server.py b/python/test/Ice/binding/Server.py index a7f24ce1642..c720f9919ac 100755 --- a/python/test/Ice/binding/Server.py +++ b/python/test/Ice/binding/Server.py @@ -8,27 +8,21 @@ # # ********************************************************************** -import os, sys, traceback - import Ice -Ice.loadSlice('Test.ice') -import Test, TestI +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") +import TestI + + +class Server(TestHelper): -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - adapter = communicator.createObjectAdapter("TestAdapter") - id = Ice.stringToIdentity("communicator") - adapter.add(TestI.RemoteCommunicatorI(), id) - adapter.activate() + def run(self, args): - communicator.waitForShutdown() - return True + with self.initialize(args) as communicator: -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(TestI.RemoteCommunicatorI(), Ice.stringToIdentity("communicator")) + adapter.activate() -sys.exit(not status) + communicator.waitForShutdown() diff --git a/python/test/Ice/blobject/Client.py b/python/test/Ice/blobject/Client.py index f118721e20b..64846c2702f 100755 --- a/python/test/Ice/blobject/Client.py +++ b/python/test/Ice/blobject/Client.py @@ -8,75 +8,63 @@ # # ********************************************************************** -import os, sys, traceback - +from TestHelper import TestHelper +TestHelper.loadSlice('Test.ice') +import sys import Ice -Ice.loadSlice('Test.ice') import Test import RouterI + def test(b): if not b: raise RuntimeError('test assertion failed') -def run(args, communicator, sync): - hello = Test.HelloPrx.checkedCast(communicator.stringToProxy("test:default -p 12010")) - hello.sayHello(False) - hello.sayHello(False, { "_fwd":"o" } ) - test(hello.add(10, 20) == 30) - try: - hello.raiseUE() - test(False) - except Test.UE: - pass - try: - Test.HelloPrx.checkedCast(communicator.stringToProxy("unknown:default -p 12010 -t 10000")) - test(False) - except Ice.ObjectNotExistException: - pass +class Client(TestHelper): + + def allTests(self, communicator, sync): + hello = Test.HelloPrx.checkedCast(communicator.stringToProxy("test:default -p 12010")) + hello.sayHello(False) + hello.sayHello(False, {"_fwd": "o"}) + test(hello.add(10, 20) == 30) + try: + hello.raiseUE() + test(False) + except Test.UE: + pass + + try: + Test.HelloPrx.checkedCast(communicator.stringToProxy("unknown:default -p 12010 -t 10000")) + test(False) + except Ice.ObjectNotExistException: + pass - # First try an object at a non-existent endpoint. - try: - Test.HelloPrx.checkedCast(communicator.stringToProxy("missing:default -p 12000 -t 10000")) - test(False) - except Ice.UnknownLocalException as e: - test(e.unknown.find('ConnectionRefusedException')) - if sync: - hello.shutdown() - return True + # First try an object at a non-existent endpoint. + try: + Test.HelloPrx.checkedCast(communicator.stringToProxy("missing:default -p 12000 -t 10000")) + test(False) + except Ice.UnknownLocalException as e: + test(e.unknown.find('ConnectionRefusedException')) + if sync: + hello.shutdown() -argv = sys.argv[:] # Clone the arguments to use again later + def run(self, args): -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(argv) - initData.properties.setProperty('Ice.Warn.Dispatch', '0') - with Ice.initialize(argv, initData) as communicator: - router = RouterI.RouterI(communicator, False) - sys.stdout.write("testing async blobject... ") - sys.stdout.flush() - status = run(sys.argv, communicator, False) - print("ok") - router.destroy() -except: - traceback.print_exc() - status = False + properties = self.createTestProperties(args) + properties.setProperty('Ice.Warn.Dispatch', '0') + with self.initialize(properties=properties) as communicator: + router = RouterI.RouterI(communicator, False) + sys.stdout.write("testing async blobject... ") + sys.stdout.flush() + self.allTests(communicator, False) + print("ok") + router.destroy() -if status: - try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - initData.properties.setProperty('Ice.Warn.Dispatch', '0') - with Ice.initialize(sys.argv, initData) as communicator: + with self.initialize(properties=properties) as communicator: router = RouterI.RouterI(communicator, True) sys.stdout.write("testing sync blobject... ") sys.stdout.flush() - status = run(sys.argv, communicator, True) + self.allTests(communicator, True) print("ok") router.destroy() - except: - traceback.print_exc() - status = False - -sys.exit(not status) diff --git a/python/test/Ice/blobject/Server.py b/python/test/Ice/blobject/Server.py index b14e881805d..b1bd3095f81 100755 --- a/python/test/Ice/blobject/Server.py +++ b/python/test/Ice/blobject/Server.py @@ -8,12 +8,12 @@ # # ********************************************************************** -import os, sys, traceback - +from TestHelper import TestHelper +TestHelper.loadSlice('Test.ice') import Ice - -Ice.loadSlice('Test.ice') import Test +import time + class TestI(Test.Hello): def sayHello(self, delay, current=None): @@ -29,27 +29,20 @@ class TestI(Test.Hello): def shutdown(self, current=None): current.adapter.getCommunicator().shutdown() -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - adapter = communicator.createObjectAdapter("TestAdapter") - adapter.add(TestI(), Ice.stringToIdentity("test")) - adapter.activate() - communicator.waitForShutdown() - return True - -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - # - # Its possible to have batch oneway requests dispatched after the - # adapter is deactivated due to thread scheduling so we supress - # this warning. - # - initData.properties.setProperty("Ice.Warn.Dispatch", "0"); - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False - -sys.exit(not status) + +class Server(TestHelper): + + def run(self, args): + properties = self.createTestProperties(args) + # + # Its possible to have batch oneway requests dispatched after the + # adapter is deactivated due to thread scheduling so we supress + # this warning. + # + properties.setProperty("Ice.Warn.Dispatch", "0") + with self.initialize(properties=properties) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(TestI(), Ice.stringToIdentity("test")) + adapter.activate() + communicator.waitForShutdown() diff --git a/python/test/Ice/checksum/AllTests.py b/python/test/Ice/checksum/AllTests.py index abaa0862cc5..d264f1f810d 100644 --- a/python/test/Ice/checksum/AllTests.py +++ b/python/test/Ice/checksum/AllTests.py @@ -13,8 +13,8 @@ def test(b): if not b: raise RuntimeError('test assertion failed') -def allTests(communicator): - ref = "test:default -p 12010" +def allTests(helper, communicator): + ref = "test:{0}".format(helper.getTestEndpoint()) base = communicator.stringToProxy(ref) test(base) @@ -55,4 +55,4 @@ def allTests(communicator): print("ok") - return checksum + checksum.shutdown() diff --git a/python/test/Ice/checksum/Client.py b/python/test/Ice/checksum/Client.py index d730b0aac35..0b50e0a5738 100755 --- a/python/test/Ice/checksum/Client.py +++ b/python/test/Ice/checksum/Client.py @@ -8,27 +8,13 @@ # # ********************************************************************** -import os, sys, traceback +from TestHelper import TestHelper +TestHelper.loadSlice("--checksum Test.ice CTypes.ice") +import AllTests -import Ice -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) -Ice.loadSlice("'-I" + slice_dir + "' --checksum Test.ice CTypes.ice") -import Test, AllTests +class Client(TestHelper): -def run(args, communicator): - checksum = AllTests.allTests(communicator) - checksum.shutdown() - return True - -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False - -sys.exit(not status) + def run(self, args): + with self.initialize(args=args) as communicator: + AllTests.allTests(self, communicator) diff --git a/python/test/Ice/checksum/Server.py b/python/test/Ice/checksum/Server.py index 7dc24ab6579..5ac01b24c93 100755 --- a/python/test/Ice/checksum/Server.py +++ b/python/test/Ice/checksum/Server.py @@ -8,17 +8,12 @@ # # ********************************************************************** -import os, sys, traceback - import Ice -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) - -Ice.loadSlice("'-I" + slice_dir + "' --checksum Test.ice STypes.ice") +from TestHelper import TestHelper +TestHelper.loadSlice("--checksum Test.ice STypes.ice") import Test + class ChecksumI(Test.Checksum): def getSliceChecksums(self, current=None): return Ice.sliceChecksums @@ -26,20 +21,15 @@ class ChecksumI(Test.Checksum): def shutdown(self, current=None): current.adapter.getCommunicator().shutdown() -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - adapter = communicator.createObjectAdapter("TestAdapter") - object = ChecksumI() - adapter.add(object, Ice.stringToIdentity("test")) - adapter.activate() - communicator.waitForShutdown() - return True - -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False - -sys.exit(not status) + +class Server(TestHelper): + + def run(self, args): + + with self.initialize(args=args) as communicator: + + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(ChecksumI(), Ice.stringToIdentity("test")) + adapter.activate() + communicator.waitForShutdown() diff --git a/python/test/Ice/custom/AllTests.py b/python/test/Ice/custom/AllTests.py index 2e0750e0bb3..e3c9eb23ce3 100644 --- a/python/test/Ice/custom/AllTests.py +++ b/python/test/Ice/custom/AllTests.py @@ -13,8 +13,8 @@ def test(b): if not b: raise RuntimeError('test assertion failed') -def allTests(communicator): - ref = "test:default -p 12010" +def allTests(helper, communicator): + ref = "test:{0}".format(helper.getTestEndpoint()) base = communicator.stringToProxy(ref) test(base) diff --git a/python/test/Ice/custom/Client.py b/python/test/Ice/custom/Client.py index 192999fae08..31a9ff8479d 100755 --- a/python/test/Ice/custom/Client.py +++ b/python/test/Ice/custom/Client.py @@ -8,22 +8,14 @@ # # ********************************************************************** -import os, sys, traceback +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") +import AllTests -import Ice -Ice.loadSlice('Test.ice') -import Test, AllTests -def run(args, communicator): - custom = AllTests.allTests(communicator) - custom.shutdown() - return True +class Client(TestHelper): -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False - -sys.exit(not status) + def run(self, args): + with self.initialize(args=args) as communicator: + custom = AllTests.allTests(self, communicator) + custom.shutdown() diff --git a/python/test/Ice/custom/Server.py b/python/test/Ice/custom/Server.py index 7716cb78b0f..a917feb2a8c 100755 --- a/python/test/Ice/custom/Server.py +++ b/python/test/Ice/custom/Server.py @@ -8,16 +8,18 @@ # # ********************************************************************** -import os, sys, traceback - -import Ice -Ice.loadSlice('Test.ice') +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") +import sys import Test +import Ice + def test(b): if not b: raise RuntimeError('test assertion failed') + class CustomI(Test.Custom): def opByteString1(self, b1, current=None): if sys.version_info[0] == 2: @@ -89,20 +91,13 @@ class CustomI(Test.Custom): def shutdown(self, current=None): current.adapter.getCommunicator().shutdown() -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - adapter = communicator.createObjectAdapter("TestAdapter") - object = CustomI() - adapter.add(object, Ice.stringToIdentity("test")) - adapter.activate() - communicator.waitForShutdown() - return True - -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False - -sys.exit(not status) + +class Server(TestHelper): + + def run(self, args): + with self.initialize(args=args) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(CustomI(), Ice.stringToIdentity("test")) + adapter.activate() + communicator.waitForShutdown() diff --git a/python/test/Ice/defaultServant/AllTests.py b/python/test/Ice/defaultServant/AllTests.py index 2548916f95d..96c393e59b1 100644 --- a/python/test/Ice/defaultServant/AllTests.py +++ b/python/test/Ice/defaultServant/AllTests.py @@ -13,7 +13,7 @@ def test(b): if not b: raise RuntimeError('test assertion failed') -def allTests(communicator): +def allTests(helper, communicator): oa = communicator.createObjectAdapterWithEndpoints("MyOA", "tcp -h localhost") oa.activate() diff --git a/python/test/Ice/defaultServant/Client.py b/python/test/Ice/defaultServant/Client.py index ad135d6ede6..25e142b7337 100755 --- a/python/test/Ice/defaultServant/Client.py +++ b/python/test/Ice/defaultServant/Client.py @@ -8,22 +8,13 @@ # # ********************************************************************** -import os, sys, traceback - -import Ice - -Ice.loadSlice('Test.ice') +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import AllTests -def run(args, communicator): - AllTests.allTests(communicator) - return True -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False +class Client(TestHelper): -sys.exit(not status) + def run(self, args): + with self.initialize(args=args) as communicator: + AllTests.allTests(self, communicator) diff --git a/python/test/Ice/defaultValue/Client.py b/python/test/Ice/defaultValue/Client.py index f6a761d0058..1e07942d822 100755 --- a/python/test/Ice/defaultValue/Client.py +++ b/python/test/Ice/defaultValue/Client.py @@ -8,21 +8,12 @@ # # ********************************************************************** -import os, sys, traceback - -import Ice - -Ice.loadSlice('Test.ice') +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import AllTests -def run(args): - AllTests.allTests() - return True -try: - status = run(sys.argv) -except: - traceback.print_exc() - status = False +class Client(TestHelper): -sys.exit(not status) + def run(self, args): + AllTests.allTests() diff --git a/python/test/Ice/dispatcher/AllTests.py b/python/test/Ice/dispatcher/AllTests.py index 797c06ec051..171bb6ce0a8 100644 --- a/python/test/Ice/dispatcher/AllTests.py +++ b/python/test/Ice/dispatcher/AllTests.py @@ -51,14 +51,14 @@ class Callback: else: test(Dispatcher.Dispatcher.isDispatcherThread()) -def allTests(communicator, collocated): - sref = "test:default -p 12010" +def allTests(helper, communicator): + sref = "test:{0}".format(helper.getTestEndpoint()) obj = communicator.stringToProxy(sref) test(obj) p = Test.TestIntfPrx.uncheckedCast(obj) - sref = "testController:default -p 12011" + sref = "testController:{0}".format(helper.getTestEndpoint(num=1)) obj = communicator.stringToProxy(sref) test(obj) diff --git a/python/test/Ice/dispatcher/Client.py b/python/test/Ice/dispatcher/Client.py index 6a366f5d6f0..cad129c0831 100755 --- a/python/test/Ice/dispatcher/Client.py +++ b/python/test/Ice/dispatcher/Client.py @@ -8,44 +8,28 @@ # # ********************************************************************** -import os, sys, traceback - import Ice -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) - -Ice.loadSlice("'-I" + slice_dir + "' Test.ice") -import AllTests, Dispatcher - -def test(b): - if not b: - raise RuntimeError('test assertion failed') - -def run(args, communicator): - AllTests.allTests(communicator, False) - return True +import Dispatcher +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") +import AllTests -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - # - # Limit the send buffer size, this test relies on the socket - # send() blocking after sending a given amount of data. - # - initData.properties.setProperty("Ice.TCP.SndSize", "50000"); +class Client(TestHelper): - d = Dispatcher.Dispatcher() - initData.dispatcher = d.dispatch + def run(self, args): + initData = Ice.InitializationData() + initData.properties = self.createTestProperties(args) - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False + # + # Limit the send buffer size, this test relies on the socket + # send() blocking after sending a given amount of data. + # + initData.properties.setProperty("Ice.TCP.SndSize", "50000") + d = Dispatcher.Dispatcher() + initData.dispatcher = d.dispatch -Dispatcher.Dispatcher.terminate() + with self.initialize(initData=initData) as communicator: + AllTests.allTests(self, communicator) -sys.exit(not status) + Dispatcher.Dispatcher.terminate() diff --git a/python/test/Ice/dispatcher/Server.py b/python/test/Ice/dispatcher/Server.py index 2a25110d0c8..0a993705117 100755 --- a/python/test/Ice/dispatcher/Server.py +++ b/python/test/Ice/dispatcher/Server.py @@ -8,59 +8,50 @@ # # ********************************************************************** -import os, sys, traceback import Ice -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") +import TestI +import Dispatcher -Ice.loadSlice('"-I' + slice_dir + '" Test.ice') -import Test, TestI, Dispatcher -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - communicator.getProperties().setProperty("ControllerAdapter.Endpoints", "default -p 12011") - communicator.getProperties().setProperty("ControllerAdapter.ThreadPool.Size", "1") +class Server(TestHelper): - adapter = communicator.createObjectAdapter("TestAdapter") - adapter2 = communicator.createObjectAdapter("ControllerAdapter") + def run(self, args): - testController = TestI.TestIntfControllerI(adapter) + initData = Ice.InitializationData() + initData.properties = self.createTestProperties(args) - adapter.add(TestI.TestIntfI(), Ice.stringToIdentity("test")) - adapter.activate() + # + # This test kills connections, so we don't want warnings. + # + initData.properties.setProperty("Ice.Warn.Connections", "0") - adapter2.add(testController, Ice.stringToIdentity("testController")) - adapter2.activate() + # + # Limit the recv buffer size, this test relies on the socket + # send() blocking after sending a given amount of data. + # + initData.properties.setProperty("Ice.TCP.RcvSize", "50000") - communicator.waitForShutdown() - return True + d = Dispatcher.Dispatcher() + initData.dispatcher = d.dispatch -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) + with self.initialize(initData=initData) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + communicator.getProperties().setProperty("ControllerAdapter.Endpoints", self.getTestEndpoint(num=1)) + communicator.getProperties().setProperty("ControllerAdapter.ThreadPool.Size", "1") - # - # This test kills connections, so we don't want warnings. - # - initData.properties.setProperty("Ice.Warn.Connections", "0") + adapter = communicator.createObjectAdapter("TestAdapter") + adapter2 = communicator.createObjectAdapter("ControllerAdapter") - # - # Limit the recv buffer size, this test relies on the socket - # send() blocking after sending a given amount of data. - # - initData.properties.setProperty("Ice.TCP.RcvSize", "50000") + testController = TestI.TestIntfControllerI(adapter) - d = Dispatcher.Dispatcher() - initData.dispatcher = d.dispatch + adapter.add(TestI.TestIntfI(), Ice.stringToIdentity("test")) + adapter.activate() - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False + adapter2.add(testController, Ice.stringToIdentity("testController")) + adapter2.activate() -Dispatcher.Dispatcher.terminate() + communicator.waitForShutdown() -sys.exit(not status) + Dispatcher.Dispatcher.terminate() diff --git a/python/test/Ice/enums/AllTests.py b/python/test/Ice/enums/AllTests.py index bc5e87d7623..2316faced0e 100644 --- a/python/test/Ice/enums/AllTests.py +++ b/python/test/Ice/enums/AllTests.py @@ -13,8 +13,8 @@ def test(b): if not b: raise RuntimeError('test assertion failed') -def allTests(communicator): - ref = "test:default -p 12010" +def allTests(helper, communicator): + ref = "test:{0}".format(helper.getTestEndpoint()) base = communicator.stringToProxy(ref) test(base) diff --git a/python/test/Ice/enums/Client.py b/python/test/Ice/enums/Client.py index 0e3231048c2..b0b4eb72617 100755 --- a/python/test/Ice/enums/Client.py +++ b/python/test/Ice/enums/Client.py @@ -8,22 +8,14 @@ # # ********************************************************************** -import os, sys, traceback +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") +import AllTests -import Ice -Ice.loadSlice('Test.ice') -import Test, AllTests -def run(args, communicator): - proxy = AllTests.allTests(communicator) - proxy.shutdown() - return True +class Client(TestHelper): -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False - -sys.exit(not status) + def run(self, args): + with self.initialize(args=args) as communicator: + proxy = AllTests.allTests(self, communicator) + proxy.shutdown() diff --git a/python/test/Ice/enums/Server.py b/python/test/Ice/enums/Server.py index a36c9b788d0..003a6a78201 100755 --- a/python/test/Ice/enums/Server.py +++ b/python/test/Ice/enums/Server.py @@ -8,15 +8,11 @@ # # ********************************************************************** -import os, sys, traceback - +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import Ice -Ice.loadSlice('Test.ice') import Test -def test(b): - if not b: - raise RuntimeError('test assertion failed') class TestIntfI(Test.TestIntf): def opByte(self, b1, current=None): @@ -46,20 +42,14 @@ class TestIntfI(Test.TestIntf): def shutdown(self, current=None): current.adapter.getCommunicator().shutdown() -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - adapter = communicator.createObjectAdapter("TestAdapter") - object = TestIntfI() - adapter.add(object, Ice.stringToIdentity("test")) - adapter.activate() - communicator.waitForShutdown() - return True -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False +class Server(TestHelper): + + def run(self, args): -sys.exit(not status) + with self.initialize(args=args) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(TestIntfI(), Ice.stringToIdentity("test")) + adapter.activate() + communicator.waitForShutdown() diff --git a/python/test/Ice/exceptions/AllTests.py b/python/test/Ice/exceptions/AllTests.py index 6639b456870..163caee8ddf 100644 --- a/python/test/Ice/exceptions/AllTests.py +++ b/python/test/Ice/exceptions/AllTests.py @@ -212,7 +212,7 @@ class Callback(CallbackBase): test(False) self.called() -def allTests(communicator): +def allTests(helper, communicator): sys.stdout.write("testing servant registration exceptions... ") sys.stdout.flush() communicator.getProperties().setProperty("TestAdapter1.Endpoints", "tcp -h *") @@ -275,7 +275,7 @@ def allTests(communicator): sys.stdout.write("testing stringToProxy... ") sys.stdout.flush() - ref = "thrower:default -p 12010" + ref = "thrower:{0}".format(helper.getTestEndpoint()) base = communicator.stringToProxy(ref) test(base) print("ok") diff --git a/python/test/Ice/exceptions/Client.py b/python/test/Ice/exceptions/Client.py index f5bd5ee0b17..da3b41dcf0f 100755 --- a/python/test/Ice/exceptions/Client.py +++ b/python/test/Ice/exceptions/Client.py @@ -8,31 +8,17 @@ # # ********************************************************************** -import os, sys, traceback - -import Ice -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) - -Ice.loadSlice('"-I' + slice_dir + '" Test.ice') +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import AllTests -def run(args, communicator): - thrower = AllTests.allTests(communicator) - thrower.shutdown() - return True -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - initData.properties.setProperty("Ice.MessageSizeMax", "10") - initData.properties.setProperty("Ice.Warn.Connections", "0"); - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False +class Client(TestHelper): -sys.exit(not status) + def run(self, args): + properties = self.createTestProperties(args) + properties.setProperty("Ice.MessageSizeMax", "10") + properties.setProperty("Ice.Warn.Connections", "0") + with self.initialize(properties=properties) as communicator: + thrower = AllTests.allTests(self, communicator) + thrower.shutdown() diff --git a/python/test/Ice/exceptions/Collocated.py b/python/test/Ice/exceptions/Collocated.py index 884094c4137..931f85dd36b 100755 --- a/python/test/Ice/exceptions/Collocated.py +++ b/python/test/Ice/exceptions/Collocated.py @@ -8,38 +8,23 @@ # # ********************************************************************** -import os, sys, traceback - import Ice -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) - -Ice.loadSlice('"-I' + slice_dir + '" Test.ice') -import Test, TestI, AllTests - -def run(args, communicator): - properties = communicator.getProperties() - properties.setProperty("Ice.Warn.Dispatch", "0") - properties.setProperty("TestAdapter.Endpoints", "default -p 12010") - adapter = communicator.createObjectAdapter("TestAdapter") - object = TestI.ThrowerI() - adapter.add(object, Ice.stringToIdentity("thrower")) - #adapter.activate() // Don't activate OA to ensure collocation is used. +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") +import TestI +import AllTests - thrower = AllTests.allTests(communicator) - return True +class Collocated(TestHelper): -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - initData.properties.setProperty("Ice.MessageSizeMax", "10") - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False + def run(self, args): + properties = self.createTestProperties(args) + properties.setProperty("Ice.MessageSizeMax", "10") -sys.exit(not status) + with self.initialize(properties=properties) as communicator: + communicator.getProperties().setProperty("Ice.Warn.Dispatch", "0") + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(TestI.ThrowerI(), Ice.stringToIdentity("thrower")) + # adapter.activate() // Don't activate OA to ensure collocation is used. + AllTests.allTests(self, communicator) diff --git a/python/test/Ice/exceptions/Server.py b/python/test/Ice/exceptions/Server.py index 18981a971a7..e08d7d432e6 100755 --- a/python/test/Ice/exceptions/Server.py +++ b/python/test/Ice/exceptions/Server.py @@ -8,46 +8,36 @@ # # ********************************************************************** -import os, sys, traceback - +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import Ice -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) +import TestI + -Ice.loadSlice('"-I' + slice_dir + '" Test.ice') -import Test, TestI +class Server(TestHelper): -def run(args, communicator): - adapter = communicator.createObjectAdapter("TestAdapter") - adapter2 = communicator.createObjectAdapter("TestAdapter2") - adapter3 = communicator.createObjectAdapter("TestAdapter3") - object = TestI.ThrowerI() - adapter.add(object, Ice.stringToIdentity("thrower")) - adapter2.add(object, Ice.stringToIdentity("thrower")) - adapter3.add(object, Ice.stringToIdentity("thrower")) - adapter.activate() - adapter2.activate() - adapter3.activate() - communicator.waitForShutdown() - return True + def run(self, args): + properties = self.createTestProperties(args) + properties.setProperty("Ice.Warn.Dispatch", "0") + properties.setProperty("Ice.Warn.Connections", "0") + properties.setProperty("Ice.MessageSizeMax", "10") -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - initData.properties.setProperty("Ice.Warn.Dispatch", "0") - initData.properties.setProperty("Ice.Warn.Connections", "0"); - initData.properties.setProperty("TestAdapter.Endpoints", "default -p 12010") - initData.properties.setProperty("Ice.MessageSizeMax", "10") - initData.properties.setProperty("TestAdapter2.Endpoints", "default -p 12011") - initData.properties.setProperty("TestAdapter2.MessageSizeMax", "0") - initData.properties.setProperty("TestAdapter3.Endpoints", "default -p 12012") - initData.properties.setProperty("TestAdapter3.MessageSizeMax", "1") - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False + with self.initialize(properties=properties) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint(num=0)) + communicator.getProperties().setProperty("Ice.MessageSizeMax", "10") + communicator.getProperties().setProperty("TestAdapter2.Endpoints", self.getTestEndpoint(num=1)) + communicator.getProperties().setProperty("TestAdapter2.MessageSizeMax", "0") + communicator.getProperties().setProperty("TestAdapter3.Endpoints", self.getTestEndpoint(num=2)) + communicator.getProperties().setProperty("TestAdapter3.MessageSizeMax", "1") -sys.exit(not status) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter2 = communicator.createObjectAdapter("TestAdapter2") + adapter3 = communicator.createObjectAdapter("TestAdapter3") + object = TestI.ThrowerI() + adapter.add(object, Ice.stringToIdentity("thrower")) + adapter2.add(object, Ice.stringToIdentity("thrower")) + adapter3.add(object, Ice.stringToIdentity("thrower")) + adapter.activate() + adapter2.activate() + adapter3.activate() + communicator.waitForShutdown() diff --git a/python/test/Ice/exceptions/ServerAMD.py b/python/test/Ice/exceptions/ServerAMD.py index 3f055709c5b..3c229492356 100755 --- a/python/test/Ice/exceptions/ServerAMD.py +++ b/python/test/Ice/exceptions/ServerAMD.py @@ -8,20 +8,11 @@ # # ********************************************************************** -import os, sys, traceback, array - +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import Ice -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) - -Ice.loadSlice('"-I' + slice_dir + '" Test.ice') import Test -def test(b): - if not b: - raise RuntimeError('test assertion failed') class ThrowerI(Test.Thrower): def shutdown(self, current=None): @@ -150,35 +141,29 @@ class ThrowerI(Test.Thrower): f.set_exception(Test.A()) return f -def run(args, communicator): - adapter = communicator.createObjectAdapter("TestAdapter") - adapter2 = communicator.createObjectAdapter("TestAdapter2") - adapter3 = communicator.createObjectAdapter("TestAdapter3") - object = ThrowerI() - adapter.add(object, Ice.stringToIdentity("thrower")) - adapter2.add(object, Ice.stringToIdentity("thrower")) - adapter3.add(object, Ice.stringToIdentity("thrower")) - adapter.activate() - adapter2.activate() - adapter3.activate() - communicator.waitForShutdown() - return True - -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - initData.properties.setProperty("Ice.Warn.Dispatch", "0") - initData.properties.setProperty("Ice.Warn.Connections", "0"); - initData.properties.setProperty("TestAdapter.Endpoints", "default -p 12010") - initData.properties.setProperty("Ice.MessageSizeMax", "10") - initData.properties.setProperty("TestAdapter2.Endpoints", "default -p 12011") - initData.properties.setProperty("TestAdapter2.MessageSizeMax", "0") - initData.properties.setProperty("TestAdapter3.Endpoints", "default -p 12012") - initData.properties.setProperty("TestAdapter3.MessageSizeMax", "1") - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False - -sys.exit(not status) + +class ServerAMD(TestHelper): + + def run(self, args): + properties = self.createTestProperties(args) + properties.setProperty("Ice.Warn.Dispatch", "0") + properties.setProperty("Ice.Warn.Connections", "0") + properties.setProperty("Ice.MessageSizeMax", "10") + with self.initialize(properties=properties) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") + communicator.getProperties().setProperty("TestAdapter2.Endpoints", "default -p 12011") + communicator.getProperties().setProperty("TestAdapter2.MessageSizeMax", "0") + communicator.getProperties().setProperty("TestAdapter3.Endpoints", "default -p 12012") + communicator.getProperties().setProperty("TestAdapter3.MessageSizeMax", "1") + + adapter = communicator.createObjectAdapter("TestAdapter") + adapter2 = communicator.createObjectAdapter("TestAdapter2") + adapter3 = communicator.createObjectAdapter("TestAdapter3") + object = ThrowerI() + adapter.add(object, Ice.stringToIdentity("thrower")) + adapter2.add(object, Ice.stringToIdentity("thrower")) + adapter3.add(object, Ice.stringToIdentity("thrower")) + adapter.activate() + adapter2.activate() + adapter3.activate() + communicator.waitForShutdown() diff --git a/python/test/Ice/facets/AllTests.py b/python/test/Ice/facets/AllTests.py index b333d80618c..5c6f55efe90 100644 --- a/python/test/Ice/facets/AllTests.py +++ b/python/test/Ice/facets/AllTests.py @@ -16,7 +16,7 @@ def test(b): class EmptyI(Test.Empty): pass -def allTests(communicator): +def allTests(helper, communicator): sys.stdout.write("testing Ice.Admin.Facets property... ") sys.stdout.flush() @@ -90,7 +90,7 @@ def allTests(communicator): sys.stdout.write("testing stringToProxy... ") sys.stdout.flush() - ref = "d:default -p 12010" + ref = "d:{0}".format(helper.getTestEndpoint()) db = communicator.stringToProxy(ref) test(db) print("ok") diff --git a/python/test/Ice/facets/Client.py b/python/test/Ice/facets/Client.py index 6c87cd862c2..2a378682942 100755 --- a/python/test/Ice/facets/Client.py +++ b/python/test/Ice/facets/Client.py @@ -8,23 +8,15 @@ # # ********************************************************************** -import os, sys, traceback - -import Ice - -Ice.loadSlice('Test.ice') +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import AllTests -def run(args, communicator): - g = AllTests.allTests(communicator) - g.shutdown() - return True -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False +class Client(TestHelper): + + def run(self, args): -sys.exit(not status) + with self.initialize(args) as communicator: + g = AllTests.allTests(self, communicator) + g.shutdown() diff --git a/python/test/Ice/facets/Collocated.py b/python/test/Ice/facets/Collocated.py index b5d2481b7b1..78c097a9fbf 100755 --- a/python/test/Ice/facets/Collocated.py +++ b/python/test/Ice/facets/Collocated.py @@ -8,34 +8,25 @@ # # ********************************************************************** -import os, sys, traceback - import Ice -Ice.loadSlice('Test.ice') -import Test, TestI, AllTests +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") +import TestI +import AllTests -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - adapter = communicator.createObjectAdapter("TestAdapter") - d = TestI.DI() - adapter.add(d, Ice.stringToIdentity("d")) - adapter.addFacet(d, Ice.stringToIdentity("d"), "facetABCD") - f = TestI.FI() - adapter.addFacet(f, Ice.stringToIdentity("d"), "facetEF") - h = TestI.HI(communicator) - adapter.addFacet(h, Ice.stringToIdentity("d"), "facetGH") - #adapter.activate() // Don't activate OA to ensure collocation is used. +class Collocated(TestHelper): - AllTests.allTests(communicator) + def run(self, args): - return True + with self.initialize(args=args) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(TestI.DI(), Ice.stringToIdentity("d")) + adapter.addFacet(TestI.DI(), Ice.stringToIdentity("d"), "facetABCD") + adapter.addFacet(TestI.FI(), Ice.stringToIdentity("d"), "facetEF") + adapter.addFacet(TestI.HI(communicator), Ice.stringToIdentity("d"), "facetGH") -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False + # adapter.activate() // Don't activate OA to ensure collocation is used. -sys.exit(not status) + AllTests.allTests(self, communicator) diff --git a/python/test/Ice/facets/Server.py b/python/test/Ice/facets/Server.py index 51ca4c7fe87..b0ac848d50c 100755 --- a/python/test/Ice/facets/Server.py +++ b/python/test/Ice/facets/Server.py @@ -8,33 +8,22 @@ # # ********************************************************************** -import os, sys, traceback - import Ice -Ice.loadSlice('Test.ice') -import Test, TestI - -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - adapter = communicator.createObjectAdapter("TestAdapter") - d = TestI.DI() - adapter.add(d, Ice.stringToIdentity("d")) - adapter.addFacet(d, Ice.stringToIdentity("d"), "facetABCD") - f = TestI.FI() - adapter.addFacet(f, Ice.stringToIdentity("d"), "facetEF") - h = TestI.HI(communicator) - adapter.addFacet(h, Ice.stringToIdentity("d"), "facetGH") +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") +import TestI - adapter.activate() - communicator.waitForShutdown() - return True +class Server(TestHelper): -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False + def run(self, args): + with self.initialize(args) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(TestI.DI(), Ice.stringToIdentity("d")) + adapter.addFacet(TestI.DI(), Ice.stringToIdentity("d"), "facetABCD") + adapter.addFacet(TestI.FI(), Ice.stringToIdentity("d"), "facetEF") + adapter.addFacet(TestI.HI(communicator), Ice.stringToIdentity("d"), "facetGH") -sys.exit(not status) + adapter.activate() + communicator.waitForShutdown() diff --git a/python/test/Ice/faultTolerance/AllTests.py b/python/test/Ice/faultTolerance/AllTests.py index ddee51dc48b..cfd6d4421d8 100644 --- a/python/test/Ice/faultTolerance/AllTests.py +++ b/python/test/Ice/faultTolerance/AllTests.py @@ -60,12 +60,12 @@ class Callback(CallbackBase): def pid(self): return self._pid -def allTests(communicator, ports): +def allTests(helper, communicator, ports): sys.stdout.write("testing stringToProxy... ") sys.stdout.flush() ref = "test" - for p in ports: - ref = ref + ":default -p " + str(p) + for i in range(len(ports)): + ref += ":{0}".format(helper.getTestEndpoint(num=i)) base = communicator.stringToProxy(ref) test(base) print("ok") diff --git a/python/test/Ice/faultTolerance/Client.py b/python/test/Ice/faultTolerance/Client.py index 9673fd3b41d..b1f9d8cb981 100755 --- a/python/test/Ice/faultTolerance/Client.py +++ b/python/test/Ice/faultTolerance/Client.py @@ -8,53 +8,30 @@ # # ********************************************************************** -import os, sys, traceback -import Ice, AllTests +from TestHelper import TestHelper +import AllTests -def test(b): - if not b: - raise RuntimeError('test assertion failed') -def usage(n): - sys.stderr.write("Usage: " + n + " port...\n") +class Client(TestHelper): -def run(args, communicator): - ports = [] - for arg in args[1:]: - if arg[0] == '-': - sys.stderr.write(args[0] + ": unknown option `" + arg + "'\n") - usage(args[0]) - return False + def run(self, args): - ports.append(12010 + int(arg)) + properties = self.createTestProperties(args) - if len(ports) == 0: - sys.stderr.write(args[0] + ": no ports specified\n") - usage(args[0]) - return False + # + # This test aborts servers, so we don't want warnings. + # + properties.setProperty('Ice.Warn.Connections', '0') - try: - AllTests.allTests(communicator, ports) - except: - traceback.print_exc() - test(False) + ports = [] + for arg in args: + if arg[0] == '-': + raise RuntimeError("unknown option `" + arg + "'") + ports.append(int(arg)) - return True + if len(ports) == 0: + raise RuntimeError("no ports specified") -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - - # - # This test aborts servers, so we don't want warnings. - # - initData.properties.setProperty('Ice.Warn.Connections', '0') - - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False - -sys.exit(not status) + with self.initialize(properties=properties) as communicator: + AllTests.allTests(self, communicator, ports) diff --git a/python/test/Ice/faultTolerance/Server.py b/python/test/Ice/faultTolerance/Server.py index 7595f572415..3da4d0fdd4f 100755 --- a/python/test/Ice/faultTolerance/Server.py +++ b/python/test/Ice/faultTolerance/Server.py @@ -8,21 +8,20 @@ # # ********************************************************************** -import os, sys, traceback - +import os import Ice -Ice.loadSlice('Test.ice') +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import Test -def usage(n): - sys.stderr.write("Usage: " + n + " port\n") class TestI(Test.TestIntf): + def shutdown(self, current=None): current.adapter.getCommunicator().shutdown() def abort(self, current=None): - sys.stdout.write("aborting...") + print("aborting...") os._exit(0) def idempotentAbort(self, current=None): @@ -31,48 +30,35 @@ class TestI(Test.TestIntf): def pid(self, current=None): return os.getpid() -def run(args, communicator): - port = 0 - for arg in args[1:]: - if arg[0] == '-': - sys.stderr.write(args[0] + ": unknown option `" + arg + "'\n") - usage(args[0]) - return False - if port > 0: - sys.stderr.write(args[0] + ": only one port can be specified\n") - usage(args[0]) - return False - - port = 12010 + int(arg) - - if port <= 0: - sys.stderr.write(args[0] + ": no port specified\n") - usage(args[0]) - return False - - endpts = "default -p " + str(port) - communicator.getProperties().setProperty("TestAdapter.Endpoints", endpts) - adapter = communicator.createObjectAdapter("TestAdapter") - object = TestI() - adapter.add(object, Ice.stringToIdentity("test")) - adapter.activate() - communicator.waitForShutdown() - return True - -try: - # - # In this test, we need a longer server idle time, otherwise - # our test servers may time out before they are used in the - # test. - # - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - initData.properties.setProperty("Ice.ServerIdleTime", "120") # Two minutes. - - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False - -sys.exit(not status) + +class Server(TestHelper): + + def run(self, args): + properties = self.createTestProperties(args) + # + # In this test, we need a longer server idle time, otherwise + # our test servers may time out before they are used in the + # test. + # + properties.setProperty("Ice.ServerIdleTime", "120") # Two minutes. + + port = 0 + for arg in args: + + if arg[0] == '-': + raise RuntimeError("unknown option `" + arg + "'") + + if port > 0: + raise RuntimeError("only one port can be specified") + + port = int(arg) + + if port <= 0: + raise RuntimeError("no port specified\n") + + with self.initialize(properties=properties) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint(num=port)) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(TestI(), Ice.stringToIdentity("test")) + adapter.activate() + communicator.waitForShutdown() diff --git a/python/test/Ice/info/AllTests.py b/python/test/Ice/info/AllTests.py index f38cf804e18..9bec16441f3 100644 --- a/python/test/Ice/info/AllTests.py +++ b/python/test/Ice/info/AllTests.py @@ -25,7 +25,7 @@ def getTCPConnectionInfo(info): return info info = info.underlying -def allTests(communicator): +def allTests(helper, communicator): sys.stdout.write("testing proxy endpoint information... ") sys.stdout.flush() @@ -126,16 +126,18 @@ def allTests(communicator): print("ok") - base = communicator.stringToProxy("test:default -p 12010:udp -p 12010") + base = communicator.stringToProxy("test:{0}:{1}".format(helper.getTestEndpoint(), + helper.getTestEndpoint(protocol="udp"))) testIntf = Test.TestIntfPrx.checkedCast(base) sys.stdout.write("test connection endpoint information... ") sys.stdout.flush() defaultHost = communicator.getProperties().getProperty("Ice.Default.Host") + port = helper.getTestPort() tcpinfo = getTCPEndpointInfo(base.ice_getConnection().getEndpoint().getInfo()) - test(tcpinfo.port == 12010) + test(tcpinfo.port == port) test(not tcpinfo.compress) test(tcpinfo.host == defaultHost) diff --git a/python/test/Ice/info/Client.py b/python/test/Ice/info/Client.py index f80ab96ba16..25e142b7337 100755 --- a/python/test/Ice/info/Client.py +++ b/python/test/Ice/info/Client.py @@ -8,32 +8,13 @@ # # ********************************************************************** -import os, sys, traceback - -import Ice -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) - -Ice.loadSlice("'-I" + slice_dir + "' Test.ice") +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import AllTests -def test(b): - if not b: - raise RuntimeError('test assertion failed') - -def run(args, communicator): - AllTests.allTests(communicator) - return True -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False +class Client(TestHelper): -sys.exit(not status) + def run(self, args): + with self.initialize(args=args) as communicator: + AllTests.allTests(self, communicator) diff --git a/python/test/Ice/info/Server.py b/python/test/Ice/info/Server.py index db88b8aeb88..37f69e4fa9c 100755 --- a/python/test/Ice/info/Server.py +++ b/python/test/Ice/info/Server.py @@ -8,32 +8,21 @@ # # ********************************************************************** -import os, sys, traceback - +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import Ice -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) +import TestI -Ice.loadSlice("'-I" + slice_dir + "' Test.ice") -import Test, TestI -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010:udp -p 12010") - adapter = communicator.createObjectAdapter("TestAdapter") - adapter.add(TestI.MyDerivedClassI(), Ice.stringToIdentity("test")) - adapter.activate() - communicator.waitForShutdown() - return True +class Server(TestHelper): -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False + def run(self, args): -sys.exit(not status) + with self.initialize(args=args) as communicator: + communicator.getProperties().setProperty( + "TestAdapter.Endpoints", "{0}:{1}".format(self.getTestEndpoint(), + self.getTestEndpoint(protocol="udp"))) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(TestI.MyDerivedClassI(), Ice.stringToIdentity("test")) + adapter.activate() + communicator.waitForShutdown() diff --git a/python/test/Ice/inheritance/AllTests.py b/python/test/Ice/inheritance/AllTests.py index 523b56ad326..5daf288a4d2 100644 --- a/python/test/Ice/inheritance/AllTests.py +++ b/python/test/Ice/inheritance/AllTests.py @@ -13,10 +13,10 @@ def test(b): if not b: raise RuntimeError('test assertion failed') -def allTests(communicator): +def allTests(helper, communicator): sys.stdout.write("testing stringToProxy... ") sys.stdout.flush() - ref = "initial:default -p 12010" + ref = "initial:{0}".format(helper.getTestEndpoint()) base = communicator.stringToProxy(ref) test(base) print("ok") diff --git a/python/test/Ice/inheritance/Client.py b/python/test/Ice/inheritance/Client.py index 888ae5518aa..996c87991f5 100755 --- a/python/test/Ice/inheritance/Client.py +++ b/python/test/Ice/inheritance/Client.py @@ -8,22 +8,15 @@ # # ********************************************************************** -import os, sys, traceback - -import Ice -Ice.loadSlice('Test.ice') +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import AllTests -def run(args, communicator): - initial = AllTests.allTests(communicator) - initial.shutdown() - return True -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False +class Client(TestHelper): + + def run(self, args): -sys.exit(not status) + with self.initialize(args=args) as communicator: + initial = AllTests.allTests(self, communicator) + initial.shutdown() diff --git a/python/test/Ice/inheritance/Collocated.py b/python/test/Ice/inheritance/Collocated.py index 4b245debe7f..87384ad637f 100755 --- a/python/test/Ice/inheritance/Collocated.py +++ b/python/test/Ice/inheritance/Collocated.py @@ -8,28 +8,19 @@ # # ********************************************************************** -import os, sys, traceback - +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import Ice -Ice.loadSlice('Test.ice') -import Test, TestI, AllTests - -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - adapter = communicator.createObjectAdapter("TestAdapter") - object = TestI.InitialI(adapter) - adapter.add(object, Ice.stringToIdentity("initial")) - #adapter.activate() // Don't activate OA to ensure collocation is used. - - AllTests.allTests(communicator) +import TestI +import AllTests - return True -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False +class Collocated(TestHelper): -sys.exit(not status) + def run(self, args): + with self.initialize(args=args) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(TestI.InitialI(adapter), Ice.stringToIdentity("initial")) + # adapter.activate() // Don't activate OA to ensure collocation is used. + AllTests.allTests(self, communicator) diff --git a/python/test/Ice/inheritance/Server.py b/python/test/Ice/inheritance/Server.py index f13c08ceefa..4b2109fd2d5 100755 --- a/python/test/Ice/inheritance/Server.py +++ b/python/test/Ice/inheritance/Server.py @@ -8,26 +8,19 @@ # # ********************************************************************** -import os, sys, traceback - +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") +import TestI import Ice -Ice.loadSlice('Test.ice') -import Test, TestI -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - adapter = communicator.createObjectAdapter("TestAdapter") - object = TestI.InitialI(adapter) - adapter.add(object, Ice.stringToIdentity("initial")) - adapter.activate() - communicator.waitForShutdown() - return True -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False +class Server(TestHelper): + + def run(self, args): -sys.exit(not status) + with self.initialize(args=args) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(TestI.InitialI(adapter), Ice.stringToIdentity("initial")) + adapter.activate() + communicator.waitForShutdown() diff --git a/python/test/Ice/location/AllTests.py b/python/test/Ice/location/AllTests.py index 4066c885d71..6cd0733062f 100644 --- a/python/test/Ice/location/AllTests.py +++ b/python/test/Ice/location/AllTests.py @@ -17,7 +17,8 @@ def test(b): if not b: raise RuntimeError('test assertion failed') -def allTests(communicator, ref): +def allTests(helper, communicator): + ref = "ServerManager:{0}".format(helper.getTestEndpoint()) manager = Test.ServerManagerPrx.checkedCast(communicator.stringToProxy(ref)) locator = communicator.getDefaultLocator() test(manager) diff --git a/python/test/Ice/location/Client.py b/python/test/Ice/location/Client.py index ea7e0ae5dec..538340ac709 100755 --- a/python/test/Ice/location/Client.py +++ b/python/test/Ice/location/Client.py @@ -8,33 +8,15 @@ # # ********************************************************************** -import os, sys, traceback +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") +import AllTests -import Ice -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) -Ice.loadSlice("'-I" + slice_dir + "' Test.ice") -import Test, AllTests +class Client(TestHelper): -def test(b): - if not b: - raise RuntimeError('test assertion failed') - -def run(args, communicator): - AllTests.allTests(communicator, "ServerManager:default -p 12010") - return True - -try: - data = Ice.InitializationData() - data.properties = Ice.createProperties(sys.argv) - data.properties.setProperty("Ice.Default.Locator", "locator:default -p 12010") - with Ice.initialize(sys.argv, data) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False - -sys.exit(not status) + def run(self, args): + properties = self.createTestProperties(args) + properties.setProperty("Ice.Default.Locator", "locator:{0}".format(self.getTestEndpoint(properties=properties))) + with self.initialize(properties=properties) as communicator: + AllTests.allTests(self, communicator) diff --git a/python/test/Ice/location/Server.py b/python/test/Ice/location/Server.py index 9ae243b45be..52475e42314 100755 --- a/python/test/Ice/location/Server.py +++ b/python/test/Ice/location/Server.py @@ -8,17 +8,12 @@ # # ********************************************************************** -import os, sys, traceback - import Ice -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) - -Ice.loadSlice("'-I" + slice_dir + "' Test.ice") +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import Test + class ServerLocatorRegistry(Test.TestLocatorRegistry): def __init__(self): self._adapters = {} @@ -56,6 +51,7 @@ class ServerLocatorRegistry(Test.TestLocatorRegistry): raise Ice.ObjectNotFoundException() return self._objects[id] + class ServerLocator(Test.TestLocator): def __init__(self, registry, registryPrx): @@ -77,6 +73,7 @@ class ServerLocator(Test.TestLocator): def getRequestCount(self, current=None): return self._requestCount + class ServerManagerI(Test.ServerManager): def __init__(self, registry, initData): self._registry = registry @@ -97,7 +94,7 @@ class ServerManagerI(Test.ServerManager): # its endpoints with the locator and create references containing # the adapter id instead of the endpoints. # - serverCommunicator = Ice.initialize(data=initData) + serverCommunicator = Ice.initialize(self._initData) self._communicators.append(serverCommunicator) def getTestEndpoint(): @@ -143,10 +140,12 @@ class ServerManagerI(Test.ServerManager): i.destroy() current.adapter.getCommunicator().shutdown() + class HelloI(Test.Hello): def sayHello(self, current=None): pass + class TestI(Test.TestIntf): def __init__(self, adapter, adapter2, registry): self._adapter1 = adapter @@ -170,45 +169,38 @@ class TestI(Test.TestIntf): except Ice.NotRegisteredException: self._registry.addObject(self._adapter1.add(self._adapter2.remove(id), id)) -def run(args, communicator, initData): - # - # Register the server manager. The server manager creates a new - # 'server' (a server isn't a different process, it's just a new - # communicator and object adapter). - # - properties = communicator.getProperties() - properties.setProperty("Ice.ThreadPool.Server.Size", "2") - properties.setProperty("ServerManager.Endpoints", "default -p 12010") - - adapter = communicator.createObjectAdapter("ServerManager") - - # - # We also register a sample server locator which implements the - # locator interface, this locator is used by the clients and the - # 'servers' created with the server manager interface. - # - registry = ServerLocatorRegistry() - registry.addObject(adapter.createProxy(Ice.stringToIdentity("ServerManager"))) - object = ServerManagerI(registry, initData) - adapter.add(object, Ice.stringToIdentity("ServerManager")) - - registryPrx = Ice.LocatorRegistryPrx.uncheckedCast(adapter.add(registry, Ice.stringToIdentity("registry"))) - - locator = ServerLocator(registry, registryPrx) - adapter.add(locator, Ice.stringToIdentity("locator")) - - adapter.activate() - communicator.waitForShutdown() - - return True - -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator, initData) -except: - traceback.print_exc() - status = False - -sys.exit(not status) + +class Server(TestHelper): + + def run(self, args): + + initData = Ice.InitializationData() + initData.properties = self.createTestProperties(args) + + with self.initialize(initData=initData) as communicator: + # + # Register the server manager. The server manager creates a new + # 'server' (a server isn't a different process, it's just a new + # communicator and object adapter). + # + communicator.getProperties().setProperty("Ice.ThreadPool.Server.Size", "2") + communicator.getProperties().setProperty("ServerManager.Endpoints", self.getTestEndpoint()) + + adapter = communicator.createObjectAdapter("ServerManager") + + # + # We also register a sample server locator which implements the + # locator interface, this locator is used by the clients and the + # 'servers' created with the server manager interface. + # + registry = ServerLocatorRegistry() + registry.addObject(adapter.createProxy(Ice.stringToIdentity("ServerManager"))) + adapter.add(ServerManagerI(registry, initData), Ice.stringToIdentity("ServerManager")) + + registryPrx = Ice.LocatorRegistryPrx.uncheckedCast(adapter.add(registry, Ice.stringToIdentity("registry"))) + + locator = ServerLocator(registry, registryPrx) + adapter.add(locator, Ice.stringToIdentity("locator")) + + adapter.activate() + communicator.waitForShutdown() diff --git a/python/test/Ice/objects/AllTests.py b/python/test/Ice/objects/AllTests.py index b9f00d1572a..5c254de44de 100644 --- a/python/test/Ice/objects/AllTests.py +++ b/python/test/Ice/objects/AllTests.py @@ -39,7 +39,7 @@ def test(b): if not b: raise RuntimeError('test assertion failed') -def allTests(communicator): +def allTests(helper, communicator): communicator.getValueFactoryManager().add(MyValueFactory, '::Test::B') communicator.getValueFactoryManager().add(MyValueFactory, '::Test::C') communicator.getValueFactoryManager().add(MyValueFactory, '::Test::D') @@ -53,7 +53,7 @@ def allTests(communicator): sys.stdout.write("testing stringToProxy... ") sys.stdout.flush() - ref = "initial:default -p 12010" + ref = "initial:{0}".format(helper.getTestEndpoint()) base = communicator.stringToProxy(ref) test(base) print("ok") diff --git a/python/test/Ice/objects/Client.py b/python/test/Ice/objects/Client.py index c56e826f89e..ffb88703206 100755 --- a/python/test/Ice/objects/Client.py +++ b/python/test/Ice/objects/Client.py @@ -8,23 +8,14 @@ # # ********************************************************************** -import os, sys, traceback - -import Ice -Ice.loadSlice('Test.ice') -Ice.loadSlice('ClientPrivate.ice') +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice ClientPrivate.ice") import AllTests -def run(args, communicator): - initial = AllTests.allTests(communicator) - initial.shutdown() - return True -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False +class Client(TestHelper): -sys.exit(not status) + def run(self, args): + with self.initialize(args=args) as communicator: + initial = AllTests.allTests(self, communicator) + initial.shutdown() diff --git a/python/test/Ice/objects/Collocated.py b/python/test/Ice/objects/Collocated.py index 457c739ce81..d796bd3a3fe 100755 --- a/python/test/Ice/objects/Collocated.py +++ b/python/test/Ice/objects/Collocated.py @@ -8,37 +8,25 @@ # # ********************************************************************** -import os, sys, traceback - +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice ClientPrivate.ice") import Ice -Ice.loadSlice('Test.ice') -Ice.loadSlice('ClientPrivate.ice') -import Test, TestI, AllTests - -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - adapter = communicator.createObjectAdapter("TestAdapter") - initial = TestI.InitialI(adapter) - adapter.add(initial, Ice.stringToIdentity("initial")) - uoet = TestI.UnexpectedObjectExceptionTestI() - adapter.add(uoet, Ice.stringToIdentity("uoet")) - #adapter.activate() // Don't activate OA to ensure collocation is used. - - AllTests.allTests(communicator) - - # We must call shutdown even in the collocated case for cyclic dependency cleanup - initial.shutdown() - - return True - -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - initData.properties.setProperty("Ice.Warn.Dispatch", "0"); - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False - -sys.exit(not status) +import TestI +import AllTests + + +class Collocated(TestHelper): + + def run(self, args): + properties = self.createTestProperties(args) + properties.setProperty("Ice.Warn.Dispatch", "0") + with self.initialize(properties=properties) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + adapter = communicator.createObjectAdapter("TestAdapter") + initial = TestI.InitialI(adapter) + adapter.add(initial, Ice.stringToIdentity("initial")) + adapter.add(TestI.UnexpectedObjectExceptionTestI(), Ice.stringToIdentity("uoet")) + # adapter.activate() // Don't activate OA to ensure collocation is used. + AllTests.allTests(self, communicator) + # We must call shutdown even in the collocated case for cyclic dependency cleanup + initial.shutdown() diff --git a/python/test/Ice/objects/Server.py b/python/test/Ice/objects/Server.py index 088e49905a3..13f49662daa 100755 --- a/python/test/Ice/objects/Server.py +++ b/python/test/Ice/objects/Server.py @@ -8,12 +8,11 @@ # # ********************************************************************** -import os, sys, traceback - +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice ServerPrivate.ice") +import TestI import Ice -Ice.loadSlice('Test.ice') -Ice.loadSlice('ServerPrivate.ice') -import Test, TestI + def MyValueFactory(type): if type == '::Test::I': @@ -22,31 +21,23 @@ def MyValueFactory(type): return TestI.JI() elif type == '::Test::H': return TestI.HI() - assert(False) # Should never be reached - -def run(args, communicator): - communicator.getValueFactoryManager().add(MyValueFactory, '::Test::I') - communicator.getValueFactoryManager().add(MyValueFactory, '::Test::J') - communicator.getValueFactoryManager().add(MyValueFactory, '::Test::H') + assert(False) # Should never be reached - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - adapter = communicator.createObjectAdapter("TestAdapter") - initial = TestI.InitialI(adapter) - adapter.add(initial, Ice.stringToIdentity("initial")) - uoet = TestI.UnexpectedObjectExceptionTestI() - adapter.add(uoet, Ice.stringToIdentity("uoet")) - adapter.activate() - communicator.waitForShutdown() - return True -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - initData.properties.setProperty("Ice.Warn.Dispatch", "0"); - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False +class Server(TestHelper): -sys.exit(not status) + def run(self, args): + properties = self.createTestProperties(args) + properties.setProperty("Ice.Warn.Dispatch", "0") + with self.initialize(properties=properties) as communicator: + communicator.getValueFactoryManager().add(MyValueFactory, '::Test::I') + communicator.getValueFactoryManager().add(MyValueFactory, '::Test::J') + communicator.getValueFactoryManager().add(MyValueFactory, '::Test::H') + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + adapter = communicator.createObjectAdapter("TestAdapter") + initial = TestI.InitialI(adapter) + adapter.add(initial, Ice.stringToIdentity("initial")) + uoet = TestI.UnexpectedObjectExceptionTestI() + adapter.add(uoet, Ice.stringToIdentity("uoet")) + adapter.activate() + communicator.waitForShutdown() diff --git a/python/test/Ice/operations/AllTests.py b/python/test/Ice/operations/AllTests.py index fdd81e0808c..b63362ff341 100644 --- a/python/test/Ice/operations/AllTests.py +++ b/python/test/Ice/operations/AllTests.py @@ -14,8 +14,8 @@ def test(b): if not b: raise RuntimeError('test assertion failed') -def allTests(communicator): - ref = "test:default -p 12010" +def allTests(helper, communicator): + ref = "test:{0}".format(helper.getTestEndpoint()) base = communicator.stringToProxy(ref) cl = Test.MyClassPrx.checkedCast(base) derived = Test.MyDerivedClassPrx.checkedCast(cl) @@ -70,4 +70,11 @@ def allTests(communicator): BatchOnewaysAMI.batchOneways(derived) print("ok") - return cl + sys.stdout.write("testing server shutdown... ") + sys.stdout.flush() + cl.shutdown() + try: + cl.ice_timeout(100).ice_ping() # Use timeout to speed up testing on Windows + test(False) + except Ice.LocalException: + print("ok") diff --git a/python/test/Ice/operations/Client.py b/python/test/Ice/operations/Client.py index 0cec40edbd9..9835a2ccac9 100755 --- a/python/test/Ice/operations/Client.py +++ b/python/test/Ice/operations/Client.py @@ -8,54 +8,21 @@ # # ********************************************************************** -import os, sys, traceback -import Ice - -import Ice -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) - -Ice.loadSlice("'-I" + slice_dir + "' Test.ice") +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import AllTests -def test(b): - if not b: - raise RuntimeError('test assertion failed') - -def run(args, communicator): - myClass = AllTests.allTests(communicator) - - sys.stdout.write("testing server shutdown... ") - sys.stdout.flush() - myClass.shutdown() - try: - myClass.ice_timeout(100).ice_ping(); # Use timeout to speed up testing on Windows - test(False) - except Ice.LocalException: - print("ok") - - return True -try: - # - # In this test, we need at least two threads in the - # client side thread pool for nested AMI. - # - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - initData.properties.setProperty('Ice.ThreadPool.Client.Size', '2') - initData.properties.setProperty('Ice.ThreadPool.Client.SizeWarn', '0') - initData.properties.setProperty("Ice.BatchAutoFlushSize", "100") +class Client(TestHelper): - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) - # Test multiple destroy calls - communicator.destroy() - communicator.destroy() -except: - traceback.print_exc() - status = False + def run(self, args): + properties = self.createTestProperties(args) + properties.setProperty('Ice.ThreadPool.Client.Size', '2') + properties.setProperty('Ice.ThreadPool.Client.SizeWarn', '0') + properties.setProperty("Ice.BatchAutoFlushSize", "100") -sys.exit(not status) + with self.initialize(properties=properties) as communicator: + AllTests.allTests(self, communicator) + # Test multiple destroy calls + communicator.destroy() + communicator.destroy() diff --git a/python/test/Ice/operations/Collocated.py b/python/test/Ice/operations/Collocated.py index e5a6deace06..099c09806bc 100755 --- a/python/test/Ice/operations/Collocated.py +++ b/python/test/Ice/operations/Collocated.py @@ -8,40 +8,23 @@ # # ********************************************************************** -import os, sys, traceback - +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import Ice -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) - -Ice.loadSlice('"-I' + slice_dir + '" Test.ice') -import Test, TestI, AllTests - -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - adapter = communicator.createObjectAdapter("TestAdapter") - prx = adapter.add(TestI.MyDerivedClassI(), Ice.stringToIdentity("test")) - #adapter.activate() // Don't activate OA to ensure collocation is used. - - if prx.ice_getConnection(): - raise RuntimeError("collocation doesn't work") - - cl = AllTests.allTests(communicator) - - return True - -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - - initData.properties.setProperty("Ice.BatchAutoFlushSize", "100") - - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False - -sys.exit(not status) +import TestI +import AllTests + + +class Collocated(TestHelper): + + def run(self, args): + properties = self.createTestProperties(args) + properties.setProperty("Ice.BatchAutoFlushSize", "100") + with self.initialize(properties=properties) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + adapter = communicator.createObjectAdapter("TestAdapter") + prx = adapter.add(TestI.MyDerivedClassI(), Ice.stringToIdentity("test")) + # adapter.activate() // Don't activate OA to ensure collocation is used. + if prx.ice_getConnection(): + raise RuntimeError("collocation doesn't work") + AllTests.allTests(self, communicator) diff --git a/python/test/Ice/operations/Server.py b/python/test/Ice/operations/Server.py index 173e4419de7..f5de973acb6 100755 --- a/python/test/Ice/operations/Server.py +++ b/python/test/Ice/operations/Server.py @@ -8,37 +8,26 @@ # # ********************************************************************** -import os, sys, traceback +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import Ice -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) +import TestI -Ice.loadSlice('"-I' + slice_dir + '" Test.ice') -import Test, TestI -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - adapter = communicator.createObjectAdapter("TestAdapter") - adapter.add(TestI.MyDerivedClassI(), Ice.stringToIdentity("test")) - adapter.activate() - communicator.waitForShutdown() - return True +class Server(TestHelper): -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - # - # Its possible to have batch oneway requests dispatched after the - # adapter is deactivated due to thread scheduling so we supress - # this warning. - # - initData.properties.setProperty("Ice.Warn.Dispatch", "0"); - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False + def run(self, args): + properties = self.createTestProperties(args) + # + # Its possible to have batch oneway requests dispatched after the + # adapter is deactivated due to thread scheduling so we supress + # this warning. + # + properties.setProperty("Ice.Warn.Dispatch", "0") -sys.exit(not status) + with self.initialize(properties=properties) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(TestI.MyDerivedClassI(), Ice.stringToIdentity("test")) + adapter.activate() + communicator.waitForShutdown() diff --git a/python/test/Ice/operations/ServerAMD.py b/python/test/Ice/operations/ServerAMD.py index 0fb5b35becf..00fff796d5c 100755 --- a/python/test/Ice/operations/ServerAMD.py +++ b/python/test/Ice/operations/ServerAMD.py @@ -8,42 +8,37 @@ # # ********************************************************************** -import os, sys, traceback, threading, time - +import sys # -# We want to test coroutines but older versions of Python cannot load a source file that uses the -# async/await keywords, so we have two versions of MyDerivedClassI. +# We want to test coroutines but older versions of Python cannot +# load a source file that uses the async/await keywords, so we +# have two versions of MyDerivedClassI. # -if sys.version_info >= (3,5): +if sys.version_info >= (3, 5): from TestAMDCoroI import MyDerivedClassI else: from TestAMDI import MyDerivedClassI + +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import Ice -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) -Ice.loadSlice("'-I" + slice_dir + "' Test.ice") -import Test -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - adapter = communicator.createObjectAdapter("TestAdapter") - adapter.add(MyDerivedClassI(), Ice.stringToIdentity("test")) - adapter.activate() - communicator.waitForShutdown() - return True +class ServerAMD(TestHelper): -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - initData.properties.setProperty("Ice.Warn.Dispatch", "0"); - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False + def run(self, args): + properties = self.createTestProperties(args) + # + # Its possible to have batch oneway requests dispatched after the + # adapter is deactivated due to thread scheduling so we supress + # this warning. + # + properties.setProperty("Ice.Warn.Dispatch", "0") -sys.exit(not status) + with self.initialize(properties=properties) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(MyDerivedClassI(), Ice.stringToIdentity("test")) + adapter.activate() + communicator.waitForShutdown() diff --git a/python/test/Ice/optional/AllTests.py b/python/test/Ice/optional/AllTests.py index 9d2ae3da261..c4ab914f39f 100644 --- a/python/test/Ice/optional/AllTests.py +++ b/python/test/Ice/optional/AllTests.py @@ -13,10 +13,10 @@ def test(b): if not b: raise RuntimeError('test assertion failed') -def allTests(communicator): +def allTests(helper, communicator): sys.stdout.write("testing stringToProxy... ") sys.stdout.flush() - ref = "initial:default -p 12010" + ref = "initial:{0}".format(helper.getTestEndpoint()) base = communicator.stringToProxy(ref) test(base) print("ok") diff --git a/python/test/Ice/optional/Client.py b/python/test/Ice/optional/Client.py index 21e57ae961c..ec1329d8b18 100755 --- a/python/test/Ice/optional/Client.py +++ b/python/test/Ice/optional/Client.py @@ -8,22 +8,14 @@ # # ********************************************************************** -import os, sys, traceback - -import Ice -Ice.loadSlice('--all -I. ClientPrivate.ice') +from TestHelper import TestHelper +TestHelper.loadSlice("--all -I. ClientPrivate.ice") import AllTests -def run(args, communicator): - initial = AllTests.allTests(communicator) - initial.shutdown() - return True -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False +class Client(TestHelper): -sys.exit(not status) + def run(self, args): + with self.initialize(args=args) as communicator: + initial = AllTests.allTests(self, communicator) + initial.shutdown() diff --git a/python/test/Ice/optional/Server.py b/python/test/Ice/optional/Server.py index e97ec1b44bc..b6856bed6f6 100755 --- a/python/test/Ice/optional/Server.py +++ b/python/test/Ice/optional/Server.py @@ -8,12 +8,12 @@ # # ********************************************************************** -import os, sys, traceback - +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import Ice -Ice.loadSlice('Test.ice') import Test + class InitialI(Test.Initial): def shutdown(self, current=None): @@ -186,21 +186,15 @@ class InitialI(Test.Initial): def supportsNullOptional(self, current=None): return True -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - adapter = communicator.createObjectAdapter("TestAdapter") - initial = InitialI() - adapter.add(initial, Ice.stringToIdentity("initial")) - adapter.activate() - communicator.waitForShutdown() - return True +class Server(TestHelper): -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False + def run(self, args): + with self.initialize(args=args) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + adapter = communicator.createObjectAdapter("TestAdapter") + initial = InitialI() + adapter.add(initial, Ice.stringToIdentity("initial")) + adapter.activate() -sys.exit(not status) + communicator.waitForShutdown() diff --git a/python/test/Ice/optional/ServerAMD.py b/python/test/Ice/optional/ServerAMD.py index c09a6843f42..f154cce322b 100755 --- a/python/test/Ice/optional/ServerAMD.py +++ b/python/test/Ice/optional/ServerAMD.py @@ -8,12 +8,12 @@ # # ********************************************************************** -import os, sys, traceback - +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import Ice -Ice.loadSlice('Test.ice') import Test + class InitialI(Test.Initial): def shutdown(self, current=None): @@ -192,21 +192,15 @@ class InitialI(Test.Initial): def supportsNullOptional(self, current=None): return Ice.Future.completed(True) -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - adapter = communicator.createObjectAdapter("TestAdapter") - initial = InitialI() - adapter.add(initial, Ice.stringToIdentity("initial")) - adapter.activate() - communicator.waitForShutdown() - return True +class ServerAMD(TestHelper): -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False + def run(self, args): + with self.initialize(args=args) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + adapter = communicator.createObjectAdapter("TestAdapter") + initial = InitialI() + adapter.add(initial, Ice.stringToIdentity("initial")) + adapter.activate() -sys.exit(not status) + communicator.waitForShutdown() diff --git a/python/test/Ice/packagemd/AllTests.py b/python/test/Ice/packagemd/AllTests.py index 035b1f9dbcf..3934e453707 100644 --- a/python/test/Ice/packagemd/AllTests.py +++ b/python/test/Ice/packagemd/AllTests.py @@ -13,10 +13,11 @@ def test(b): if not b: raise RuntimeError('test assertion failed') -def allTests(communicator): +def allTests(helper, communicator): + sys.stdout.write("testing stringToProxy... ") sys.stdout.flush() - ref = "initial:default -p 12010" + ref = "initial:{0}".format(helper.getTestEndpoint()) base = communicator.stringToProxy(ref) test(base) print("ok") diff --git a/python/test/Ice/packagemd/Client.py b/python/test/Ice/packagemd/Client.py index 327b68dadb1..5cd23baeff5 100755 --- a/python/test/Ice/packagemd/Client.py +++ b/python/test/Ice/packagemd/Client.py @@ -8,31 +8,16 @@ # # ********************************************************************** -import os, sys, traceback -import Ice - -import Ice - -Ice.loadSlice("--all -I. Test.ice") +from TestHelper import TestHelper +TestHelper.loadSlice("--all -I. Test.ice") import AllTests -def test(b): - if not b: - raise RuntimeError('test assertion failed') - -def run(args, communicator): - initial = AllTests.allTests(communicator) - initial.shutdown() - return True -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - initData.properties.setProperty('Ice.Warn.Dispatch', '0') - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False +class Client(TestHelper): -sys.exit(not status) + def run(self, args): + properties = self.createTestProperties(args) + properties.setProperty('Ice.Warn.Dispatch', '0') + with self.initialize(properties=properties) as communicator: + initial = AllTests.allTests(self, communicator) + initial.shutdown() diff --git a/python/test/Ice/packagemd/Server.py b/python/test/Ice/packagemd/Server.py index 324c881ae58..04aae06b2f0 100755 --- a/python/test/Ice/packagemd/Server.py +++ b/python/test/Ice/packagemd/Server.py @@ -8,11 +8,14 @@ # # ********************************************************************** -import os, sys, traceback - +from TestHelper import TestHelper +TestHelper.loadSlice('--all -I. Test.ice') +import Test +import Test1 +import testpkg +import modpkg import Ice -Ice.loadSlice('--all -I. Test.ice') -import Test, Test1, testpkg, modpkg + class InitialI(Test.Initial): @@ -67,21 +70,14 @@ class InitialI(Test.Initial): def shutdown(self, current): current.adapter.getCommunicator().shutdown() -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - adapter = communicator.createObjectAdapter("TestAdapter") - initial = InitialI() - adapter.add(initial, Ice.stringToIdentity("initial")) - adapter.activate() - communicator.waitForShutdown() - return True +class Server(TestHelper): -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False + def run(self, args): -sys.exit(not status) + with self.initialize(args=args) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(InitialI(), Ice.stringToIdentity("initial")) + adapter.activate() + communicator.waitForShutdown() diff --git a/python/test/Ice/properties/Client.py b/python/test/Ice/properties/Client.py index bdcd129c949..8c05215706b 100644 --- a/python/test/Ice/properties/Client.py +++ b/python/test/Ice/properties/Client.py @@ -9,14 +9,17 @@ # # ********************************************************************** -import os, sys, traceback +import sys import Ice +from TestHelper import TestHelper + def test(b): if not b: raise RuntimeError('test assertion failed') -class Client(Ice.Application): + +class App(Ice.Application): def run(self, args): properties = self.communicator().getProperties() test(properties.getProperty("Ice.Trace.Network") == "1") @@ -25,58 +28,62 @@ class Client(Ice.Application): test(properties.getProperty("Ice.ProgramName") == "PropertiesClient") test(self.appName() == properties.getProperty("Ice.ProgramName")) -sys.stdout.write("testing load properties from UTF-8 path... ") -sys.stdout.flush() -properties = Ice.createProperties() -properties.load("./config/ä¸å›½_client.config") -test(properties.getProperty("Ice.Trace.Network") == "1") -test(properties.getProperty("Ice.Trace.Protocol") == "1") -test(properties.getProperty("Config.Path") == "./config/ä¸å›½_client.config") -test(properties.getProperty("Ice.ProgramName") == "PropertiesClient") -print("ok") -sys.stdout.write("testing load properties from UTF-8 path using Ice::Application... ") -sys.stdout.flush() -c = Client() -c.main(sys.argv, "./config/ä¸å›½_client.config") -print("ok") -sys.stdout.write("testing using Ice.Config with multiple config files... ") -sys.stdout.flush() -properties = Ice.createProperties(["--Ice.Config=config/config.1, config/config.2, config/config.3"]) -test(properties.getProperty("Config1") == "Config1") -test(properties.getProperty("Config2") == "Config2") -test(properties.getProperty("Config3") == "Config3") -print("ok") +class Client(TestHelper): + + def run(sef, args): + sys.stdout.write("testing load properties from UTF-8 path... ") + sys.stdout.flush() + properties = Ice.createProperties() + properties.load("./config/ä¸å›½_client.config") + test(properties.getProperty("Ice.Trace.Network") == "1") + test(properties.getProperty("Ice.Trace.Protocol") == "1") + test(properties.getProperty("Config.Path") == "./config/ä¸å›½_client.config") + test(properties.getProperty("Ice.ProgramName") == "PropertiesClient") + print("ok") -sys.stdout.write("testing configuration file escapes... ") -sys.stdout.flush() -properties = Ice.createProperties(["--Ice.Config=config/escapes.cfg"]) + sys.stdout.write("testing load properties from UTF-8 path using Ice::Application... ") + sys.stdout.flush() + app = App() + app.main(args, "./config/ä¸å›½_client.config") + print("ok") -props = { "Foo\tBar":"3", - "Foo\\tBar":"4", - "Escape\\ Space":"2", - "Prop1":"1", - "Prop2":"2", - "Prop3":"3", - "My Prop1":"1", - "My Prop2":"2", - "My.Prop1":"a property", - "My.Prop2":"a property", - "My.Prop3":" a property ", - "My.Prop4":" a property ", - "My.Prop5":"a \\ property", - "foo=bar":"1", - "foo#bar":"2", - "foo bar":"3", - "A":"1", - "B":"2 3 4", - "C":"5=#6", - "AServer":"\\\\server\\dir", - "BServer":"\\server\\dir"}; + sys.stdout.write("testing using Ice.Config with multiple config files... ") + sys.stdout.flush() + properties = Ice.createProperties(["--Ice.Config=config/config.1, config/config.2, config/config.3"]) + test(properties.getProperty("Config1") == "Config1") + test(properties.getProperty("Config2") == "Config2") + test(properties.getProperty("Config3") == "Config3") + print("ok") -for k in props.keys(): - test(properties.getProperty(k) == props[k]) + sys.stdout.write("testing configuration file escapes... ") + sys.stdout.flush() + properties = Ice.createProperties(["--Ice.Config=config/escapes.cfg"]) -print("ok") + props = { + "Foo\tBar": "3", + "Foo\\tBar": "4", + "Escape\\ Space": "2", + "Prop1": "1", + "Prop2": "2", + "Prop3": "3", + "My Prop1": "1", + "My Prop2": "2", + "My.Prop1": "a property", + "My.Prop2": "a property", + "My.Prop3": " a property ", + "My.Prop4": " a property ", + "My.Prop5": "a \\ property", + "foo=bar": "1", + "foo#bar": "2", + "foo bar": "3", + "A": "1", + "B": "2 3 4", + "C": "5=#6", + "AServer": "\\\\server\\dir", + "BServer": "\\server\\dir" + } -sys.exit(0) + for k in props.keys(): + test(properties.getProperty(k) == props[k]) + print("ok") diff --git a/python/test/Ice/proxy/AllTests.py b/python/test/Ice/proxy/AllTests.py index 3d514a32669..20a2a7176ae 100644 --- a/python/test/Ice/proxy/AllTests.py +++ b/python/test/Ice/proxy/AllTests.py @@ -13,7 +13,7 @@ def test(b): if not b: raise RuntimeError('test assertion failed') -def allTests(communicator, collocated): +def allTests(helper, communicator, collocated): sys.stdout.write("testing stringToProxy... ") sys.stdout.flush() @@ -25,7 +25,7 @@ def allTests(communicator, collocated): p = communicator.propertyToProxy('bogus') test(p == None) - ref = "test:default -p 12010" + ref = "test:{0}".format(helper.getTestEndpoint()) base = communicator.stringToProxy(ref) test(base) @@ -199,7 +199,7 @@ def allTests(communicator, collocated): sys.stdout.flush() prop = communicator.getProperties() propertyPrefix = "Foo.Proxy" - prop.setProperty(propertyPrefix, "test:default -p 12010") + prop.setProperty(propertyPrefix, "test:{0}".format(helper.getTestEndpoint())) b1 = communicator.propertyToProxy(propertyPrefix) test(b1.ice_getIdentity().name == "test" and len(b1.ice_getIdentity().category) == 0 and \ len(b1.ice_getAdapterId()) == 0 and len(b1.ice_getFacet()) == 0) @@ -694,16 +694,16 @@ def allTests(communicator, collocated): sys.stdout.write("testing encoding versioning... ") sys.stdout.flush() - ref20 = "test -e 2.0:default -p 12010"; + ref20 = "test -e 2.0:{0}".format(helper.getTestEndpoint()) cl20 = Test.MyClassPrx.uncheckedCast(communicator.stringToProxy(ref20)); try: - cl20.ice_ping(); - test(false); + cl20.ice_ping() + test(False) except Ice.UnsupportedEncodingException: # Server 2.0 endpoint doesn't support 1.1 version. pass - ref10 = "test -e 1.0:default -p 12010" + ref10 = "test -e 1.0:{0}".format(helper.getTestEndpoint()) cl10 = Test.MyClassPrx.uncheckedCast(communicator.stringToProxy(ref10)) cl10.ice_ping() cl10.ice_encodingVersion(Ice.Encoding_1_0).ice_ping() @@ -711,7 +711,7 @@ def allTests(communicator, collocated): # 1.3 isn't supported but since a 1.3 proxy supports 1.1, the # call will use the 1.1 encoding - ref13 = "test -e 1.3:default -p 12010" + ref13 = "test -e 1.3:{0}".format(helper.getTestEndpoint()) cl13 = Test.MyClassPrx.uncheckedCast(communicator.stringToProxy(ref13)) cl13.ice_ping() diff --git a/python/test/Ice/proxy/Client.py b/python/test/Ice/proxy/Client.py index 8f7871fd61d..1bde5dc2a0e 100755 --- a/python/test/Ice/proxy/Client.py +++ b/python/test/Ice/proxy/Client.py @@ -8,34 +8,14 @@ # # ********************************************************************** -import os, sys, traceback - -import Ice -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) - -Ice.loadSlice("'-I" + slice_dir + "' Test.ice") +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import AllTests -def test(b): - if not b: - raise RuntimeError('test assertion failed') - -def run(args, communicator): - myClass = AllTests.allTests(communicator, False) - myClass.shutdown() - - return True -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False +class Client(TestHelper): -sys.exit(not status) + def run(self, args): + with self.initialize(args) as communicator: + myClass = AllTests.allTests(self, communicator, False) + myClass.shutdown() diff --git a/python/test/Ice/proxy/Collocated.py b/python/test/Ice/proxy/Collocated.py index 8e351a2a558..b046e694289 100755 --- a/python/test/Ice/proxy/Collocated.py +++ b/python/test/Ice/proxy/Collocated.py @@ -8,34 +8,20 @@ # # ********************************************************************** -import os, sys, traceback - +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import Ice -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) - -Ice.loadSlice("'-I" + slice_dir + "' Test.ice") -import Test, TestI, AllTests - -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - adapter = communicator.createObjectAdapter("TestAdapter") - adapter.add(TestI.MyDerivedClassI(), Ice.stringToIdentity("test")) - #adapter.activate() // Don't activate OA to ensure collocation is used. +import TestI +import AllTests - AllTests.allTests(communicator, True) - return True +class Collocated(TestHelper): -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False + def run(self, args): -sys.exit(not status) + with self.initialize(args=args) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(TestI.MyDerivedClassI(), Ice.stringToIdentity("test")) + # adapter.activate() // Don't activate OA to ensure collocation is used. + AllTests.allTests(self, communicator, True) diff --git a/python/test/Ice/scope/AllTests.py b/python/test/Ice/scope/AllTests.py index b7552d179d5..c043794436f 100644 --- a/python/test/Ice/scope/AllTests.py +++ b/python/test/Ice/scope/AllTests.py @@ -15,10 +15,10 @@ def test(b): raise RuntimeError('test assertion failed') -def allTests(communicator): +def allTests(helper, communicator): sys.stdout.write("test same Slice type name in different scopes... ") sys.stdout.flush() - i1 = Test.IPrx.checkedCast(communicator.stringToProxy("i1:default -p 12010")) + i1 = Test.IPrx.checkedCast(communicator.stringToProxy("i1:{0}".format(helper.getTestEndpoint()))) s1 = Test.S(0) @@ -57,7 +57,7 @@ def allTests(communicator): test(cmap2["a"].s == s1) test(cmap3["a"].s == s1) - i2 = Test.Inner.Inner2.IPrx.checkedCast(communicator.stringToProxy("i2:default -p 12010")) + i2 = Test.Inner.Inner2.IPrx.checkedCast(communicator.stringToProxy("i2:{0}".format(helper.getTestEndpoint()))) s1 = Test.Inner.Inner2.S(0) @@ -96,7 +96,7 @@ def allTests(communicator): test(cmap2["a"].s == s1) test(cmap3["a"].s == s1) - i3 = Test.Inner.IPrx.checkedCast(communicator.stringToProxy("i3:default -p 12010")) + i3 = Test.Inner.IPrx.checkedCast(communicator.stringToProxy("i3:{0}".format(helper.getTestEndpoint()))) s1 = Test.Inner.Inner2.S(0) @@ -135,7 +135,7 @@ def allTests(communicator): test(cmap2["a"].s == s1) test(cmap3["a"].s == s1) - i4 = Inner.Test.Inner2.IPrx.checkedCast(communicator.stringToProxy("i4:default -p 12010")) + i4 = Inner.Test.Inner2.IPrx.checkedCast(communicator.stringToProxy("i4:{0}".format(helper.getTestEndpoint()))) s1 = Test.S(0) diff --git a/python/test/Ice/scope/Client.py b/python/test/Ice/scope/Client.py index c09de20efc6..25e142b7337 100755 --- a/python/test/Ice/scope/Client.py +++ b/python/test/Ice/scope/Client.py @@ -8,21 +8,13 @@ # # ********************************************************************** -import os, sys, traceback +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") +import AllTests -import Ice -Ice.loadSlice('Test.ice') -import Test, AllTests -def run(args, communicator): - AllTests.allTests(communicator) - return True +class Client(TestHelper): -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False - -sys.exit(not status) + def run(self, args): + with self.initialize(args=args) as communicator: + AllTests.allTests(self, communicator) diff --git a/python/test/Ice/scope/Server.py b/python/test/Ice/scope/Server.py index c3a70e62c03..9d708d843d4 100755 --- a/python/test/Ice/scope/Server.py +++ b/python/test/Ice/scope/Server.py @@ -8,12 +8,11 @@ # # ********************************************************************** -import os, sys, traceback - -import Ice -Ice.loadSlice('Test.ice') +from TestHelper import TestHelper +TestHelper.loadSlice('Test.ice') import Test import Inner +import Ice class I1(Test.I): @@ -112,23 +111,15 @@ class I4(Inner.Test.Inner2.I): current.adapter.getCommunicator().shutdown() -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - adapter = communicator.createObjectAdapter("TestAdapter") - adapter.add(I1(), Ice.stringToIdentity("i1")) - adapter.add(I2(), Ice.stringToIdentity("i2")) - adapter.add(I3(), Ice.stringToIdentity("i3")) - adapter.add(I4(), Ice.stringToIdentity("i4")) - adapter.activate() - communicator.waitForShutdown() - return True - - -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False +class Server(TestHelper): -sys.exit(not status) + def run(self, args): + with self.initialize(args) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(I1(), Ice.stringToIdentity("i1")) + adapter.add(I2(), Ice.stringToIdentity("i2")) + adapter.add(I3(), Ice.stringToIdentity("i3")) + adapter.add(I4(), Ice.stringToIdentity("i4")) + adapter.activate() + communicator.waitForShutdown() diff --git a/python/test/Ice/servantLocator/AllTests.py b/python/test/Ice/servantLocator/AllTests.py index 930aa7bb889..4c860a80c31 100644 --- a/python/test/Ice/servantLocator/AllTests.py +++ b/python/test/Ice/servantLocator/AllTests.py @@ -13,7 +13,7 @@ def test(b): if not b: raise RuntimeError('test assertion failed') -def testExceptions(obj, collocated): +def testExceptions(obj): try: obj.requestFailedException() @@ -64,10 +64,7 @@ def testExceptions(obj, collocated): obj.localException() test(False) except Ice.UnknownLocalException as ex: - test(not collocated) test(ex.unknown.find("Ice.SocketException") >= 0 or ex.unknown.find("Ice::SocketException") >= 0) - except SocketException: - test(collocated) except: test(False) @@ -127,10 +124,10 @@ def testExceptions(obj, collocated): except: test(False) -def allTests(communicator, collocated): +def allTests(helper, communicator): sys.stdout.write("testing stringToProxy... ") sys.stdout.flush() - base = communicator.stringToProxy("asm:default -p 12010") + base = communicator.stringToProxy("asm:{0}".format(helper.getTestEndpoint())) test(base) print("ok") @@ -144,7 +141,7 @@ def allTests(communicator, collocated): sys.stdout.write("testing ice_ids... ") sys.stdout.flush() try: - obj = communicator.stringToProxy("category/locate:default -p 12010") + obj = communicator.stringToProxy("category/locate:{0}".format(helper.getTestEndpoint())) obj.ice_ids() test(False) except Ice.UnknownUserException as ex: @@ -153,7 +150,7 @@ def allTests(communicator, collocated): test(False) try: - obj = communicator.stringToProxy("category/finished:default -p 12010") + obj = communicator.stringToProxy("category/finished:{0}".format(helper.getTestEndpoint())) obj.ice_ids() test(False) except Ice.UnknownUserException as ex: @@ -164,47 +161,49 @@ def allTests(communicator, collocated): sys.stdout.write("testing servant locator... ") sys.stdout.flush() - base = communicator.stringToProxy("category/locate:default -p 12010") + base = communicator.stringToProxy("category/locate:{0}".format(helper.getTestEndpoint())) obj = Test.TestIntfPrx.checkedCast(base) try: - Test.TestIntfPrx.checkedCast(communicator.stringToProxy("category/unknown:default -p 12010")) + Test.TestIntfPrx.checkedCast( + communicator.stringToProxy("category/unknown:{0}".format(helper.getTestEndpoint()))) except Ice.ObjectNotExistException: pass print("ok") sys.stdout.write("testing default servant locator... ") sys.stdout.flush() - base = communicator.stringToProxy("anothercat/locate:default -p 12010") + base = communicator.stringToProxy("anothercat/locate:{0}".format(helper.getTestEndpoint())) obj = Test.TestIntfPrx.checkedCast(base) base = communicator.stringToProxy("locate:default -p 12010") obj = Test.TestIntfPrx.checkedCast(base) try: - Test.TestIntfPrx.checkedCast(communicator.stringToProxy("anothercat/unknown:default -p 12010")) + Test.TestIntfPrx.checkedCast( + communicator.stringToProxy("anothercat/unknown:{0}".format(helper.getTestEndpoint()))) except Ice.ObjectNotExistException: pass try: - Test.TestIntfPrx.checkedCast(communicator.stringToProxy("unknown:default -p 12010")) + Test.TestIntfPrx.checkedCast(communicator.stringToProxy("unknown:{0}".format(helper.getTestEndpoint()))) except Ice.ObjectNotExistException: pass print("ok") sys.stdout.write("testing locate exceptions... ") sys.stdout.flush() - base = communicator.stringToProxy("category/locate:default -p 12010") + base = communicator.stringToProxy("category/locate:{0}".format(helper.getTestEndpoint())) obj = Test.TestIntfPrx.checkedCast(base) - testExceptions(obj, collocated) + testExceptions(obj) print("ok") sys.stdout.write("testing finished exceptions... ") sys.stdout.flush() - base = communicator.stringToProxy("category/finished:default -p 12010") + base = communicator.stringToProxy("category/finished:{0}".format(helper.getTestEndpoint())) obj = Test.TestIntfPrx.checkedCast(base) - testExceptions(obj, collocated) + testExceptions(obj) print("ok") sys.stdout.write("testing servant locator removal... ") sys.stdout.flush() - base = communicator.stringToProxy("test/activation:default -p 12010") + base = communicator.stringToProxy("test/activation:{0}".format(helper.getTestEndpoint())) activation = Test.TestActivationPrx.checkedCast(base) activation.activateServantLocator(False) try: diff --git a/python/test/Ice/servantLocator/Client.py b/python/test/Ice/servantLocator/Client.py index 86d5f0b8dd9..4c588c1e8b2 100755 --- a/python/test/Ice/servantLocator/Client.py +++ b/python/test/Ice/servantLocator/Client.py @@ -8,17 +8,14 @@ # # ********************************************************************** -import os, sys +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") +import AllTests -import Ice -Ice.loadSlice('Test.ice') -import Test, AllTests -class TestClient(Ice.Application): - def run(self, args): - obj = AllTests.allTests(self.communicator(), False) - obj.shutdown() - return 0 +class Client(TestHelper): -app = TestClient() -sys.exit(app.main(sys.argv)) + def run(self, args): + with self.initialize(args=args) as communicator: + obj = AllTests.allTests(self, communicator) + obj.shutdown() diff --git a/python/test/Ice/servantLocator/Collocated.py b/python/test/Ice/servantLocator/Collocated.py index 77d3dc12967..061b032435d 100755 --- a/python/test/Ice/servantLocator/Collocated.py +++ b/python/test/Ice/servantLocator/Collocated.py @@ -8,29 +8,29 @@ # # ********************************************************************** -import os, sys, traceback, time - +from TestHelper import TestHelper +TestHelper.loadSlice('Test.ice') import Ice -Ice.loadSlice('Test.ice') -import Test, TestI, AllTests, TestActivationI +import TestI +import AllTests +import TestActivationI -class TestServer(Ice.Application): - def run(self, args): - self.communicator().getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - self.communicator().getProperties().setProperty("Ice.Warn.Dispatch", "0") - adapter = self.communicator().createObjectAdapter("TestAdapter") - #adapter.activate() // Don't activate OA to ensure collocation is used. - adapter.addServantLocator(TestI.ServantLocatorI("category"), "category") - adapter.addServantLocator(TestI.ServantLocatorI(""), "") - adapter.add(TestI.TestI(), Ice.stringToIdentity("asm")) - adapter.add(TestActivationI.TestActivationI(), Ice.stringToIdentity("test/activation")) +class Collocated(TestHelper): + + def run(self, args): + with self.initialize(args=args) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + communicator.getProperties().setProperty("Ice.Warn.Dispatch", "0") - AllTests.allTests(self.communicator(), False) + adapter = communicator.createObjectAdapter("TestAdapter") + # adapter.activate() // Don't activate OA to ensure collocation is used. + adapter.addServantLocator(TestI.ServantLocatorI("category"), "category") + adapter.addServantLocator(TestI.ServantLocatorI(""), "") + adapter.add(TestI.TestI(), Ice.stringToIdentity("asm")) + adapter.add(TestActivationI.TestActivationI(), Ice.stringToIdentity("test/activation")) - adapter.deactivate() - adapter.waitForDeactivate() - return 0 + AllTests.allTests(self, communicator) -app = TestServer() -sys.exit(app.main(sys.argv)) + adapter.deactivate() + adapter.waitForDeactivate() diff --git a/python/test/Ice/servantLocator/Server.py b/python/test/Ice/servantLocator/Server.py index bba67c364e2..6df66582edc 100755 --- a/python/test/Ice/servantLocator/Server.py +++ b/python/test/Ice/servantLocator/Server.py @@ -8,26 +8,25 @@ # # ********************************************************************** -import os, sys, traceback, time - +from TestHelper import TestHelper +TestHelper.loadSlice('Test.ice') import Ice -Ice.loadSlice('Test.ice') -import Test, TestI, TestActivationI +import TestI +import TestActivationI -class TestServer(Ice.Application): - def run(self, args): - self.communicator().getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - self.communicator().getProperties().setProperty("Ice.Warn.Dispatch", "0") - adapter = self.communicator().createObjectAdapter("TestAdapter") - adapter.addServantLocator(TestI.ServantLocatorI("category"), "category") - adapter.addServantLocator(TestI.ServantLocatorI(""), "") - adapter.add(TestI.TestI(), Ice.stringToIdentity("asm")) - adapter.add(TestActivationI.TestActivationI(), Ice.stringToIdentity("test/activation")) +class Server(TestHelper): + + def run(self, args): + with self.initialize(args=args) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + communicator.getProperties().setProperty("Ice.Warn.Dispatch", "0") - adapter.activate() - adapter.waitForDeactivate() - return 0 + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.addServantLocator(TestI.ServantLocatorI("category"), "category") + adapter.addServantLocator(TestI.ServantLocatorI(""), "") + adapter.add(TestI.TestI(), Ice.stringToIdentity("asm")) + adapter.add(TestActivationI.TestActivationI(), Ice.stringToIdentity("test/activation")) -app = TestServer() -sys.exit(app.main(sys.argv)) + adapter.activate() + adapter.waitForDeactivate() diff --git a/python/test/Ice/servantLocator/ServerAMD.py b/python/test/Ice/servantLocator/ServerAMD.py index d7e24ae2816..a8879fafd0a 100755 --- a/python/test/Ice/servantLocator/ServerAMD.py +++ b/python/test/Ice/servantLocator/ServerAMD.py @@ -8,26 +8,25 @@ # # ********************************************************************** -import os, sys, traceback, time - +from TestHelper import TestHelper +TestHelper.loadSlice('Test.ice') import Ice -Ice.loadSlice('Test.ice') -import Test, TestAMDI, TestActivationAMDI +import TestAMDI +import TestActivationAMDI -class TestServer(Ice.Application): - def run(self, args): - self.communicator().getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - self.communicator().getProperties().setProperty("Ice.Warn.Dispatch", "0") - adapter = self.communicator().createObjectAdapter("TestAdapter") - adapter.addServantLocator(TestAMDI.ServantLocatorI("category"), "category") - adapter.addServantLocator(TestAMDI.ServantLocatorI(""), "") - adapter.add(TestAMDI.TestI(), Ice.stringToIdentity("asm")) - adapter.add(TestActivationAMDI.TestActivationAMDI(), Ice.stringToIdentity("test/activation")) +class ServerAMD(TestHelper): + + def run(self, args): + with self.initialize(args=args) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + communicator.getProperties().setProperty("Ice.Warn.Dispatch", "0") - adapter.activate() - adapter.waitForDeactivate() - return 0 + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.addServantLocator(TestAMDI.ServantLocatorI("category"), "category") + adapter.addServantLocator(TestAMDI.ServantLocatorI(""), "") + adapter.add(TestAMDI.TestI(), Ice.stringToIdentity("asm")) + adapter.add(TestActivationAMDI.TestActivationAMDI(), Ice.stringToIdentity("test/activation")) -app = TestServer() -sys.exit(app.main(sys.argv)) + adapter.activate() + adapter.waitForDeactivate() diff --git a/python/test/Ice/slicing/exceptions/AllTests.py b/python/test/Ice/slicing/exceptions/AllTests.py index eba36fc17cc..9dc2054c036 100644 --- a/python/test/Ice/slicing/exceptions/AllTests.py +++ b/python/test/Ice/slicing/exceptions/AllTests.py @@ -222,8 +222,8 @@ class RelayI(Test.Relay): ex.p2 = ex.p1 raise ex -def allTests(communicator): - obj = communicator.stringToProxy("Test:default -p 12010") +def allTests(helper, communicator): + obj = communicator.stringToProxy("Test:{0}".format(helper.getTestEndpoint())) t = Test.TestIntfPrx.checkedCast(obj) sys.stdout.write("base... ") diff --git a/python/test/Ice/slicing/exceptions/Client.py b/python/test/Ice/slicing/exceptions/Client.py index 6826dcd1889..cb8e7d513cd 100755 --- a/python/test/Ice/slicing/exceptions/Client.py +++ b/python/test/Ice/slicing/exceptions/Client.py @@ -8,20 +8,14 @@ # # ********************************************************************** -import os, sys, traceback +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") +import AllTests -import Ice, AllTests -def run(args, communicator): - Test = AllTests.allTests(communicator) - Test.shutdown() - return True +class Client(TestHelper): -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False - -sys.exit(not status) + def run(self, args): + with self.initialize(args=args) as communicator: + initial = AllTests.allTests(self, communicator) + initial.shutdown() diff --git a/python/test/Ice/slicing/exceptions/Server.py b/python/test/Ice/slicing/exceptions/Server.py index 4ade2ca8d9c..c29a5c86979 100755 --- a/python/test/Ice/slicing/exceptions/Server.py +++ b/python/test/Ice/slicing/exceptions/Server.py @@ -8,11 +8,12 @@ # # ********************************************************************** -import os, sys, traceback +from TestHelper import TestHelper +TestHelper.loadSlice("-I. --all ServerPrivate.ice") import Ice -Ice.loadSlice('-I. --all ServerPrivate.ice') import Test + class TestI(Test.TestIntf): def shutdown(self, current=None): current.adapter.getCommunicator().shutdown() @@ -155,22 +156,15 @@ class TestI(Test.TestIntf): p = Test.RelayPrx.uncheckedCast(current.con.createProxy(r.ice_getIdentity())) p.unknownPreservedAsKnownPreserved() -def run(args, communicator): - properties = communicator.getProperties() - properties.setProperty("Ice.Warn.Dispatch", "0") - properties.setProperty("TestAdapter.Endpoints", "default -p 12010 -t 10000") - adapter = communicator.createObjectAdapter("TestAdapter") - object = TestI() - adapter.add(object, Ice.stringToIdentity("Test")) - adapter.activate() - communicator.waitForShutdown() - return True - -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False - -sys.exit(not status) + +class Server(TestHelper): + def run(self, args): + properties = self.createTestProperties(args) + properties.setProperty("Ice.Warn.Dispatch", "0") + with self.initialize(properties=properties) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", + "{0} -t 10000".format(self.getTestEndpoint())) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(TestI(), Ice.stringToIdentity("Test")) + adapter.activate() + communicator.waitForShutdown() diff --git a/python/test/Ice/slicing/exceptions/ServerAMD.py b/python/test/Ice/slicing/exceptions/ServerAMD.py index 73ab20b8eaa..f497895516d 100755 --- a/python/test/Ice/slicing/exceptions/ServerAMD.py +++ b/python/test/Ice/slicing/exceptions/ServerAMD.py @@ -8,13 +8,19 @@ # # ********************************************************************** -import os, sys, traceback - +from TestHelper import TestHelper +TestHelper.loadSlice("-I. --all ServerPrivate.ice") import Ice -Ice.loadSlice('-I. --all ServerPrivate.ice') import Test + +def test(b): + if not b: + raise RuntimeError('test assertion failed') + + class TestI(Test.TestIntf): + def shutdown(self, current=None): current.adapter.getCommunicator().shutdown() @@ -216,22 +222,16 @@ class TestI(Test.TestIntf): f.set_exception(ex) return f -def run(args, communicator): - properties = communicator.getProperties() - properties.setProperty("Ice.Warn.Dispatch", "0") - properties.setProperty("TestAdapter.Endpoints", "default -p 12010 -t 10000") - adapter = communicator.createObjectAdapter("TestAdapter") - object = TestI() - adapter.add(object, Ice.stringToIdentity("Test")) - adapter.activate() - communicator.waitForShutdown() - return True - -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False - -sys.exit(not status) + +class ServerAMD(TestHelper): + + def run(self, args): + properties = self.createTestProperties(args) + properties.setProperty("Ice.Warn.Dispatch", "0") + with self.initialize(properties=properties) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", + "{0} -t 10000".format(self.getTestEndpoint())) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(TestI(), Ice.stringToIdentity("Test")) + adapter.activate() + communicator.waitForShutdown() diff --git a/python/test/Ice/slicing/objects/AllTests.py b/python/test/Ice/slicing/objects/AllTests.py index 2e412a07fe2..252b2c9f0d3 100644 --- a/python/test/Ice/slicing/objects/AllTests.py +++ b/python/test/Ice/slicing/objects/AllTests.py @@ -392,8 +392,8 @@ def PreservedFactoryI(id): return PreservedI() return None -def allTests(communicator): - obj = communicator.stringToProxy("Test:default -p 12010") +def allTests(helper, communicator): + obj = communicator.stringToProxy("Test:{0}".format(helper.getTestEndpoint())) t = Test.TestIntfPrx.checkedCast(obj) sys.stdout.write("base as Object... ") diff --git a/python/test/Ice/slicing/objects/Client.py b/python/test/Ice/slicing/objects/Client.py index 6826dcd1889..915622f36bb 100755 --- a/python/test/Ice/slicing/objects/Client.py +++ b/python/test/Ice/slicing/objects/Client.py @@ -8,20 +8,13 @@ # # ********************************************************************** -import os, sys, traceback +from TestHelper import TestHelper +import AllTests -import Ice, AllTests -def run(args, communicator): - Test = AllTests.allTests(communicator) - Test.shutdown() - return True +class Client(TestHelper): -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False - -sys.exit(not status) + def run(self, args): + with self.initialize(args=args) as communicator: + initial = AllTests.allTests(self, communicator) + initial.shutdown() diff --git a/python/test/Ice/slicing/objects/Server.py b/python/test/Ice/slicing/objects/Server.py index 7ec35db7c93..ba621300e42 100755 --- a/python/test/Ice/slicing/objects/Server.py +++ b/python/test/Ice/slicing/objects/Server.py @@ -8,12 +8,12 @@ # # ********************************************************************** -import os, sys, traceback - +from TestHelper import TestHelper +TestHelper.loadSlice("-I. --all ServerPrivate.ice") import Ice -Ice.loadSlice('-I. --all ServerPrivate.ice') import Test + def test(b): if not b: raise RuntimeError('test assertion failed') @@ -364,22 +364,16 @@ class TestI(Test.TestIntf): def shutdown(self, current=None): current.adapter.getCommunicator().shutdown() -def run(args, communicator): - properties = communicator.getProperties() - properties.setProperty("Ice.Warn.Dispatch", "0") - properties.setProperty("TestAdapter.Endpoints", "default -p 12010 -t 10000") - adapter = communicator.createObjectAdapter("TestAdapter") - object = TestI() - adapter.add(object, Ice.stringToIdentity("Test")) - adapter.activate() - communicator.waitForShutdown() - return True - -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False - -sys.exit(not status) + +class Server(TestHelper): + + def run(self, args): + properties = self.createTestProperties(args) + properties.setProperty("Ice.Warn.Dispatch", "0") + with self.initialize(properties=properties) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", + "{0} -t 10000".format(self.getTestEndpoint())) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(TestI(), Ice.stringToIdentity("Test")) + adapter.activate() + communicator.waitForShutdown() diff --git a/python/test/Ice/slicing/objects/ServerAMD.py b/python/test/Ice/slicing/objects/ServerAMD.py index 908765049d5..4822b2ba28c 100755 --- a/python/test/Ice/slicing/objects/ServerAMD.py +++ b/python/test/Ice/slicing/objects/ServerAMD.py @@ -8,16 +8,17 @@ # # ********************************************************************** -import os, sys, traceback - +from TestHelper import TestHelper +TestHelper.loadSlice("-I. --all ServerPrivate.ice") import Ice -Ice.loadSlice('-I. --all ServerPrivate.ice') import Test + def test(b): if not b: raise RuntimeError('test assertion failed') + class TestI(Test.TestIntf): def SBaseAsObject(self, current=None): sb = Test.SBase() @@ -400,22 +401,15 @@ class TestI(Test.TestIntf): def shutdown(self, current=None): current.adapter.getCommunicator().shutdown() -def run(args, communicator): - properties = communicator.getProperties() - properties.setProperty("Ice.Warn.Dispatch", "0") - properties.setProperty("TestAdapter.Endpoints", "default -p 12010 -t 10000") - adapter = communicator.createObjectAdapter("TestAdapter") - object = TestI() - adapter.add(object, Ice.stringToIdentity("Test")) - adapter.activate() - communicator.waitForShutdown() - return True - -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False - -sys.exit(not status) + +class ServerAMD(TestHelper): + def run(self, args): + properties = self.createTestProperties(args) + properties.setProperty("Ice.Warn.Dispatch", "0") + with self.initialize(properties=properties) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", + "{0} -t 10000".format(self.getTestEndpoint())) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(TestI(), Ice.stringToIdentity("Test")) + adapter.activate() + communicator.waitForShutdown() diff --git a/python/test/Ice/thread/AllTests.py b/python/test/Ice/thread/AllTests.py index 48d4fce67a0..0614992021a 100644 --- a/python/test/Ice/thread/AllTests.py +++ b/python/test/Ice/thread/AllTests.py @@ -13,9 +13,9 @@ def test(b): if not b: raise RuntimeError('test assertion failed') -def allTests(communicator): +def allTests(helper, communicator): - ref = "factory:default -p 12010 -t 10000" + ref = "factory:{0} -t 10000".format(helper.getTestEndpoint()) factory = Test.RemoteCommunicatorFactoryPrx.checkedCast(communicator.stringToProxy(ref)) sys.stdout.write("testing thread hooks... ") diff --git a/python/test/Ice/thread/Client.py b/python/test/Ice/thread/Client.py index 76b723c5930..25e142b7337 100644 --- a/python/test/Ice/thread/Client.py +++ b/python/test/Ice/thread/Client.py @@ -8,30 +8,13 @@ # # ********************************************************************** -import os, sys, traceback -import Ice - -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) - -Ice.loadSlice("'-I" + slice_dir + "' Test.ice") +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import AllTests -def test(b): - if not b: - raise RuntimeError('test assertion failed') - -def run(args, communicator): - AllTests.allTests(communicator) - return True -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False +class Client(TestHelper): -sys.exit(not status) + def run(self, args): + with self.initialize(args=args) as communicator: + AllTests.allTests(self, communicator) diff --git a/python/test/Ice/thread/Server.py b/python/test/Ice/thread/Server.py index 0ded6f9744d..c00e3403f68 100644 --- a/python/test/Ice/thread/Server.py +++ b/python/test/Ice/thread/Server.py @@ -8,32 +8,18 @@ # # ********************************************************************** -import os, sys, traceback +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import Ice +import TestI -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) -Ice.loadSlice("'-I" + slice_dir + "' Test.ice") -import Test, TestI - -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010 -t 10000"); - adapter = communicator.createObjectAdapter("TestAdapter"); - ident = Ice.stringToIdentity("factory"); - adapter.add(TestI.RemoteCommunicatorFactoryI(), ident); - adapter.activate(); - - communicator.waitForShutdown(); - return True; - -try: - with Ice.initialize(sys.argv) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False - -sys.exit(not status) +class Server(TestHelper): + def run(self, args): + with self.initialize(args=args) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", + "{0} -t 10000".format(self.getTestEndpoint())) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(TestI.RemoteCommunicatorFactoryI(), Ice.stringToIdentity("factory")) + adapter.activate() + communicator.waitForShutdown() diff --git a/python/test/Ice/timeout/AllTests.py b/python/test/Ice/timeout/AllTests.py index c18f559bfb6..69e78ccef94 100644 --- a/python/test/Ice/timeout/AllTests.py +++ b/python/test/Ice/timeout/AllTests.py @@ -59,16 +59,17 @@ def connect(prx): pass return prx.ice_getConnection(); # Establish connection -def allTests(communicator): +def allTests(helper, communicator): - sref = "timeout:default -p 12010" + sref = "timeout:{0}".format(helper.getTestEndpoint()) obj = communicator.stringToProxy(sref) test(obj != None) timeout = Test.TimeoutPrx.checkedCast(obj) test(timeout != None) - controller = Test.ControllerPrx.checkedCast(communicator.stringToProxy("controller:default -p 12011")) + controller = Test.ControllerPrx.checkedCast( + communicator.stringToProxy("controller:{0}".format(helper.getTestEndpoint(num=1)))) test(controller != None) sys.stdout.write("testing connect timeout... ") diff --git a/python/test/Ice/timeout/Client.py b/python/test/Ice/timeout/Client.py index d4cc9adef77..c4d0a103bb7 100755 --- a/python/test/Ice/timeout/Client.py +++ b/python/test/Ice/timeout/Client.py @@ -8,52 +8,35 @@ # # ********************************************************************** -import os, sys, traceback - -import Ice -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) -Ice.loadSlice("'-I" + slice_dir + "' Test.ice") +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") import AllTests -def test(b): - if not b: - raise RuntimeError('test assertion failed') - -def run(args, communicator): - AllTests.allTests(communicator) - return True - -try: - # - # In this test, we need at least two threads in the - # client side thread pool for nested AMI. - # - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - - # - # For this test, we want to disable retries. - # - initData.properties.setProperty("Ice.RetryIntervals", "-1"); - - # - # This test kills connections, so we don't want warnings. - # - initData.properties.setProperty("Ice.Warn.Connections", "0"); - - # - # Limit the send buffer size, this test relies on the socket - # send() blocking after sending a given amount of data. - # - initData.properties.setProperty("Ice.TCP.SndSize", "50000"); - - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False - -sys.exit(not status) + +class Client(TestHelper): + + def run(self, args): + # + # In this test, we need at least two threads in the + # client side thread pool for nested AMI. + # + properties = self.createTestProperties(args) + + # + # For this test, we want to disable retries. + # + properties.setProperty("Ice.RetryIntervals", "-1") + + # + # This test kills connections, so we don't want warnings. + # + properties.setProperty("Ice.Warn.Connections", "0") + + # + # Limit the send buffer size, this test relies on the socket + # send() blocking after sending a given amount of data. + # + properties.setProperty("Ice.TCP.SndSize", "50000") + + with self.initialize(properties=properties) as communicator: + AllTests.allTests(self, communicator) diff --git a/python/test/Ice/timeout/Server.py b/python/test/Ice/timeout/Server.py index 872d7cf485b..5f504d19266 100755 --- a/python/test/Ice/timeout/Server.py +++ b/python/test/Ice/timeout/Server.py @@ -8,17 +8,14 @@ # # ********************************************************************** -import os, sys, traceback, time, threading - +from TestHelper import TestHelper +TestHelper.loadSlice("Test.ice") +import threading +import time import Ice -slice_dir = Ice.getSliceDir() -if not slice_dir: - print(sys.argv[0] + ': Slice directory not found.') - sys.exit(1) - -Ice.loadSlice("'-I" + slice_dir + "' Test.ice") import Test + class ActivateAdapterThread(threading.Thread): def __init__(self, adapter, timeout): threading.Thread.__init__(self) @@ -57,42 +54,36 @@ class ControllerI(Test.Controller): def shutdown(self, current=None): current.adapter.getCommunicator().shutdown() -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - communicator.getProperties().setProperty("ControllerAdapter.Endpoints", "default -p 12011"); - communicator.getProperties().setProperty("ControllerAdapter.ThreadPool.Size", "1"); - - adapter = communicator.createObjectAdapter("TestAdapter") - adapter.add(TimeoutI(), Ice.stringToIdentity("timeout")) - adapter.activate() - - controllerAdapter = communicator.createObjectAdapter("ControllerAdapter") - controllerAdapter.add(ControllerI(adapter), Ice.stringToIdentity("controller")) - controllerAdapter.activate() - - communicator.waitForShutdown() - return True - -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - initData.properties.setProperty("Ice.Warn.Connections", "0"); - - # - # The client sends large messages to cause the transport - # buffers to fill up. - # - initData.properties.setProperty("Ice.MessageSizeMax", "10000"); - - # - # Limit the recv buffer size, this test relies on the socket - # send() blocking after sending a given amount of data. - # - initData.properties.setProperty("Ice.TCP.RcvSize", "50000"); - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False - -sys.exit(not status) + +class Server(TestHelper): + + def run(self, args): + properties = self.createTestProperties(args) + properties.setProperty("Ice.Warn.Connections", "0") + + # + # The client sends large messages to cause the transport + # buffers to fill up. + # + properties.setProperty("Ice.MessageSizeMax", "10000") + + # + # Limit the recv buffer size, this test relies on the socket + # send() blocking after sending a given amount of data. + # + properties.setProperty("Ice.TCP.RcvSize", "50000") + + with self.initialize(properties=properties) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + communicator.getProperties().setProperty("ControllerAdapter.Endpoints", self.getTestEndpoint(num=1)) + communicator.getProperties().setProperty("ControllerAdapter.ThreadPool.Size", "1") + + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(TimeoutI(), Ice.stringToIdentity("timeout")) + adapter.activate() + + controllerAdapter = communicator.createObjectAdapter("ControllerAdapter") + controllerAdapter.add(ControllerI(adapter), Ice.stringToIdentity("controller")) + controllerAdapter.activate() + + communicator.waitForShutdown() diff --git a/python/test/Slice/escape/Client.py b/python/test/Slice/escape/Client.py index 33a4ac5cbee..915030fbe25 100755 --- a/python/test/Slice/escape/Client.py +++ b/python/test/Slice/escape/Client.py @@ -8,42 +8,39 @@ # # ********************************************************************** -import os, sys, traceback - -for toplevel in [".", "..", "../..", "../../..", "../../../.."]: - toplevel = os.path.normpath(toplevel) - if os.path.exists(os.path.join(toplevel, "python", "Ice", "__init__.py")): - break -else: - raise RuntimeError("can't find toplevel directory!") - +from TestHelper import TestHelper +TestHelper.loadSlice("Key.ice Clash.ice") +import sys import Ice - -Ice.loadSlice('Key.ice') -Ice.loadSlice('Clash.ice') - import _and + class delI(_and._del): def _elifAsync(self, _else, current=None): pass + class execI(_and._exec): def _finally(self, current=None): assert current.operation == "finally" + class ifI(_and._if): def _elifAsync(self, _else, current=None): pass + def _finally(self, current=None): pass + def foo(self, _from, current=None): pass + class printI(_and._print): def _raise(self, _else, _return, _try, _while, _yield, _lambda, _or, _global): pass + def testtypes(): sys.stdout.write("Testing generated type names... ") sys.stdout.flush() @@ -74,36 +71,27 @@ def testtypes(): en = _and.EnumNone._None print("ok") -def run(args, communicator): - communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") - adapter = communicator.createObjectAdapter("TestAdapter") - adapter.add(execI(), Ice.stringToIdentity("test")) - adapter.activate() - - sys.stdout.write("Testing operation name... ") - sys.stdout.flush() - p = _and.execPrx.uncheckedCast( - adapter.createProxy(Ice.stringToIdentity("test"))); - p._finally(); - print("ok") - testtypes() - - return True - -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - # - # Its possible to have batch oneway requests dispatched after the - # adapter is deactivated due to thread scheduling so we supress - # this warning. - # - initData.properties.setProperty("Ice.Warn.Dispatch", "0"); - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False - -sys.exit(not status) +class Client(TestHelper): + + def run(self, args): + properties = self.createTestProperties(args) + # + # Its possible to have batch oneway requests dispatched after the + # adapter is deactivated due to thread scheduling so we supress + # this warning. + # + properties.setProperty("Ice.Warn.Dispatch", "0") + with self.initialize(properties=properties) as communicator: + communicator.getProperties().setProperty("TestAdapter.Endpoints", self.getTestEndpoint()) + adapter = communicator.createObjectAdapter("TestAdapter") + adapter.add(execI(), Ice.stringToIdentity("test")) + adapter.activate() + + sys.stdout.write("Testing operation name... ") + sys.stdout.flush() + p = _and.execPrx.uncheckedCast(adapter.createProxy(Ice.stringToIdentity("test"))) + p._finally() + print("ok") + + testtypes() diff --git a/python/test/Slice/import/Client.py b/python/test/Slice/import/Client.py index 93811469483..c5f65ba3d86 100755 --- a/python/test/Slice/import/Client.py +++ b/python/test/Slice/import/Client.py @@ -8,36 +8,26 @@ # # ********************************************************************** -import os, sys, traceback - -for toplevel in [".", "..", "../..", "../../..", "../../../.."]: - toplevel = os.path.normpath(toplevel) - if os.path.exists(os.path.join(toplevel, "python", "Ice", "__init__.py")): - break -else: - raise RuntimeError("can't find toplevel directory!") - +from TestHelper import TestHelper +import sys import Test -status = True def test(b): if not b: raise RuntimeError('test assertion failed') -try: - sys.stdout.write("testing imports... ") - sys.stdout.flush() - test(Test.SubA.SubSubA1.Value1 == 10) - test(Test.SubA.SubSubA1.Value2 == 11) - test(Test.SubA.SubSubA2.Value1 == 30) - test(Test.SubB.SubSubB1.Value1 == 20) - test(Test.SubB.SubSubB1.Value2 == 21) +class Client(TestHelper): + + def run(self, args): + sys.stdout.write("testing imports... ") + sys.stdout.flush() - print("ok") -except: - traceback.print_exc() - status = False + test(Test.SubA.SubSubA1.Value1 == 10) + test(Test.SubA.SubSubA1.Value2 == 11) + test(Test.SubA.SubSubA2.Value1 == 30) + test(Test.SubB.SubSubB1.Value1 == 20) + test(Test.SubB.SubSubB1.Value2 == 21) -sys.exit(not status) + print("ok") diff --git a/python/test/Slice/macros/Client.py b/python/test/Slice/macros/Client.py index dea8161c050..7e6d25fe6e6 100755 --- a/python/test/Slice/macros/Client.py +++ b/python/test/Slice/macros/Client.py @@ -8,44 +8,33 @@ # # ********************************************************************** -import os, sys, traceback - -for toplevel in [".", "..", "../..", "../../..", "../../../.."]: - toplevel = os.path.normpath(toplevel) - if os.path.exists(os.path.join(toplevel, "python", "Ice", "__init__.py")): - break -else: - raise RuntimeError("can't find toplevel directory!") - +from TestHelper import TestHelper +TestHelper.loadSlice('Test.ice') +import sys import Ice +import Test -Ice.loadSlice('Test.ice') -import Test, copy - -status = True def test(b): if not b: raise RuntimeError('test assertion failed') -try: - sys.stdout.write("testing Slice predefined macros... ") - sys.stdout.flush() - d = Test.Default() - test(d.x == 10) - test(d.y == 10) +class Client(TestHelper): + + def run(self, args): + sys.stdout.write("testing Slice predefined macros... ") + sys.stdout.flush() - nd = Test.NoDefault() - test(nd.x != 10) - test(nd.y != 10) + d = Test.Default() + test(d.x == 10) + test(d.y == 10) - c = Test.PythonOnly() - test(c.lang == "python") - test(c.version == Ice.intVersion()) - print("ok") -except: - traceback.print_exc() - status = False + nd = Test.NoDefault() + test(nd.x != 10) + test(nd.y != 10) -sys.exit(not status) + c = Test.PythonOnly() + test(c.lang == "python") + test(c.version == Ice.intVersion()) + print("ok") diff --git a/python/test/Slice/structure/Client.py b/python/test/Slice/structure/Client.py index 46820ea2289..a6aabfe9aaf 100755 --- a/python/test/Slice/structure/Client.py +++ b/python/test/Slice/structure/Client.py @@ -8,24 +8,18 @@ # # ********************************************************************** -import os, sys, traceback +from TestHelper import TestHelper +TestHelper.loadSlice('Test.ice') +import sys +import copy +import Test -for toplevel in [".", "..", "../..", "../../..", "../../../.."]: - toplevel = os.path.normpath(toplevel) - if os.path.exists(os.path.join(toplevel, "python", "Ice", "__init__.py")): - break -else: - raise RuntimeError("can't find toplevel directory!") - -import Ice - -Ice.loadSlice('Test.ice') -import Test, copy def test(b): if not b: raise RuntimeError('test assertion failed') + def allTests(communicator): sys.stdout.write("testing equals() for Slice structures... ") sys.stdout.flush() @@ -187,18 +181,10 @@ def allTests(communicator): print("ok") -def run(args, communicator): - allTests(communicator) - return True +class Client(TestHelper): -try: - initData = Ice.InitializationData() - initData.properties = Ice.createProperties(sys.argv) - with Ice.initialize(sys.argv, initData) as communicator: - status = run(sys.argv, communicator) -except: - traceback.print_exc() - status = False + def run(self, args): -sys.exit(not status) + with self.initialize(args=args) as communicator: + allTests(communicator) diff --git a/python/test/TestHelper.py b/python/test/TestHelper.py new file mode 100644 index 00000000000..21adf4797d9 --- /dev/null +++ b/python/test/TestHelper.py @@ -0,0 +1,107 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2018 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import Ice +import sys +import os +import traceback +import importlib + + +class TestHelper: + + def __init__(self): + self._communicator = None + + def getTestEndpoint(self, properties=None, num=0, protocol=""): + + if properties is None: + properties = self._communicator.getProperties() + + if protocol == "": + protocol = properties.getPropertyWithDefault("Ice.Default.Protocol", "default") + + port = properties.getPropertyAsIntWithDefault("Test.BasePort", 12010) + num + + return "{0} -p {1}".format(protocol, port) + + def getTestHost(self, properties=None): + + if properties is None: + properties = self._communicator.getProperties() + + return properties.getPropertyWithDefaultHost("Ice.Default.Host", "127.0.0.1") + + def getTestProtocol(self, properties=None): + + if properties is None: + properties = self._communicator.getProperties() + + return properties.getPropertyWithDefault("Ice.Default.Protocol", "tcp") + + def getTestPort(self, properties=None, num=0): + + if properties is None: + properties = self._communicator.getProperties() + + return properties.getPropertyAsIntWithDefault("Test.BasePort", 12010) + num + + def createTestProperties(self, args=[]): + + properties = Ice.createProperties(args) + properties.parseCommandLineOptions("Test", args) + return properties + + def initialize(self, initData=None, properties=None, args=[]): + + if initData is None: + initData = Ice.InitializationData() + if properties: + initData.properties = properties + else: + initData.properties = self.createTestProperties(args) + + communicator = Ice.initialize(initData) + + if self._communicator is None: + self._communicator = communicator + + return communicator + + def communicator(self): + return self._communicator + + def shutdown(self): + if self._communicator: + self._communicator.shutdown() + + @classmethod + def loadSlice(self, args): + sliceDir = Ice.getSliceDir() + if not sliceDir: + print(sys.argv[0] + ': Slice directory not found.') + sys.exit(1) + Ice.loadSlice("'-I{0}' {1}".format(sliceDir, args)) + + @classmethod + def run(self): + try: + moduleName = os.path.splitext(sys.argv[1])[0] + module = importlib.import_module(moduleName) + cls = getattr(module, moduleName) + helper = cls() + helper.run(sys.argv[2:]) + return 0 + except Exception: + traceback.print_exc() + return 1 + + +if __name__ == '__main__': + sys.exit(TestHelper.run()) |