From 961bb1d18bfb2c58e98b216dfbc83ad90084d1d7 Mon Sep 17 00:00:00 2001 From: Joe George Date: Mon, 22 Jan 2024 15:16:46 -0500 Subject: [PATCH] Format and lint scripts dir (#1714) --- .github/workflows/ruff.yml | 2 +- scripts/Component.py | 114 ++++++++++++---------- scripts/Controller.py | 20 +++- scripts/Expect.py | 4 +- scripts/Glacier2Util.py | 12 ++- scripts/IceBoxUtil.py | 18 +++- scripts/IceBridgeUtil.py | 3 +- scripts/IceGridUtil.py | 30 ++++-- scripts/IcePatch2Util.py | 3 +- scripts/IceStormUtil.py | 20 ++-- scripts/LocalDriver.py | 17 ++-- scripts/NetworkProxy.py | 8 +- scripts/Util.py | 118 ++++++++++++----------- scripts/icehashpassword.py | 4 +- scripts/tests/Glacier2/application.py | 3 + scripts/tests/Glacier2/router.py | 39 ++++++-- scripts/tests/Glacier2/sessionHelper.py | 3 + scripts/tests/Ice/adapterDeactivation.py | 3 + scripts/tests/Ice/admin.py | 3 + scripts/tests/Ice/ami.py | 12 +-- scripts/tests/Ice/background.py | 3 + scripts/tests/Ice/binding.py | 4 + scripts/tests/Ice/enums.py | 17 +++- scripts/tests/Ice/exceptions.py | 27 +++++- scripts/tests/Ice/faultTolerance.py | 27 ++++-- scripts/tests/Ice/hold.py | 3 + scripts/tests/Ice/info.py | 3 + scripts/tests/Ice/interceptor.py | 9 +- scripts/tests/Ice/interrupt.py | 3 + scripts/tests/Ice/location.py | 8 +- scripts/tests/Ice/metrics.py | 23 +++-- scripts/tests/Ice/networkProxy.py | 35 ++++--- scripts/tests/Ice/objects.py | 12 ++- scripts/tests/Ice/optional.py | 12 ++- scripts/tests/Ice/properties.py | 22 +++-- scripts/tests/Ice/retry.py | 9 +- scripts/tests/Ice/slicing/exceptions.py | 12 ++- scripts/tests/Ice/slicing/objects.py | 18 +++- scripts/tests/Ice/stream.py | 16 ++- scripts/tests/Ice/timeout.py | 18 ++-- scripts/tests/Ice/udp.py | 8 +- scripts/tests/IceBox/admin.py | 25 +++-- scripts/tests/IceBox/configuration.py | 23 ++++- scripts/tests/IceDiscovery/simple.py | 53 ++++++---- scripts/tests/IceGrid/simple.py | 88 ++++++++++++----- scripts/tests/IceSSL/configuration.py | 97 ++++++++++++++----- scripts/tests/Slice/generation.py | 18 +++- 47 files changed, 695 insertions(+), 334 deletions(-) diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml index 35f88c1011c..3af6590eafd 100644 --- a/.github/workflows/ruff.yml +++ b/.github/workflows/ruff.yml @@ -20,4 +20,4 @@ jobs: run: pip install ruff - name: Run Ruff - run: ruff check . --exclude "scripts" --exclude "python" --ignore E402 + run: ruff check . --exclude "python" --ignore E402 diff --git a/scripts/Component.py b/scripts/Component.py index 47f144689ef..438fb8a4cd4 100644 --- a/scripts/Component.py +++ b/scripts/Component.py @@ -3,11 +3,14 @@ # import os +import re -from Util import * +# Import as modules to allow for circular imports +import Util +import IceGridUtil -class Ice(Component): +class Ice(Util.Component): # Options for all transports (ran only with Ice client/server tests defined for cross testing) transportOptions = { "protocol": ["tcp", "ssl", "wss", "ws"], @@ -36,19 +39,20 @@ class Ice(Component): } def useBinDist(self, mapping, current): - return Component._useBinDist(self, mapping, current, "ICE_BIN_DIST") + return Util.Component._useBinDist(self, mapping, current, "ICE_BIN_DIST") def getInstallDir(self, mapping, current): # On Windows, the Ice MSI installation can only be used for C++ envHomeName = ( None - if isinstance(platform, Windows) and not isinstance(mapping, CppMapping) + if isinstance(Util.platform, Util.Windows) + and not isinstance(mapping, Util.CppMapping) else "ICE_HOME" ) - return Component._getInstallDir(self, mapping, current, envHomeName) + return Util.Component._getInstallDir(self, mapping, current, envHomeName) def getPhpExtension(self, mapping, current): - if isinstance(platform, Windows): + if isinstance(Util.platform, Util.Windows): return ( "php_ice.dll" if current.driver.configs[mapping].buildConfig in ["Debug", "Release"] @@ -58,14 +62,16 @@ def getPhpExtension(self, mapping, current): return "ice.so" def getNugetPackageVersionFile(self, mapping): - if isinstance(mapping, CSharpMapping): - return os.path.join(toplevel, "csharp", "msbuild", "zeroc.ice.net.nuspec") + if isinstance(mapping, Util.CSharpMapping): + return os.path.join( + Util.toplevel, "csharp", "msbuild", "zeroc.ice.net.nuspec" + ) else: return os.path.join( - toplevel, + Util.toplevel, "cpp", "msbuild", - "zeroc.ice.{0}.nuspec".format(platform.getPlatformToolset()), + "zeroc.ice.{0}.nuspec".format(Util.platform.getPlatformToolset()), ) def getFilters(self, mapping, config): @@ -96,7 +102,7 @@ def getFilters(self, mapping, config): ], ["Ice/library", "Ice/plugin"], ) - elif isinstance(mapping, JavaMapping) and config.android: + elif isinstance(mapping, Util.JavaMapping) and config.android: return ( ["Ice/.*"], [ @@ -110,9 +116,9 @@ def getFilters(self, mapping, config): "Ice/properties", ], ) - elif isinstance(mapping, JavaScriptMapping): + elif isinstance(mapping, Util.JavaScriptMapping): return ([], ["typescript/.*"]) - elif isinstance(mapping, SwiftMapping) and config.buildPlatform in [ + elif isinstance(mapping, Util.SwiftMapping) and config.buildPlatform in [ "iphonesimulator", "iphoneos", ]: @@ -124,9 +130,9 @@ def getFilters(self, mapping, config): def canRun(self, testId, mapping, current): parent = re.match(r"^([\w]*).*", testId).group(1) - if isinstance(platform, Linux): + if isinstance(Util.platform, Util.Linux): if ( - platform.getLinuxId() in ["centos", "rhel", "fedora"] + Util.platform.getLinuxId() in ["centos", "rhel", "fedora"] and current.config.buildPlatform == "x86" ): # @@ -135,7 +141,7 @@ def canRun(self, testId, mapping, current): # if parent in ["Glacier2", "IceStorm", "IceGrid"]: return False - elif isinstance(platform, Windows): + elif isinstance(Util.platform, Util.Windows): # # On Windows, if testing with a binary distribution, don't test Glacier2/IceBridge services # with the Debug configurations since we don't provide binaries for them. @@ -146,7 +152,7 @@ def canRun(self, testId, mapping, current): and current.config.buildConfig.find("Debug") >= 0 ): return False - elif isinstance(platform, AIX): + elif isinstance(Util.platform, Util.AIX): if current.config.buildPlatform == "ppc" and self.useBinDist( mapping, current ): @@ -161,7 +167,7 @@ def canRun(self, testId, mapping, current): # No C++98 tests for Glacier2, IceGrid, IceStorm, IceBridge if ( - isinstance(mapping, CppMapping) + isinstance(mapping, Util.CppMapping) and not current.config.cpp11 and parent in ["Glacier2", "IceBridge", "IceGrid", "IceStorm"] ): @@ -174,12 +180,12 @@ def isMainThreadOnly(self, testId): def getDefaultProcesses(self, mapping, processType, testId): if testId.startswith("IceUtil") or testId.startswith("Slice"): - return [SimpleClient()] + return [Util.SimpleClient()] elif testId.startswith("IceGrid"): if processType in ["client", "collocated"]: - return [IceGridClient()] + return [IceGridUtil.IceGridClient()] if processType in ["server", "serveramd"]: - return [IceGridServer()] + return [IceGridUtil.IceGridServer()] def getOptions(self, testcase, current): parent = re.match(r"^([\w]*).*", testcase.getTestSuite().getId()).group(1) @@ -194,7 +200,7 @@ def getOptions(self, testcase, current): ]: return None - if isinstance(testcase, CollocatedTestCase): + if isinstance(testcase, Util.CollocatedTestCase): return None # Define here Ice tests which are slow to execute and for which it's not useful to test different options @@ -206,7 +212,7 @@ def getOptions(self, testcase, current): return self.serviceOptions # We only run the client/server tests defined for cross testing with all transports - if isinstance(testcase, ClientServerTestCase) and self.isCross( + if isinstance(testcase, Util.ClientServerTestCase) and self.isCross( testcase.getTestSuite().getId() ): return self.transportOptions @@ -245,7 +251,7 @@ def isCross(self, testId): def getSoVersion(self): with open( - os.path.join(toplevel, "cpp", "include", "IceUtil", "Config.h"), "r" + os.path.join(Util.toplevel, "cpp", "include", "IceUtil", "Config.h"), "r" ) as config: intVersion = int( re.search("ICE_INT_VERSION ([0-9]*)", config.read()).group(1) @@ -263,60 +269,66 @@ def getSoVersion(self): component = Ice() -from Glacier2Util import * -from IceBoxUtil import * -from IceBridgeUtil import * -from IcePatch2Util import * -from IceGridUtil import * -from IceStormUtil import * - # # Supported mappings # for m in filter( - lambda x: os.path.isdir(os.path.join(toplevel, x)), os.listdir(toplevel) + lambda x: os.path.isdir(os.path.join(Util.toplevel, x)), os.listdir(Util.toplevel) ): if m == "cpp" or re.match("cpp-.*", m): - Mapping.add(m, CppMapping(), component) + Util.Mapping.add(m, Util.CppMapping(), component) elif m == "java" or re.match("java-.*", m): - Mapping.add(m, JavaMapping(), component) + Util.Mapping.add(m, Util.JavaMapping(), component) elif m == "python" or re.match("python-.*", m): - Mapping.add(m, PythonMapping(), component) + Util.Mapping.add(m, Util.PythonMapping(), component) elif m == "ruby" or re.match("ruby-.*", m): - Mapping.add( - m, RubyMapping(), component, enable=not isinstance(platform, Windows) + Util.Mapping.add( + m, + Util.RubyMapping(), + component, + enable=not isinstance(Util.platform, Util.Windows), ) elif m == "php" or re.match("php-.*", m): - Mapping.add( - m, PhpMapping(), component, enable=not isinstance(platform, Windows) + Util.Mapping.add( + m, + Util.PhpMapping(), + component, + enable=not isinstance(Util.platform, Util.Windows), ) elif m == "js" or re.match("js-.*", m): - Mapping.add(m, JavaScriptMapping(), component, enable=platform.hasNodeJS()) - Mapping.add( + Util.Mapping.add( + m, Util.JavaScriptMapping(), component, enable=Util.platform.hasNodeJS() + ) + Util.Mapping.add( "typescript", - TypeScriptMapping(), + Util.TypeScriptMapping(), component, "js", - enable=platform.hasNodeJS(), + enable=Util.platform.hasNodeJS(), ) elif m == "swift" or re.match("swift-.*", m): # Swift mapping requires Swift 5.0 or greater - Mapping.add( - "swift", SwiftMapping(), component, enable=platform.hasSwift((5, 0)) + Util.Mapping.add( + "swift", + Util.SwiftMapping(), + component, + enable=Util.platform.hasSwift((5, 0)), ) elif m == "csharp" or re.match("charp-.*", m): - Mapping.add( + Util.Mapping.add( "csharp", - CSharpMapping(), + Util.CSharpMapping(), component, - enable=isinstance(platform, Windows) or platform.hasDotNet(), + enable=isinstance(Util.platform, Util.Windows) or Util.platform.hasDotNet(), ) # # Check if Matlab is installed and eventually add the Matlab mapping # try: - run("where matlab" if isinstance(platform, Windows) else "which matlab") - Mapping.add("matlab", MatlabMapping(), component) -except: + Util.run( + "where matlab" if isinstance(Util.platform, Util.Windows) else "which matlab" + ) + Util.Mapping.add("matlab", Util.MatlabMapping(), component) +except Exception: pass diff --git a/scripts/Controller.py b/scripts/Controller.py index 61ec8aed15e..459f3ca78e7 100755 --- a/scripts/Controller.py +++ b/scripts/Controller.py @@ -5,7 +5,19 @@ import os import sys -from Util import * + +from Util import ( + Darwin, + Driver, + IceProcess, + Mapping, + Result, + parseOptions, + toplevel, + platform, + runTests, + traceback, +) class ControllerDriver(Driver): @@ -109,7 +121,7 @@ def startServerSide(self, config, c): try: self.serverSideRunning = True return self.current.serverTestCase._startServerSide(self.current) - except Exception as ex: + except Exception: self.serverSideRunning = False raise Test.Common.TestCaseFailedException( self.current.result.getOutput() + "\n" + traceback.format_exc() @@ -141,7 +153,7 @@ def destroy(self, c): if self.serverSideRunning: try: self.current.serverTestCase._stopServerSide(self.current, False) - except: + except Exception: pass c.adapter.remove(c.id) @@ -171,7 +183,7 @@ def runTestCase(self, mapping, testsuite, testcase, cross, c): if self.testcase: try: self.testcase.destroy() - except: + except Exception: pass self.testcase = None diff --git a/scripts/Expect.py b/scripts/Expect.py index 5a3c60955d1..c95e0a8a848 100755 --- a/scripts/Expect.py +++ b/scripts/Expect.py @@ -634,11 +634,13 @@ def kill(): return killProcess(self.p) self.wait() + break except KeyboardInterrupt as e: ex = e raise - except e: + except Exception as e: ex = e + if ex: print(ex) raise ex diff --git a/scripts/Glacier2Util.py b/scripts/Glacier2Util.py index d74e9bb0ea0..403c2f5f5a2 100644 --- a/scripts/Glacier2Util.py +++ b/scripts/Glacier2Util.py @@ -4,7 +4,17 @@ import sys import os -from Util import * + +from Util import ( + ClientServerTestCase, + Mapping, + ProcessFromBinDir, + ProcessIsReleaseOnly, + Server, + TestSuite, + run, + toplevel, +) class Glacier2Router(ProcessFromBinDir, ProcessIsReleaseOnly, Server): diff --git a/scripts/IceBoxUtil.py b/scripts/IceBoxUtil.py index e9f7a36f321..1822da32ae4 100644 --- a/scripts/IceBoxUtil.py +++ b/scripts/IceBoxUtil.py @@ -2,8 +2,20 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # -from Util import * -from Component import component +import Component +from Util import ( + AIX, + CSharpMapping, + Client, + CppMapping, + JavaMapping, + Linux, + Mapping, + ProcessFromBinDir, + ProcessIsReleaseOnly, + Server, + platform, +) class IceBox(ProcessFromBinDir, Server): @@ -62,7 +74,7 @@ def getExe(self, current): elif ( isinstance(platform, AIX) and current.config.buildPlatform == "ppc" - and not component.useBinDist(mapping, current) + and not Component.component.useBinDist(mapping, current) ): return "iceboxadmin_32" else: diff --git a/scripts/IceBridgeUtil.py b/scripts/IceBridgeUtil.py index 15de3277b7e..1df1f0f77ac 100644 --- a/scripts/IceBridgeUtil.py +++ b/scripts/IceBridgeUtil.py @@ -2,7 +2,8 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # -from Util import * + +from Util import Mapping, ProcessFromBinDir, ProcessIsReleaseOnly, Server class IceBridge(ProcessFromBinDir, ProcessIsReleaseOnly, Server): diff --git a/scripts/IceGridUtil.py b/scripts/IceGridUtil.py index a544222d1d1..e232502c9b8 100644 --- a/scripts/IceGridUtil.py +++ b/scripts/IceGridUtil.py @@ -2,12 +2,25 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # -import sys import os -from Util import * -from IceBoxUtil import * -from Glacier2Util import * -from IcePatch2Util import * +import shutil +from Glacier2Util import Glacier2Router +from IceBoxUtil import IceBox +from IcePatch2Util import IcePatch2Server + +from Util import ( + CSharpMapping, + Client, + Linux, + Mapping, + ProcessFromBinDir, + ProcessIsReleaseOnly, + Server, + TestCase, + toplevel, + platform, + val, +) class IceGridProcess: @@ -106,7 +119,7 @@ def teardown(self, current, success): if success or current.driver.isInterrupted(): try: shutil.rmtree(self.dbdir) - except: + except Exception: pass def getProps(self, current): @@ -176,7 +189,7 @@ def teardown(self, current, success): if success or current.driver.isInterrupted(): try: shutil.rmtree(self.dbdir) - except: + except Exception: pass def getProps(self, current): @@ -295,11 +308,10 @@ def setupClientSide(self, current): if self.application: try: self.runadmin(current, "application remove Test", quiet=True) - except: + except Exception: pass javaHome = os.environ.get("JAVA_HOME", None) - serverProps = Server().getProps(current) variables = { "test.dir": self.getPath(current), "java.exe": os.path.join(javaHome, "bin", "java") diff --git a/scripts/IcePatch2Util.py b/scripts/IcePatch2Util.py index 436502895d3..bcb1d8964fc 100644 --- a/scripts/IcePatch2Util.py +++ b/scripts/IcePatch2Util.py @@ -2,7 +2,8 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # -from Util import * + +from Util import Mapping, Process, ProcessFromBinDir, ProcessIsReleaseOnly class IcePatch2Calc(ProcessFromBinDir, ProcessIsReleaseOnly, Process): diff --git a/scripts/IceStormUtil.py b/scripts/IceStormUtil.py index 036c7435ed6..b841f48ecf0 100644 --- a/scripts/IceStormUtil.py +++ b/scripts/IceStormUtil.py @@ -3,9 +3,17 @@ # import os -from Util import * -from Component import component -from IceBoxUtil import * +import shutil +import Component +from IceBoxUtil import IceBoxAdmin +from Util import ( + Client, + Mapping, + ProcessFromBinDir, + ProcessIsReleaseOnly, + Server, + TestCase, +) class IceStorm(ProcessFromBinDir, Server): @@ -61,7 +69,7 @@ def teardown(self, current, success): # Remove the database directory tree try: shutil.rmtree(self.dbdir) - except: + except Exception: pass def getProps(self, current): @@ -71,7 +79,7 @@ def getProps(self, current): props.update( { "IceBox.Service.IceStorm": "IceStormService," - + component.getSoVersion() + + Component.component.getSoVersion() + ":createIceStorm", "IceBox.PrintServicesReady": "IceStorm", "IceBox.InheritProperties": 1, @@ -223,7 +231,7 @@ def __init__(self, instanceName=None, instance=None, *args, **kargs): IceStormProcess.__init__(self, instanceName, instance) def getExe(self, current): - if current.config.buildPlatform == "ppc" and not component.useBinDist( + if current.config.buildPlatform == "ppc" and not Component.component.useBinDist( self.mapping, current ): return self.exe + "_32" diff --git a/scripts/LocalDriver.py b/scripts/LocalDriver.py index 32de5d1bdc4..c90227814ba 100644 --- a/scripts/LocalDriver.py +++ b/scripts/LocalDriver.py @@ -7,7 +7,9 @@ import time import threading import queue -from Util import * +import traceback + +from Util import Driver, IceProcess, Mapping, Result, parseOptions, Expect # # The Executor class runs testsuites on multiple worker threads. @@ -82,7 +84,7 @@ def runTestSuites(self, driver, total, results, mainThread=False): except KeyboardInterrupt: if mainThread: raise - except: + except Exception: pass finally: current.destroy() @@ -285,7 +287,7 @@ def startServerSide(self, testcase, current): except Test.Common.TestCaseFailedException as ex: current.result.writeln(ex.output) raise RuntimeError("test failed:\n" + str(ex)) - except: + except Exception: current.serverTestCase.destroy() current.serverTestCase = None raise @@ -588,7 +590,7 @@ def runTestSuite(self, current): current.result.started("setup") current.testsuite.setup(current) current.result.succeeded("setup") - except Exception as ex: + except Exception: current.result.failed("setup", traceback.format_exc()) raise @@ -602,7 +604,7 @@ def runTestSuite(self, current): ): current.config = conf testcase.run(current) - except: + except Exception: if current.driver.debug: current.result.writeln(traceback.format_exc()) raise @@ -614,7 +616,7 @@ def runTestSuite(self, current): current.result.started("teardown") current.testsuite.teardown(current, success) current.result.succeeded("teardown") - except Exception as ex: + except Exception: current.result.failed("teardown", traceback.format_exc()) raise @@ -785,6 +787,3 @@ def getMappings(self): def filterOptions(self, options): return self.runner.filterOptions(options) - - -Driver.add("local", LocalDriver) diff --git a/scripts/NetworkProxy.py b/scripts/NetworkProxy.py index 24c1b18a821..0b7a575d4a9 100644 --- a/scripts/NetworkProxy.py +++ b/scripts/NetworkProxy.py @@ -38,7 +38,7 @@ def close(self): if self.remoteSocket: self.remoteSocket.close() self.remoteSocket = None - except: + except Exception: pass def run(self): @@ -48,7 +48,7 @@ def run(self): try: self.remoteSocket.connect(remoteAddr) self.socket.send(self.response(True)) - except: + except Exception: self.socket.send(self.response(False)) return @@ -106,7 +106,7 @@ def run(self): self.socket.setsockopt( socket.SOL_SOCKET, socket.SO_REUSEPORT, 1 ) - except: + except Exception: # Ignore, this can throw on some platforms if not supported (e.g: ARMHF/Qemu) pass self.socket.bind(("127.0.0.1", self.port)) @@ -126,7 +126,7 @@ def run(self): connection.start() with self.cond: self.connections.append(connection) - except: + except Exception: pass finally: self.socket.close() diff --git a/scripts/Util.py b/scripts/Util.py index 60ba5ef694b..d34c4c60c2d 100644 --- a/scripts/Util.py +++ b/scripts/Util.py @@ -45,7 +45,7 @@ def run(cmd, cwd=None, err=False, stdout=False, stdin=None, stdinRepeat=True): if not stdinRepeat: break time.sleep(1) - except: + except Exception: pass out = (p.stderr if stdout else p.stdout).read().decode("UTF-8").strip() @@ -66,9 +66,9 @@ def run(cmd, cwd=None, err=False, stdout=False, stdin=None, stdinRepeat=True): def val(v, quoteValue=True): - if type(v) == bool: + if isinstance(v, bool): return "1" if v else "0" - elif type(v) == str: + elif isinstance(v, str): if not quoteValue or v.find(" ") < 0: return v v = v.replace("\\", "\\\\").replace('"', '\\"') @@ -110,7 +110,7 @@ def useBinDist(self, mapping, current): """ def getInstallDir(self, mapping, current): - raise Error("must be overridden") + raise Exception("must be overridden") def getSourceDir(self): return toplevel @@ -139,7 +139,7 @@ def getNugetPackage(self, mapping): ) def getNugetPackageVersion(self, mapping): - if not mapping in self.nugetVersion: + if mapping not in self.nugetVersion: file = self.getNugetPackageVersionFile(mapping) if file.endswith(".nuspec"): expr = "(.*)" @@ -152,7 +152,7 @@ def getNugetPackageVersion(self, mapping): m = re.search(expr, config.read()) if m: self.nugetVersion[mapping] = m.group(1) - if not mapping in self.nugetVersion: + if mapping not in self.nugetVersion: raise RuntimeError( "couldn't figure out the nuget version from `{0}'".format(file) ) @@ -255,7 +255,7 @@ def __init__(self): "global-packages: (.*)", run("dotnet nuget locals --list global-packages"), ).groups(1)[0] - except: + except Exception: self.nugetPackageCache = None self._hasNodeJS = None @@ -271,14 +271,14 @@ def init(self, component): ) def hasDotNet(self): - return self.nugetPackageCache != None + return self.nugetPackageCache is not None def hasNodeJS(self): if self._hasNodeJS is None: try: run("node --version") self._hasNodeJS = True - except: + except Exception: self._hasNodeJS = False return self._hasNodeJS @@ -294,7 +294,7 @@ def hasSwift(self, version): ) else: self.hasSwift = False - except: + except Exception: self._hasSwift = False return self._hasSwift @@ -308,8 +308,8 @@ def parseBuildVariables(self, component, variables): cwd = Mapping.getByName("cpp").getPath() output = run('make print V="{0}"'.format(" ".join(variables.keys())), cwd=cwd) - for l in output.split("\n"): - match = re.match(r"^.*:.*: (.*) = (.*)", l) + for line in output.split("\n"): + match = re.match(r"^.*:.*: (.*) = (.*)", line) if match and match.group(1): if match.group(1) in variables: (varname, valuefn) = variables[match.group(1).strip()] @@ -497,7 +497,7 @@ def getDefaultBuildConfig(self): return "Release" def getCompiler(self): - if self.compiler != None: + if self.compiler is not None: return self.compiler if os.environ.get("CPP_COMPILER", "") != "": self.compiler = os.environ["CPP_COMPILER"] @@ -520,7 +520,7 @@ def getCompiler(self): self.compiler = "v143" else: raise RuntimeError("Unknown compiler version:\n{0}".format(out)) - except: + except Exception: self.compiler = "" return self.compiler @@ -632,7 +632,7 @@ def getNugetPackageDir(self, component, mapping, current): def getDotNetExe(self): try: return run("where dotnet").strip().splitlines()[0] - except: + except Exception: return None @@ -658,13 +658,13 @@ def parseOptions(obj, options, mapped={}): if isinstance(getattr(obj, o), bool): setattr(obj, o, True if not a else (a.lower() in ["yes", "true", "1"])) elif isinstance(getattr(obj, o), list): - l = getattr(obj, o) - l.append(a) + argList = getattr(obj, o) + argList.append(a) else: if not a and not isinstance(a, str): a = "0" setattr(obj, o, type(getattr(obj, o))(a)) - if not o in obj.parsedOptions: + if o not in obj.parsedOptions: obj.parsedOptions.append(o) else: remaining.append((o, a)) @@ -770,7 +770,7 @@ def __str__(self): for o in self.parsedOptions: v = getattr(self, o) if v: - s.append(o if type(v) == bool else str(v)) + s.append(o if isinstance(v, bool) else str(v)) return ",".join(s) def getAll(self, current, testcase, rand=False): @@ -812,7 +812,7 @@ def gen(supportedOptions): for k, v in supportedOptions.items(): v = next(v) if v: - if type(v) == bool: + if isinstance(v, bool): if v: options.append(("--{0}".format(k), None)) else: @@ -821,10 +821,10 @@ def gen(supportedOptions): # Add parsed options for o in self.parsedOptions: v = getattr(self, o) - if type(v) == bool: + if isinstance(v, bool): if v: options.append(("--{0}".format(o), None)) - elif type(v) == list: + elif isinstance(v, list): options += [("--{0}".format(o), e) for e in v] else: options.append(("--{0}".format(o), v)) @@ -853,10 +853,10 @@ def canRun(self, testId, current): for k, v in options.items(): if hasattr(self, k): - if not getattr(self, k) in v: + if getattr(self, k) not in v: return False elif hasattr(current.driver, k): - if not getattr(current.driver, k) in v: + if getattr(current.driver, k) not in v: return False else: return True @@ -950,7 +950,7 @@ def getProps(self, process, current): @classmethod def getByName(self, name): - if not name in self.mappings: + if name not in self.mappings: raise RuntimeError( "unknown mapping: `{0}', known mappings: `{1}'".format( name, list(self.mappings) @@ -1524,7 +1524,7 @@ def start(self, current, args=[], props={}, watchDog=None): ) try: self.waitForStart(current) - except: + except Exception: self.stop(current) raise @@ -1985,7 +1985,7 @@ def _startServerSide(self, current): try: self.startServerSide(current) return current.host - except: + except Exception: self._stopServerSide(current, False) raise finally: @@ -2013,7 +2013,7 @@ def _startServer(self, current, server): def _stopServer(self, current, server, success): try: server.stop(current, success) - except: + except Exception: success = False raise finally: @@ -2415,7 +2415,7 @@ def __init__(self, current): pass def start(self, process, current, args, props, envs, watchDog): - raise NotImplemented() + raise NotImplementedError() def destroy(self, driver): pass @@ -2612,7 +2612,7 @@ def getHost(self, current): def getController(self, current): ident = self.getControllerIdentity(current) - if type(ident) == str: + if isinstance(ident, str): ident = current.driver.getCommunicator().stringToIdentity(ident) import Ice @@ -2654,7 +2654,7 @@ def callback(future): try: future.result() with self.cond: - if not ident in self.processControllerProxies: + if ident not in self.processControllerProxies: self.processControllerProxies[proxy.ice_getIdentity()] = proxy self.cond.notifyAll() except Exception: @@ -2668,7 +2668,7 @@ def callback(future): proxy.ice_pingAsync().add_done_callback(callback) with self.cond: - if not ident in self.processControllerProxies: + if ident not in self.processControllerProxies: self.cond.wait(5) if ident in self.processControllerProxies: return self.processControllerProxies[ident] @@ -2811,7 +2811,7 @@ def startEmulator(self, avd): port = -1 out = run("adb devices -l") for p in range(5554, 5586, 2): - if not "emulator-{}".format(p) in out: + if "emulator-{}".format(p) not in out: port = p if port == -1: @@ -2865,7 +2865,7 @@ def startControllerApp(self, current, ident): print("creating virtual device ({0})... ".format(sdk)) try: run("avdmanager -v delete avd -n IceTests") # Delete the created device - except: + except Exception: pass # The SDK is downloaded by test VMs instead of here. # run("sdkmanager \"{0}\"".format(sdk), stdout=True, stdin="yes", stdinRepeat=True) # yes to accept licenses @@ -2879,7 +2879,7 @@ def startControllerApp(self, current, ident): # First try uninstall in case the controller was left behind from a previous run try: run("{} shell pm uninstall com.zeroc.testcontroller".format(self.adb())) - except: + except Exception: pass run( "{} install -t -r {}".format( @@ -2895,13 +2895,13 @@ def startControllerApp(self, current, ident): def stopControllerApp(self, ident): try: run("{} shell pm uninstall com.zeroc.testcontroller".format(self.adb())) - except: + except Exception: pass if self.avd: try: run("{} emu kill".format(self.adb())) - except: + except Exception: pass if self.avd == "IceTests": @@ -2909,7 +2909,7 @@ def stopControllerApp(self, ident): run( "avdmanager -v delete avd -n IceTests" ) # Delete the created device - except: + except Exception: pass # @@ -2919,7 +2919,7 @@ def stopControllerApp(self, ident): sys.stdout.write("Waiting for the emulator to shutdown..") sys.stdout.flush() while True: - if self.emulator.poll() != None: + if self.emulator.poll() is not None: print(" ok") break sys.stdout.write(".") @@ -2928,7 +2928,7 @@ def stopControllerApp(self, ident): try: run("adb kill-server") - except: + except Exception: pass @@ -2946,7 +2946,7 @@ def __init__(self, current): m = re.search("iOS .* \\(.*\\) - (.*)", r) if m: self.runtimeID = m.group(1) - except: + except Exception: pass if not self.runtimeID: self.runtimeID = ( @@ -3035,7 +3035,7 @@ def restartControllerApp(self, current, ident): def stopControllerApp(self, ident): try: run('xcrun simctl uninstall "{0}" {1}'.format(self.device, ident.name)) - except: + except Exception: pass def destroy(self, driver): @@ -3045,7 +3045,7 @@ def destroy(self, driver): sys.stdout.flush() try: run('xcrun simctl shutdown "{0}"'.format(self.simulatorID)) - except: + except Exception: pass print("ok") @@ -3054,7 +3054,7 @@ def destroy(self, driver): sys.stdout.flush() try: run('xcrun simctl delete "{0}"'.format(self.simulatorID)) - except: + except Exception: pass print("ok") @@ -3145,7 +3145,7 @@ def __init__(self, current): self.driver = webdriver.Safari(service=service) else: self.driver = getattr(webdriver, driver)() - except: + except Exception: self.destroy(current.driver) raise @@ -3212,7 +3212,7 @@ def getControllerIdentity(self, current): Test.Common.BrowserProcessControllerPrx.uncheckedCast(prx).redirect( url ) - except: + except Exception: pass finally: self.clearProcessController(prx, prx.ice_getCachedConnection()) @@ -3242,7 +3242,7 @@ def getController(self, current): # Print out the browser log try: print("browser log:\n{0}".format(self.driver.get_log("browser"))) - except: + except Exception: pass # Not all browsers support retrieving the browser console log raise ex @@ -3254,7 +3254,7 @@ def destroy(self, driver): try: self.driver.quit() - except: + except Exception: pass @@ -3315,8 +3315,8 @@ def createFile(self, path, lines, encoding=None): with open(path, "w", encoding=encoding) if encoding else open( path, "w" ) as file: - for l in lines: - file.write("%s\n" % l) + for line in lines: + file.write("%s\n" % line) self.files.append(path) def mkdirs(self, dirs): @@ -3441,12 +3441,14 @@ def __init__(self, options, component): if self.languages: self.languages = [ - i for sublist in [l.split(",") for l in self.languages] for i in sublist + i + for sublist in [lang.split(",") for lang in self.languages] + for i in sublist ] if self.rlanguages: self.rlanguages = [ i - for sublist in [l.split(",") for l in self.rlanguages] + for sublist in [lang.split(",") for lang in self.rlanguages] for i in sublist ] @@ -4109,7 +4111,7 @@ def getPythonVersion(self): 'import sys; print("{0}.{1}".format(sys.version_info[0], sys.version_info[1]))', ] ) - if type(version) != str: + if not isinstance(version, str): version = version.decode("utf-8") self.pythonVersion = tuple(int(num) for num in version.split(".")) return self.pythonVersion @@ -4583,7 +4585,7 @@ def getXcodeProject(self, current): # # Import component classes and instantiate the default component # -from Component import * +from Component import component # noqa: F401, E402 # # Initialize the platform with component @@ -4591,9 +4593,11 @@ def getXcodeProject(self, current): platform.init(component) # -# Import local driver +# Import local driver (this adds the local driver to the list of supported drivers) # -from LocalDriver import * +import LocalDriver # noqa: F401, E402 + +Driver.add("local", LocalDriver.LocalDriver) def runTestsWithPath(path): @@ -4686,6 +4690,6 @@ def usage(): finally: driver.destroy() - except Exception as e: + except Exception: print(sys.argv[0] + ": unexpected exception raised:\n" + traceback.format_exc()) sys.exit(1) diff --git a/scripts/icehashpassword.py b/scripts/icehashpassword.py index e7978fdaf28..afa2f2670f6 100755 --- a/scripts/icehashpassword.py +++ b/scripts/icehashpassword.py @@ -83,14 +83,14 @@ def main(): elif o in ("-s", "--salt"): try: salt = int(a) - except ValueError as err: + except ValueError: print("Invalid salt size. Value must be an integer") usage() return 2 elif o in ("-r", "--rounds"): try: rounds = int(a) - except ValueError as err: + except ValueError: print("Invalid number of rounds. Value must be an integer") usage() return 2 diff --git a/scripts/tests/Glacier2/application.py b/scripts/tests/Glacier2/application.py index 089c3a4aec2..7f27d0e2a9c 100644 --- a/scripts/tests/Glacier2/application.py +++ b/scripts/tests/Glacier2/application.py @@ -3,4 +3,7 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # +from Glacier2Util import Glacier2TestSuite + + Glacier2TestSuite(__name__, routerProps={"Glacier2.SessionTimeout": 30}) diff --git a/scripts/tests/Glacier2/router.py b/scripts/tests/Glacier2/router.py index e03b99b15e4..6026bb6a5b9 100644 --- a/scripts/tests/Glacier2/router.py +++ b/scripts/tests/Glacier2/router.py @@ -3,13 +3,17 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # +from Glacier2Util import Glacier2Router, Glacier2TestSuite +from Util import Client, ClientServerTestCase, Server + + passwords = { "userid": "abc123", "userid-0": "abc123", "userid-1": "abc123", "userid-2": "abc123", "userid-3": "abc123", - "userid-4": "abc123" + "userid-4": "abc123", } routerProps = { @@ -31,12 +35,27 @@ def buffered(enabled): return {"Glacier2.Client.Buffered": enabled, "Glacier2.Server.Buffered": enabled} -Glacier2TestSuite(__name__, routerProps, [ - ClientServerTestCase(name="client/server with router in unbuffered mode", - servers=[Glacier2Router(passwords=passwords, props=buffered(False)), Server()], - client=Client(args=["--shutdown"]), - traceProps=traceProps), - ClientServerTestCase(name="client/server with router in buffered mode", - servers=[Glacier2Router(passwords=passwords, props=buffered(True)), Server()], - clients=[Client(), Client(args=["--shutdown"])], - traceProps=traceProps)]) +Glacier2TestSuite( + __name__, + routerProps, + [ + ClientServerTestCase( + name="client/server with router in unbuffered mode", + servers=[ + Glacier2Router(passwords=passwords, props=buffered(False)), + Server(), + ], + client=Client(args=["--shutdown"]), + traceProps=traceProps, + ), + ClientServerTestCase( + name="client/server with router in buffered mode", + servers=[ + Glacier2Router(passwords=passwords, props=buffered(True)), + Server(), + ], + clients=[Client(), Client(args=["--shutdown"])], + traceProps=traceProps, + ), + ], +) diff --git a/scripts/tests/Glacier2/sessionHelper.py b/scripts/tests/Glacier2/sessionHelper.py index 435a3488299..4ab17306ed1 100644 --- a/scripts/tests/Glacier2/sessionHelper.py +++ b/scripts/tests/Glacier2/sessionHelper.py @@ -3,4 +3,7 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # +from Glacier2Util import Glacier2TestSuite + + Glacier2TestSuite(__name__, routerProps={"Glacier2.Client.ACM.Timeout": 30}) diff --git a/scripts/tests/Ice/adapterDeactivation.py b/scripts/tests/Ice/adapterDeactivation.py index 01239f17d70..e99077122f6 100644 --- a/scripts/tests/Ice/adapterDeactivation.py +++ b/scripts/tests/Ice/adapterDeactivation.py @@ -3,4 +3,7 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # +from Util import TestSuite + + TestSuite(__name__, multihost=False) diff --git a/scripts/tests/Ice/admin.py b/scripts/tests/Ice/admin.py index 92a2ac7f608..ded84aa418f 100644 --- a/scripts/tests/Ice/admin.py +++ b/scripts/tests/Ice/admin.py @@ -3,4 +3,7 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # +from Util import TestSuite + + TestSuite(__name__, options={"ipv6": [False]}, multihost=False) diff --git a/scripts/tests/Ice/ami.py b/scripts/tests/Ice/ami.py index eea41489e6c..6a33e4bcdf1 100644 --- a/scripts/tests/Ice/ami.py +++ b/scripts/tests/Ice/ami.py @@ -4,15 +4,13 @@ # # Enable some tracing to allow investigating test failures -traceProps = { - "Ice.Trace.Network": 2, - "Ice.Trace.Retry": 1, - "Ice.Trace.Protocol": 1 -} +from Util import ClientServerTestCase, CollocatedTestCase, Mapping, TestSuite + + +traceProps = {"Ice.Trace.Network": 2, "Ice.Trace.Retry": 1, "Ice.Trace.Protocol": 1} testcases = [ClientServerTestCase(traceProps=traceProps)] if Mapping.getByPath(__name__).hasSource("Ice/ami", "collocated"): testcases += [CollocatedTestCase()] -TestSuite(__name__, testcases, - options={"compress": [False], "serialize": [False]}) +TestSuite(__name__, testcases, options={"compress": [False], "serialize": [False]}) diff --git a/scripts/tests/Ice/background.py b/scripts/tests/Ice/background.py index 688997af769..ac0192a0d2b 100644 --- a/scripts/tests/Ice/background.py +++ b/scripts/tests/Ice/background.py @@ -2,4 +2,7 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # +from Util import TestSuite + + TestSuite(__name__, libDirs=["testtransport"], options={"mx": [False]}) diff --git a/scripts/tests/Ice/binding.py b/scripts/tests/Ice/binding.py index 1b84cc6324b..961dc882181 100644 --- a/scripts/tests/Ice/binding.py +++ b/scripts/tests/Ice/binding.py @@ -3,6 +3,9 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # +from Util import ClientServerTestCase, Server, TestSuite, Windows, platform + + def setlimits(): if not isinstance(platform, Windows): # @@ -10,6 +13,7 @@ def setlimits(): # which could otherwise potentially allocate many file descriptors on the system. # import resource + resource.setrlimit(resource.RLIMIT_NOFILE, (92, 92)) diff --git a/scripts/tests/Ice/enums.py b/scripts/tests/Ice/enums.py index 086a09fd427..85c3f584272 100644 --- a/scripts/tests/Ice/enums.py +++ b/scripts/tests/Ice/enums.py @@ -2,7 +2,16 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # -TestSuite(__name__, [ - ClientServerTestCase("client/server with default encoding"), - ClientServerTestCase("client/server with 1.0 encoding", props={"Ice.Default.EncodingVersion": "1.0"}), -]) +from Util import ClientServerTestCase, TestSuite + + +TestSuite( + __name__, + [ + ClientServerTestCase("client/server with default encoding"), + ClientServerTestCase( + "client/server with 1.0 encoding", + props={"Ice.Default.EncodingVersion": "1.0"}, + ), + ], +) diff --git a/scripts/tests/Ice/exceptions.py b/scripts/tests/Ice/exceptions.py index 407eec045c1..b2401cc0bf4 100644 --- a/scripts/tests/Ice/exceptions.py +++ b/scripts/tests/Ice/exceptions.py @@ -2,18 +2,37 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # +from Util import ( + ClientAMDServerTestCase, + ClientServerTestCase, + CollocatedTestCase, + Mapping, + TestSuite, +) + + testcases = [ ClientServerTestCase("client/server with compact format"), - ClientServerTestCase("client/server with sliced format", props={"Ice.Default.SlicedFormat": True}), - ClientServerTestCase("client/server with 1.0 encoding", props={"Ice.Default.EncodingVersion": "1.0"}), + ClientServerTestCase( + "client/server with sliced format", props={"Ice.Default.SlicedFormat": True} + ), + ClientServerTestCase( + "client/server with 1.0 encoding", props={"Ice.Default.EncodingVersion": "1.0"} + ), ] # If the mapping has AMD servers, also run with the AMD servers if Mapping.getByPath(__name__).hasSource("Ice/exceptions", "serveramd"): testcases += [ ClientAMDServerTestCase("client/amd server with compact format"), - ClientAMDServerTestCase("client/amd server with sliced format", props={"Ice.Default.SlicedFormat": True}), - ClientAMDServerTestCase("client/amd server with 1.0 encoding", props={"Ice.Default.EncodingVersion": "1.0"}), + ClientAMDServerTestCase( + "client/amd server with sliced format", + props={"Ice.Default.SlicedFormat": True}, + ), + ClientAMDServerTestCase( + "client/amd server with 1.0 encoding", + props={"Ice.Default.EncodingVersion": "1.0"}, + ), ] if Mapping.getByPath(__name__).hasSource("Ice/exceptions", "collocated"): diff --git a/scripts/tests/Ice/faultTolerance.py b/scripts/tests/Ice/faultTolerance.py index 3ec75d00ec1..76d90003324 100755 --- a/scripts/tests/Ice/faultTolerance.py +++ b/scripts/tests/Ice/faultTolerance.py @@ -2,14 +2,13 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # -from Util import * -# This is used for the trace file +from Util import Client, ClientServerTestCase, Server, TestSuite -def props(process, current): return { - "Ice.ProgramName": "server{}".format(process.args[0]) -} +# This is used for the trace file +def props(process, current): + return {"Ice.ProgramName": "server{}".format(process.args[0])} # Enable some tracing to allow investigating test failures @@ -24,8 +23,16 @@ def props(process, current): return { # servers = range(1, 13) -TestSuite(__name__, [ - ClientServerTestCase(client=Client(args=[i for i in servers]), - servers=[Server(args=[i], waitForShutdown=False, props=props, quiet=True) for i in servers], - traceProps=traceProps) -]) +TestSuite( + __name__, + [ + ClientServerTestCase( + client=Client(args=[i for i in servers]), + servers=[ + Server(args=[i], waitForShutdown=False, props=props, quiet=True) + for i in servers + ], + traceProps=traceProps, + ) + ], +) diff --git a/scripts/tests/Ice/hold.py b/scripts/tests/Ice/hold.py index 9e389bc9ed2..da188128b7e 100644 --- a/scripts/tests/Ice/hold.py +++ b/scripts/tests/Ice/hold.py @@ -3,4 +3,7 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # +from Util import ClientServerTestCase, Server, TestSuite + + TestSuite(__name__, [ClientServerTestCase(server=Server(readyCount=2))]) diff --git a/scripts/tests/Ice/info.py b/scripts/tests/Ice/info.py index 1363cf46890..1e84d913152 100644 --- a/scripts/tests/Ice/info.py +++ b/scripts/tests/Ice/info.py @@ -3,4 +3,7 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # +from Util import TestSuite + + TestSuite(__name__, options={"ipv6": [False], "compress": [False]}, multihost=False) diff --git a/scripts/tests/Ice/interceptor.py b/scripts/tests/Ice/interceptor.py index 6bcbe8faad2..1159e9ee25d 100644 --- a/scripts/tests/Ice/interceptor.py +++ b/scripts/tests/Ice/interceptor.py @@ -2,4 +2,11 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # -TestSuite(__name__, [ClientTestCase(client=Client(props={"Ice.Warn.Dispatch": 0}))], libDirs=["interceptortest"]) +from Util import Client, ClientTestCase, TestSuite + + +TestSuite( + __name__, + [ClientTestCase(client=Client(props={"Ice.Warn.Dispatch": 0}))], + libDirs=["interceptortest"], +) diff --git a/scripts/tests/Ice/interrupt.py b/scripts/tests/Ice/interrupt.py index b91b22956d5..58b6362b187 100644 --- a/scripts/tests/Ice/interrupt.py +++ b/scripts/tests/Ice/interrupt.py @@ -3,4 +3,7 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # +from Util import TestSuite + + TestSuite(__name__, options={"compress": [False]}) diff --git a/scripts/tests/Ice/location.py b/scripts/tests/Ice/location.py index ae3dfd55e52..092f0dc1914 100644 --- a/scripts/tests/Ice/location.py +++ b/scripts/tests/Ice/location.py @@ -4,9 +4,9 @@ # # Enable some tracing to allow investigating test failures -traceProps = { - "Ice.Trace.Locator": 2, - "Ice.Trace.Protocol": 1 -} +from Util import ClientServerTestCase, TestSuite + + +traceProps = {"Ice.Trace.Locator": 2, "Ice.Trace.Protocol": 1} TestSuite(__name__, [ClientServerTestCase(traceProps=traceProps)]) diff --git a/scripts/tests/Ice/metrics.py b/scripts/tests/Ice/metrics.py index 671ebcfbb5c..c9ed2f20335 100644 --- a/scripts/tests/Ice/metrics.py +++ b/scripts/tests/Ice/metrics.py @@ -3,12 +3,16 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # +from Util import ( + ClientAMDServerTestCase, + ClientServerTestCase, + CollocatedTestCase, + Mapping, + TestSuite, +) + # Enable some tracing to allow investigating test failures -traceProps = { - "Ice.Trace.Network": 2, - "Ice.Trace.Retry": 1, - "Ice.Trace.Protocol": 1 -} +traceProps = {"Ice.Trace.Network": 2, "Ice.Trace.Retry": 1, "Ice.Trace.Protocol": 1} testcases = [ ClientServerTestCase(traceProps=traceProps), ] @@ -17,6 +21,9 @@ if Mapping.getByPath(__name__).hasSource("Ice/metrics", "collocated"): testcases += [CollocatedTestCase(traceProps=traceProps)] -TestSuite(__name__, testcases, - options={"ipv6": [False], "compress": [False], "protocol": ["tcp", "ssl"]}, - multihost=False) +TestSuite( + __name__, + testcases, + options={"ipv6": [False], "compress": [False], "protocol": ["tcp", "ssl"]}, + multihost=False, +) diff --git a/scripts/tests/Ice/networkProxy.py b/scripts/tests/Ice/networkProxy.py index 226ba02e7b1..addbb3c6cbc 100644 --- a/scripts/tests/Ice/networkProxy.py +++ b/scripts/tests/Ice/networkProxy.py @@ -3,21 +3,28 @@ # import NetworkProxy +from Util import Client, ClientServerTestCase, TestSuite class NetworkProxyTestSuite(TestSuite): - def setup(self, current): self.portNum = 30 class NetworkProxyTestCase(ClientServerTestCase): - def __init__(self, proxyName, proxyType): - ClientServerTestCase.__init__(self, proxyName + " client/server", client=Client(props=lambda p, c: { - "Ice.{0}ProxyHost".format(proxyName): "localhost", - "Ice.{0}ProxyPort".format(proxyName): "{0}".format(c.driver.getTestPort(c.testsuite.portNum)) - })) + ClientServerTestCase.__init__( + self, + proxyName + " client/server", + client=Client( + props=lambda p, c: { + "Ice.{0}ProxyHost".format(proxyName): "localhost", + "Ice.{0}ProxyPort".format(proxyName): "{0}".format( + c.driver.getTestPort(c.testsuite.portNum) + ), + } + ), + ) self.proxyName = proxyName self.proxyType = proxyType self.proxy = None @@ -29,7 +36,9 @@ def canRun(self, current): def setupClientSide(self, current): current.write("starting {0} proxy... ".format(self.proxyName)) - self.proxy = self.proxyType(current.driver.getTestPort(current.testsuite.portNum)) + self.proxy = self.proxyType( + current.driver.getTestPort(current.testsuite.portNum) + ) current.writeln("ok") def teardownClientSide(self, current, success): @@ -40,7 +49,11 @@ def teardownClientSide(self, current, success): current.writeln("ok") -NetworkProxyTestSuite(__name__, [ - NetworkProxyTestCase("SOCKS", NetworkProxy.SocksProxy), - NetworkProxyTestCase("HTTP", NetworkProxy.HttpProxy), -], options={"ipv6": [False]}) +NetworkProxyTestSuite( + __name__, + [ + NetworkProxyTestCase("SOCKS", NetworkProxy.SocksProxy), + NetworkProxyTestCase("HTTP", NetworkProxy.HttpProxy), + ], + options={"ipv6": [False]}, +) diff --git a/scripts/tests/Ice/objects.py b/scripts/tests/Ice/objects.py index 8fac1ee78af..e324faea61f 100644 --- a/scripts/tests/Ice/objects.py +++ b/scripts/tests/Ice/objects.py @@ -8,8 +8,10 @@ # a client stack overflow if the client stack is too small compared to the # Java server stack. # -class ObjectClientServerTestCase(ClientServerTestCase): +from Util import ClientServerTestCase, CollocatedTestCase, Mapping, Server, TestSuite + +class ObjectClientServerTestCase(ClientServerTestCase): def getProps(self, process, current): props = ClientServerTestCase.getProps(self, process, current) if process.getMapping(current) in ["java"] and isinstance(process, Server): @@ -32,8 +34,12 @@ def getProps(self, process, current): testcases = [ ObjectClientServerTestCase("client/server with compact format"), - ObjectClientServerTestCase("client/server with sliced format", props={"Ice.Default.SlicedFormat": True}), - ObjectClientServerTestCase("client/server with 1.0 encoding", props={"Ice.Default.EncodingVersion": "1.0"}), + ObjectClientServerTestCase( + "client/server with sliced format", props={"Ice.Default.SlicedFormat": True} + ), + ObjectClientServerTestCase( + "client/server with 1.0 encoding", props={"Ice.Default.EncodingVersion": "1.0"} + ), ] if Mapping.getByPath(__name__).hasSource("Ice/objects", "collocated"): diff --git a/scripts/tests/Ice/optional.py b/scripts/tests/Ice/optional.py index 65c1a026143..4ba814aefb0 100644 --- a/scripts/tests/Ice/optional.py +++ b/scripts/tests/Ice/optional.py @@ -2,16 +2,24 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # +from Util import ClientAMDServerTestCase, ClientServerTestCase, Mapping, TestSuite + + testcases = [ ClientServerTestCase("client/server with compact format"), - ClientServerTestCase("client/server with sliced format", props={"Ice.Default.SlicedFormat": True}), + ClientServerTestCase( + "client/server with sliced format", props={"Ice.Default.SlicedFormat": True} + ), ] # If the mapping has AMD servers, also run with the AMD servers if Mapping.getByPath(__name__).hasSource("Ice/optional", "serveramd"): testcases += [ ClientAMDServerTestCase("client/amd server with compact format"), - ClientAMDServerTestCase("client/amd server with sliced format", props={"Ice.Default.SlicedFormat": True}), + ClientAMDServerTestCase( + "client/amd server with sliced format", + props={"Ice.Default.SlicedFormat": True}, + ), ] TestSuite(__name__, testcases) diff --git a/scripts/tests/Ice/properties.py b/scripts/tests/Ice/properties.py index ce45a2660e1..536101f544b 100644 --- a/scripts/tests/Ice/properties.py +++ b/scripts/tests/Ice/properties.py @@ -3,17 +3,23 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # -class PropertiesTestSuite(TestSuite): +from Util import Client, ClientTestCase, TestSuite + +class PropertiesTestSuite(TestSuite): def setup(self, current): name = "\u4e2d\u56fd_client.config" - current.createFile("./config/" + name, - ["# Automatically generated by Ice test driver.", - "Ice.Trace.Protocol=1", - "Ice.Trace.Network=1", - "Ice.ProgramName=PropertiesClient", - "Config.Path=./config/" + name], - "utf-8") + current.createFile( + "./config/" + name, + [ + "# Automatically generated by Ice test driver.", + "Ice.Trace.Protocol=1", + "Ice.Trace.Network=1", + "Ice.ProgramName=PropertiesClient", + "Config.Path=./config/" + name, + ], + "utf-8", + ) PropertiesTestSuite(__name__, [ClientTestCase(client=Client(args=["{testdir}"]))]) diff --git a/scripts/tests/Ice/retry.py b/scripts/tests/Ice/retry.py index 81ac0858bdf..8e4a8f5115f 100644 --- a/scripts/tests/Ice/retry.py +++ b/scripts/tests/Ice/retry.py @@ -4,11 +4,10 @@ # # Enable some tracing to allow investigating test failures -traceProps = { - "Ice.Trace.Network": 2, - "Ice.Trace.Retry": 1, - "Ice.Trace.Protocol": 1 -} +from Util import ClientServerTestCase, CollocatedTestCase, Mapping, TestSuite + + +traceProps = {"Ice.Trace.Network": 2, "Ice.Trace.Retry": 1, "Ice.Trace.Protocol": 1} testcases = [ClientServerTestCase(traceProps=traceProps)] diff --git a/scripts/tests/Ice/slicing/exceptions.py b/scripts/tests/Ice/slicing/exceptions.py index 47823f33478..dbff1337326 100644 --- a/scripts/tests/Ice/slicing/exceptions.py +++ b/scripts/tests/Ice/slicing/exceptions.py @@ -2,16 +2,24 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # +from Util import ClientAMDServerTestCase, ClientServerTestCase, Mapping, TestSuite + + testcases = [ ClientServerTestCase(), - ClientServerTestCase("client/server with 1.0 encoding", props={"Ice.Default.EncodingVersion": "1.0"}), + ClientServerTestCase( + "client/server with 1.0 encoding", props={"Ice.Default.EncodingVersion": "1.0"} + ), ] # If the mapping has AMD servers, also run with the AMD servers if Mapping.getByPath(__name__).hasSource("Ice/exceptions", "serveramd"): testcases += [ ClientAMDServerTestCase(), - ClientAMDServerTestCase("client/amd server with 1.0 encoding", props={"Ice.Default.EncodingVersion": "1.0"}), + ClientAMDServerTestCase( + "client/amd server with 1.0 encoding", + props={"Ice.Default.EncodingVersion": "1.0"}, + ), ] TestSuite(__name__, testcases, options={"serialize": [False]}) diff --git a/scripts/tests/Ice/slicing/objects.py b/scripts/tests/Ice/slicing/objects.py index 0f4a865eeb1..201dd23d2d3 100644 --- a/scripts/tests/Ice/slicing/objects.py +++ b/scripts/tests/Ice/slicing/objects.py @@ -2,7 +2,17 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # -TestSuite(__name__, [ - ClientServerTestCase(), - ClientServerTestCase("client/server with 1.0 encoding", props={"Ice.Default.EncodingVersion": "1.0"}), -], options={"valgrind": [False]}) +from Util import ClientServerTestCase, TestSuite + + +TestSuite( + __name__, + [ + ClientServerTestCase(), + ClientServerTestCase( + "client/server with 1.0 encoding", + props={"Ice.Default.EncodingVersion": "1.0"}, + ), + ], + options={"valgrind": [False]}, +) diff --git a/scripts/tests/Ice/stream.py b/scripts/tests/Ice/stream.py index ffcae89db0c..6154a08dc96 100644 --- a/scripts/tests/Ice/stream.py +++ b/scripts/tests/Ice/stream.py @@ -2,7 +2,15 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # -TestSuite(__name__, [ - ClientTestCase("client with default encoding"), - ClientTestCase("client with 1.0 encoding", props={"Ice.Default.EncodingVersion": "1.0"}) -]) +from Util import ClientTestCase, TestSuite + + +TestSuite( + __name__, + [ + ClientTestCase("client with default encoding"), + ClientTestCase( + "client with 1.0 encoding", props={"Ice.Default.EncodingVersion": "1.0"} + ), + ], +) diff --git a/scripts/tests/Ice/timeout.py b/scripts/tests/Ice/timeout.py index 4609c52eccd..ab2e5211344 100644 --- a/scripts/tests/Ice/timeout.py +++ b/scripts/tests/Ice/timeout.py @@ -4,11 +4,13 @@ # # Enable some tracing to allow investigating test failures -traceProps = { - "Ice.Trace.Network": 2, - "Ice.Trace.Retry": 1, - "Ice.Trace.Protocol": 1 -} - -TestSuite(__name__, [ClientServerTestCase(server=Server(readyCount=2), - traceProps=traceProps)], options={"compress": [False]}, ) +from Util import ClientServerTestCase, Server, TestSuite + + +traceProps = {"Ice.Trace.Network": 2, "Ice.Trace.Retry": 1, "Ice.Trace.Protocol": 1} + +TestSuite( + __name__, + [ClientServerTestCase(server=Server(readyCount=2), traceProps=traceProps)], + options={"compress": [False]}, +) diff --git a/scripts/tests/Ice/udp.py b/scripts/tests/Ice/udp.py index 6c427fa05b1..cc9b56b2a42 100644 --- a/scripts/tests/Ice/udp.py +++ b/scripts/tests/Ice/udp.py @@ -2,16 +2,18 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # -from Util import * +from Util import Client, ClientServerTestCase, Server, TestSuite -class UdpTestCase(ClientServerTestCase): +class UdpTestCase(ClientServerTestCase): def setupServerSide(self, current): if current.config.android: self.servers = [Server(ready="McastTestAdapter")] else: - self.servers = [Server(args=[i], ready="McastTestAdapter") for i in range(0, 5)] + self.servers = [ + Server(args=[i], ready="McastTestAdapter") for i in range(0, 5) + ] def setupClientSide(self, current): if current.config.android: diff --git a/scripts/tests/IceBox/admin.py b/scripts/tests/IceBox/admin.py index 24e3049fffb..041e3450722 100644 --- a/scripts/tests/IceBox/admin.py +++ b/scripts/tests/IceBox/admin.py @@ -3,27 +3,32 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # -class IceBoxAdminTestCase(ClientServerTestCase): +from IceBoxUtil import IceBox, IceBoxAdmin +from Util import ClientServerTestCase, TestSuite - def runClientSide(self, current): +class IceBoxAdminTestCase(ClientServerTestCase): + def runClientSide(self, current): admin = IceBoxAdmin(args=['--Ice.Config="{testdir}/config.admin"']) current.write("testing service stop...") - admin.run(current, args=['stop', 'TestService']) + admin.run(current, args=["stop", "TestService"]) current.writeln("ok") current.write("testing service start...") - admin.run(current, args=['start', 'TestService']) + admin.run(current, args=["start", "TestService"]) current.writeln("ok") current.write("testing shutdown...") - admin.run(current, args=['shutdown']) + admin.run(current, args=["shutdown"]) current.writeln("ok") -TestSuite(__name__, [ - ClientServerTestCase(server=IceBox("{testdir}/config.icebox")), - IceBoxAdminTestCase("iceboxadmin", server=IceBox("{testdir}/config.icebox")), -], +TestSuite( + __name__, + [ + ClientServerTestCase(server=IceBox("{testdir}/config.icebox")), + IceBoxAdminTestCase("iceboxadmin", server=IceBox("{testdir}/config.icebox")), + ], libDirs=["testservice"], runOnMainThread=True, options={"ipv6": [False], "mx": [False], "cpp11": [False]}, - multihost=False) + multihost=False, +) diff --git a/scripts/tests/IceBox/configuration.py b/scripts/tests/IceBox/configuration.py index 63d02090837..7038813a468 100644 --- a/scripts/tests/IceBox/configuration.py +++ b/scripts/tests/IceBox/configuration.py @@ -3,7 +3,22 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # -TestSuite(__name__, [ - ClientServerTestCase("client/server #1", server=IceBox("{testdir}/config.icebox")), - ClientServerTestCase("client/server #2", server=IceBox("{testdir}/config.icebox2")) -], libDirs=["testservice"], runOnMainThread=True, options={"protocol": ["tcp"], "ipv6": [False], "mx": [False]}, multihost=False) +from IceBoxUtil import IceBox +from Util import ClientServerTestCase, TestSuite + + +TestSuite( + __name__, + [ + ClientServerTestCase( + "client/server #1", server=IceBox("{testdir}/config.icebox") + ), + ClientServerTestCase( + "client/server #2", server=IceBox("{testdir}/config.icebox2") + ), + ], + libDirs=["testservice"], + runOnMainThread=True, + options={"protocol": ["tcp"], "ipv6": [False], "mx": [False]}, + multihost=False, +) diff --git a/scripts/tests/IceDiscovery/simple.py b/scripts/tests/IceDiscovery/simple.py index 22ecce4a982..eb78598d584 100644 --- a/scripts/tests/IceDiscovery/simple.py +++ b/scripts/tests/IceDiscovery/simple.py @@ -3,28 +3,34 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # +import re import uuid +from Util import AIX, Client, ClientServerTestCase, Linux, Server, TestSuite, platform + domainId = uuid.uuid4() # Ensures each test uses a unique domain ID -def props(process, current): return { - "IceDiscovery.Timeout": 50, - "IceDiscovery.RetryCount": 20, - "IceDiscovery.DomainId": domainId, - "IceDiscovery.Interface": "" if isinstance(platform, Linux) else "::1" if current.config.ipv6 else "127.0.0.1", - "IceDiscovery.Port": current.driver.getTestPort(10), - "Ice.Plugin.IceDiscovery": current.getPluginEntryPoint("IceDiscovery", process), - # This is used for the trace file - "Ice.ProgramName": "server{}".format(process.args[0]) if isinstance(process, Server) else "client" -} +def props(process, current): + return { + "IceDiscovery.Timeout": 50, + "IceDiscovery.RetryCount": 20, + "IceDiscovery.DomainId": domainId, + "IceDiscovery.Interface": "" + if isinstance(platform, Linux) + else "::1" + if current.config.ipv6 + else "127.0.0.1", + "IceDiscovery.Port": current.driver.getTestPort(10), + "Ice.Plugin.IceDiscovery": current.getPluginEntryPoint("IceDiscovery", process), + # This is used for the trace file + "Ice.ProgramName": "server{}".format(process.args[0]) + if isinstance(process, Server) + else "client", + } -traceProps = { - "Ice.Trace.Locator": 2, - "Ice.Trace.Protocol": 1, - "Ice.Trace.Network": 3 -} +traceProps = {"Ice.Trace.Locator": 2, "Ice.Trace.Protocol": 1, "Ice.Trace.Network": 3} # # Suppress the warning lines @@ -53,8 +59,15 @@ def suppressWarning(x): # where multicast doesn't work options = {"ipv6": [False]} -TestSuite(__name__, [ - ClientServerTestCase(client=Client(args=[3], props=props, outfilters=outfilters), - servers=[Server(args=[i], readyCount=4, props=props) for i in range(0, 3)], - traceProps=traceProps) -], multihost=False, options=options) +TestSuite( + __name__, + [ + ClientServerTestCase( + client=Client(args=[3], props=props, outfilters=outfilters), + servers=[Server(args=[i], readyCount=4, props=props) for i in range(0, 3)], + traceProps=traceProps, + ) + ], + multihost=False, + options=options, +) diff --git a/scripts/tests/IceGrid/simple.py b/scripts/tests/IceGrid/simple.py index b96637a6e20..db7a1975ddf 100644 --- a/scripts/tests/IceGrid/simple.py +++ b/scripts/tests/IceGrid/simple.py @@ -3,42 +3,78 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # +import os +import re +from IceGridUtil import ( + IceGridRegistryMaster, + IceGridRegistrySlave, + IceGridTestCase, + IceGridClient, + IceGridServer, +) +from Util import ClientServerTestCase, Linux, TestSuite, Windows, platform + + serverProps = { "TestAdapter.Endpoints": "default", - "TestAdapter.AdapterId": "TestAdapter" + "TestAdapter.AdapterId": "TestAdapter", } -registryProps = { - "IceGrid.Registry.DynamicRegistration": 1 -} -registryTraceProps = { - "IceGrid.Registry.Trace.Discovery": 2 -} +registryProps = {"IceGrid.Registry.DynamicRegistration": 1} +registryTraceProps = {"IceGrid.Registry.Trace.Discovery": 2} -def clientProps(process, current): return { - "IceLocatorDiscovery.Timeout": 50, - "IceLocatorDiscovery.RetryCount": 5, - "IceLocatorDiscovery.Interface": "" if isinstance(platform, Linux) else "::1" if current.config.ipv6 else "127.0.0.1", - "IceLocatorDiscovery.Port": current.driver.getTestPort(99), -} +def clientProps(process, current): + return { + "IceLocatorDiscovery.Timeout": 50, + "IceLocatorDiscovery.RetryCount": 5, + "IceLocatorDiscovery.Interface": "" + if isinstance(platform, Linux) + else "::1" + if current.config.ipv6 + else "127.0.0.1", + "IceLocatorDiscovery.Port": current.driver.getTestPort(99), + } clientTraceProps = {"IceLocatorDiscovery.Trace.Lookup": 3} # Filter-out the warning about invalid lookup proxy -outfilters = [lambda x: re.sub("-! .* warning: .*failed to lookup locator.*\n", "", x), - lambda x: re.sub("^ .*\n", "", x)] +outfilters = [ + lambda x: re.sub("-! .* warning: .*failed to lookup locator.*\n", "", x), + lambda x: re.sub("^ .*\n", "", x), +] if isinstance(platform, Windows) or os.getuid() != 0: - TestSuite(__name__, [ - IceGridTestCase("without deployment", application=None, - icegridregistry=[IceGridRegistryMaster(props=registryProps, traceProps=registryTraceProps), - IceGridRegistrySlave(1, props=registryProps, traceProps=registryTraceProps), - IceGridRegistrySlave(2, props=registryProps, traceProps=registryTraceProps)], - client=ClientServerTestCase(client=IceGridClient(props=clientProps, - outfilters=outfilters, - traceProps=clientTraceProps), - server=IceGridServer(props=serverProps))), - IceGridTestCase("with deployment", client=IceGridClient(args=["--with-deploy"])) - ], multihost=False) + TestSuite( + __name__, + [ + IceGridTestCase( + "without deployment", + application=None, + icegridregistry=[ + IceGridRegistryMaster( + props=registryProps, traceProps=registryTraceProps + ), + IceGridRegistrySlave( + 1, props=registryProps, traceProps=registryTraceProps + ), + IceGridRegistrySlave( + 2, props=registryProps, traceProps=registryTraceProps + ), + ], + client=ClientServerTestCase( + client=IceGridClient( + props=clientProps, + outfilters=outfilters, + traceProps=clientTraceProps, + ), + server=IceGridServer(props=serverProps), + ), + ), + IceGridTestCase( + "with deployment", client=IceGridClient(args=["--with-deploy"]) + ), + ], + multihost=False, + ) diff --git a/scripts/tests/IceSSL/configuration.py b/scripts/tests/IceSSL/configuration.py index e45d037ae69..89d17588c52 100644 --- a/scripts/tests/IceSSL/configuration.py +++ b/scripts/tests/IceSSL/configuration.py @@ -4,25 +4,44 @@ # import os +import shutil +from Util import ( + Client, + ClientServerTestCase, + CppMapping, + Darwin, + Server, + TestSuite, + Windows, + run, + platform, +) -class ConfigurationTestCase(ClientServerTestCase): +class ConfigurationTestCase(ClientServerTestCase): def setupServerSide(self, current): # Nothing to do if we're not running this test with the C++ mapping if not isinstance(self.getMapping(), CppMapping): return - certsPath = os.path.abspath(os.path.join(current.testsuite.getPath(), "..", "certs")) + certsPath = os.path.abspath( + os.path.join(current.testsuite.getPath(), "..", "certs") + ) self.crlServer = None self.ocspServer = None if isinstance(platform, Windows) or isinstance(platform, Darwin): from scripts.tests.IceSSL import revocationutil - self.crlServer = revocationutil.createCRLServer('127.0.0.1', 20001, certsPath) + + self.crlServer = revocationutil.createCRLServer( + "127.0.0.1", 20001, certsPath + ) self.crlServer.start() - self.ocspServer = revocationutil.createOCSPServer('127.0.0.1', 20002, certsPath) + self.ocspServer = revocationutil.createOCSPServer( + "127.0.0.1", 20002, certsPath + ) self.ocspServer.start() if isinstance(platform, Darwin) and current.config.buildPlatform == "macosx": @@ -30,14 +49,18 @@ def setupServerSide(self, current): os.system("mkdir -p {0}".format(os.path.join(certsPath, "keychain"))) os.system("security create-keychain -p password %s" % keychainPath) for cert in ["s_rsa_ca1.p12", "c_rsa_ca1.p12"]: - os.system("security import %s -f pkcs12 -A -P password -k %s" % - (os.path.join(certsPath, cert), keychainPath)) + os.system( + "security import %s -f pkcs12 -A -P password -k %s" + % (os.path.join(certsPath, cert), keychainPath) + ) elif current.config.openssl or platform.hasOpenSSL(): if isinstance(platform, Windows): conf = os.path.join(current.testsuite.getPath(), "openssl.cnf") os.environ["OPENSSL_CONF"] = conf with open(conf, "w") as file: - file.write("# Dummy openssl configuration file to avoid warnings with Windows testing") + file.write( + "# Dummy openssl configuration file to avoid warnings with Windows testing" + ) # # Create copies of the CA certificates named after the subject @@ -46,8 +69,11 @@ def setupServerSide(self, current): # for c in ["cacert1.pem", "cacert2.pem"]: pem = os.path.join(certsPath, c) - out = run("{openssl} x509 -subject_hash -noout -in {pem}".format(pem=pem, - openssl=self.getOpenSSLCommand(current))) + out = run( + "{openssl} x509 -subject_hash -noout -in {pem}".format( + pem=pem, openssl=self.getOpenSSLCommand(current) + ) + ) shutil.copyfile(pem, "{dir}/{out}.0".format(dir=certsPath, out=out)) def teardownServerSide(self, current, success): @@ -60,15 +86,24 @@ def teardownServerSide(self, current, success): if self.ocspServer: self.ocspServer.shutdown() - certsPath = os.path.abspath(os.path.join(current.testsuite.getPath(), "..", "certs")) + certsPath = os.path.abspath( + os.path.join(current.testsuite.getPath(), "..", "certs") + ) if isinstance(platform, Darwin) and current.config.buildPlatform == "macosx": - os.system("rm -rf {0} {1}".format(os.path.join(certsPath, "keychain"), - os.path.join(certsPath, "Find.keychain"))) + os.system( + "rm -rf {0} {1}".format( + os.path.join(certsPath, "keychain"), + os.path.join(certsPath, "Find.keychain"), + ) + ) elif current.config.openssl or platform.hasOpenSSL(): for c in ["cacert1.pem", "cacert2.pem"]: pem = os.path.join(certsPath, c) - out = run("{openssl} x509 -subject_hash -noout -in {pem}".format(pem=pem, - openssl=self.getOpenSSLCommand(current))) + out = run( + "{openssl} x509 -subject_hash -noout -in {pem}".format( + pem=pem, openssl=self.getOpenSSLCommand(current) + ) + ) os.remove("{dir}/{out}.0".format(out=out, dir=certsPath)) if isinstance(platform, Windows): os.remove(os.path.join(current.testsuite.getPath(), "openssl.cnf")) @@ -76,15 +111,26 @@ def teardownServerSide(self, current, success): def getOpenSSLCommand(self, current): if isinstance(platform, Windows): - return os.path.join(current.testsuite.getPath(), "..", "..", "..", "msbuild", "packages", - "zeroc.openssl.v143.1.1.1.3", "build", "native", "bin", "Win32", "Release", - "openssl.exe") + return os.path.join( + current.testsuite.getPath(), + "..", + "..", + "..", + "msbuild", + "packages", + "zeroc.openssl.v143.1.1.1.3", + "build", + "native", + "bin", + "Win32", + "Release", + "openssl.exe", + ) else: return "openssl" class IceSSLConfigurationClient(Client): - def getExe(self, current): if isinstance(platform, Windows) and current.config.openssl: return "clientopenssl" @@ -92,14 +138,19 @@ def getExe(self, current): class IceSSLConfigurationServer(Server): - def getExe(self, current): if isinstance(platform, Windows) and current.config.openssl: return "serveropenssl" return Server.getExe(self, current) -TestSuite(__name__, [ - ConfigurationTestCase(client=IceSSLConfigurationClient(args=['"{testdir}"']), - server=IceSSLConfigurationServer(args=['"{testdir}"'])) -], multihost=False) +TestSuite( + __name__, + [ + ConfigurationTestCase( + client=IceSSLConfigurationClient(args=['"{testdir}"']), + server=IceSSLConfigurationServer(args=['"{testdir}"']), + ) + ], + multihost=False, +) diff --git a/scripts/tests/Slice/generation.py b/scripts/tests/Slice/generation.py index f8ab3432a4e..00952c43f62 100644 --- a/scripts/tests/Slice/generation.py +++ b/scripts/tests/Slice/generation.py @@ -2,8 +2,11 @@ # Copyright (c) ZeroC, Inc. All rights reserved. # -class SliceGenerationTestCase(ClientTestCase): +import os +from Util import ClientTestCase, SliceTranslator, TestSuite + +class SliceGenerationTestCase(ClientTestCase): def runClientSide(self, current): current.write("testing list-generated... ") @@ -12,10 +15,19 @@ def runClientSide(self, current): slice2java.run( current, - args=["--list-generated", "--output-dir", "classes", "File1.ice", "File2.ice"]) + args=[ + "--list-generated", + "--output-dir", + "classes", + "File1.ice", + "File2.ice", + ], + ) lines1 = slice2java.getOutput(current).strip().split("\n") - lines2 = open(os.path.join(current.testsuite.getPath(), "list-generated.out"), "r").readlines() + lines2 = open( + os.path.join(current.testsuite.getPath(), "list-generated.out"), "r" + ).readlines() if len(lines1) != len(lines2): raise RuntimeError("failed!")