From c5e774cebcbbe8fa4dd85f2d11f181beb504baf8 Mon Sep 17 00:00:00 2001 From: scott snyder <snyder@bnl.gov> Date: Mon, 16 Dec 2019 16:57:19 +0100 Subject: [PATCH 1/2] StoreGateTests: Get tests with working with python 3. - print function - commands module --- Control/StoreGateTests/python/Lib.py | 3 ++ ...t_sgProducerConsumerDataPool_jobOptions.py | 34 +++++++++++-------- .../atn_test_sgProducerConsumer_jobOptions.py | 28 ++++++++------- 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/Control/StoreGateTests/python/Lib.py b/Control/StoreGateTests/python/Lib.py index df21e2598b8a..c3e5b830ecf5 100644 --- a/Control/StoreGateTests/python/Lib.py +++ b/Control/StoreGateTests/python/Lib.py @@ -175,6 +175,9 @@ class PyClidsTestWriter(PyAthena.Alg): if not allGood: return StatusCode.Failure self.sg.dump() + import sys + sys.stdout.flush() + sys.stderr.flush() return self.testReadBack() diff --git a/Control/StoreGateTests/share/tests/atn_test_sgProducerConsumerDataPool_jobOptions.py b/Control/StoreGateTests/share/tests/atn_test_sgProducerConsumerDataPool_jobOptions.py index 2eac1a7bf6cd..7c2428080a15 100644 --- a/Control/StoreGateTests/share/tests/atn_test_sgProducerConsumerDataPool_jobOptions.py +++ b/Control/StoreGateTests/share/tests/atn_test_sgProducerConsumerDataPool_jobOptions.py @@ -1,11 +1,15 @@ #!/usr/bin/env python -import user +from __future__ import print_function + import os import sys -import commands from AthenaCommon import ChapPy +from future import standard_library +standard_library.install_aliases() +import subprocess + ###----------------------------------------------------- ## For compatibility with ATN tests from TestTools.iobench import workDir @@ -15,10 +19,10 @@ from TestTools.iobench import workDir from TestTools.iobench import ScOutput from TestTools.iobench import BenchSequence -print "#"*80 -print "## StoreGate test... [producer/consumer-DataPool-bench]" -print "#"*80 -print "::: No DataPool ", +print ("#"*80) +print ("## StoreGate test... [producer/consumer-DataPool-bench]") +print ("#"*80) +print ("::: No DataPool ", end='') athena = ChapPy.Athena( jobOptions = [ ChapPy.JobOptionsCmd( "SGDATAPOOL=False" ), @@ -29,10 +33,10 @@ athena = ChapPy.Athena( athena.EvtMax = 100 sc = athena.run() if sc != 0: - print "ERROR" + print ("ERROR") sys.exit(sc) -print "::: With DataPool ", +print ("::: With DataPool ", end='') athena = ChapPy.Athena( jobOptions = [ ChapPy.JobOptionsCmd( "SGDATAPOOL=True" ), @@ -43,19 +47,19 @@ athena = ChapPy.Athena( athena.EvtMax = 100 sc = athena.run() if sc != 0: - print "ERROR" + print ("ERROR") sys.exit(sc) -sc,out = commands.getstatusoutput( +sc,out = subprocess.getstatusoutput( "perfmon.py %s %s -o %s -l dp,nodp -s \"m.name!=''\"" % ( "withdatapool.pmon.gz", "nodatapool.pmon.gz", "datapool.root" ) ) -print "All tests SUCCESSFULLY completed" +print ("All tests SUCCESSFULLY completed") -print "" -print "#"*80 -print "## Bye." -print "#"*80 +print ("") +print ("#"*80) +print ("## Bye.") +print ("#"*80) diff --git a/Control/StoreGateTests/share/tests/atn_test_sgProducerConsumer_jobOptions.py b/Control/StoreGateTests/share/tests/atn_test_sgProducerConsumer_jobOptions.py index 4ecfc886b0ae..816c8b03b0db 100755 --- a/Control/StoreGateTests/share/tests/atn_test_sgProducerConsumer_jobOptions.py +++ b/Control/StoreGateTests/share/tests/atn_test_sgProducerConsumer_jobOptions.py @@ -1,11 +1,15 @@ #!/usr/bin/env python -import user +from __future__ import print_function + import os import sys -import commands from AthenaCommon import ChapPy +from future import standard_library +standard_library.install_aliases() +import subprocess + ###----------------------------------------------------- ## For compatibility with ATN tests from TestTools.iobench import workDir @@ -15,22 +19,22 @@ from TestTools.iobench import workDir from TestTools.iobench import ScOutput from TestTools.iobench import BenchSequence -print "#"*80 -print "## StoreGate test... [producer/consumer-bench]" -print "#"*80 +print ("#"*80) +print ("## StoreGate test... [producer/consumer-bench]") +print ("#"*80) athena = ChapPy.Athena( jobOptions = [ ChapPy.JobOptions( "StoreGateTests/test_sgProducerConsumer_jobOptions.py" ) ] ) athena.EvtMax = 100 sc = athena.run() -if sc != 0: print "ERROR" +if sc != 0: print ("ERROR") else: - commands.getstatusoutput( + subprocess.getstatusoutput( "perfmon.py %s -o %s" % ( "perfmon.pmon.gz", "out.sg.perfmon.root" ) ) - print "All tests SUCCESSFULLY completed" + print ("All tests SUCCESSFULLY completed") -print "" -print "#"*80 -print "## Bye." -print "#"*80 +print ("") +print ("#"*80) +print ("## Bye.") +print ("#"*80) -- GitLab From 8e51d9fe6e79ae30b74327b44b6ec3a24c659087 Mon Sep 17 00:00:00 2001 From: scott snyder <snyder@bnl.gov> Date: Mon, 16 Dec 2019 16:58:05 +0100 Subject: [PATCH 2/2] AthExJobOptions: python 3 fixes Get tests working with python 3 --- .../AthExJobOptions/python/CustomToolUsingTool.py | 8 +++----- .../AthExJobOptions/python/CustomToolUsingTool2.py | 6 +++--- .../AthExJobOptions/python/CustomTopAlgorithm.py | 8 +++----- .../share/AthExJobOptions_BasicJobOptions.py | 2 +- .../share/AthExJobOptions_CustomToolJobOptions.py | 4 ++-- .../share/AthExJobOptions_CustomTopAlgorithmJobOptions.py | 2 +- 6 files changed, 13 insertions(+), 17 deletions(-) diff --git a/Control/AthenaExamples/AthExJobOptions/python/CustomToolUsingTool.py b/Control/AthenaExamples/AthExJobOptions/python/CustomToolUsingTool.py index 4efd723bf46f..cd43112a3d92 100755 --- a/Control/AthenaExamples/AthExJobOptions/python/CustomToolUsingTool.py +++ b/Control/AthenaExamples/AthExJobOptions/python/CustomToolUsingTool.py @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration # File: AthExJobOptions/CustomToolUsingTool.py # Author: Wim Lavrijsen (WLavrijsen@lbl.gov) @@ -9,9 +9,7 @@ __author__ = 'Wim Lavrijsen (WLavrijsen@lbl.gov)' __all__ = [ 'CustomToolUsingTool' ] -# Get our base class (was generated by genConf; note that the package name is -# not necessary if both classes reside in the same directory) -from AthExJobOptionsConf import ToolUsingTool +from .AthExJobOptionsConf import ToolUsingTool # Customized class, enable through derivation @@ -30,5 +28,5 @@ class CustomToolUsingTool( ToolUsingTool ): handle.Factor = 42. # best, is considered default if not hasattr( handle, 'TheToolTool' ): - from AthExJobOptionsConf import ConcreteTool + from .AthExJobOptionsConf import ConcreteTool handle.TheToolTool = ConcreteTool( 'ToolTool' ) diff --git a/Control/AthenaExamples/AthExJobOptions/python/CustomToolUsingTool2.py b/Control/AthenaExamples/AthExJobOptions/python/CustomToolUsingTool2.py index ec6130ccba3d..3b4e3579fb2c 100755 --- a/Control/AthenaExamples/AthExJobOptions/python/CustomToolUsingTool2.py +++ b/Control/AthenaExamples/AthExJobOptions/python/CustomToolUsingTool2.py @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration # File: AthExJobOptions/CustomToolUsingTool2.py # Author: Wim Lavrijsen (WLavrijsen@lbl.gov) @@ -13,14 +13,14 @@ __all__ = [ 'CustomToolUsingTool2' ] class CustomToolUsingTool2( object ): def __new__( cls, name = 'CustomToolUsingTool2' ): # first, look for already fully customized instance - from AthExJobOptionsConf import ToolUsingTool + from .AthExJobOptionsConf import ToolUsingTool try: return ToolUsingTool.configurables[ name ] except KeyError: pass # else, request a new instance, and add customization - from AthExJobOptionsConf import ConcreteTool + from .AthExJobOptionsConf import ConcreteTool tool = ToolUsingTool( name ) tool.Factor = 42. diff --git a/Control/AthenaExamples/AthExJobOptions/python/CustomTopAlgorithm.py b/Control/AthenaExamples/AthExJobOptions/python/CustomTopAlgorithm.py index 6b10b29f36a0..959f5214ccd0 100755 --- a/Control/AthenaExamples/AthExJobOptions/python/CustomTopAlgorithm.py +++ b/Control/AthenaExamples/AthExJobOptions/python/CustomTopAlgorithm.py @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration ## @file CustomTopAlgorithm.py @@ -11,9 +11,7 @@ __author__ = 'Wim Lavrijsen (WLavrijsen@lbl.gov)' __all__ = [ 'CustomTopAlgorithm' ] -# Get our base class (was generated by genConf; note that the package name is -# not necessary if both classes reside in the same directory) -from AthExJobOptionsConf import TopAlgorithm +from .AthExJobOptionsConf import TopAlgorithm ## @class CustomTopAlgorithm # @brief Customizer class for TopAlgorithm, enabled through derivation @@ -36,5 +34,5 @@ class CustomTopAlgorithm( TopAlgorithm ): # make sure one tool is always selected if not hasattr( handle, 'TheTool' ): - from AthExJobOptionsConf import ConcreteTool + from .AthExJobOptionsConf import ConcreteTool handle.TheTool = ConcreteTool() diff --git a/Control/AthenaExamples/AthExJobOptions/share/AthExJobOptions_BasicJobOptions.py b/Control/AthenaExamples/AthExJobOptions/share/AthExJobOptions_BasicJobOptions.py index 3d681b48812a..b085fb4978b9 100755 --- a/Control/AthenaExamples/AthExJobOptions/share/AthExJobOptions_BasicJobOptions.py +++ b/Control/AthenaExamples/AthExJobOptions/share/AthExJobOptions_BasicJobOptions.py @@ -116,6 +116,6 @@ for alg in job: setdebug(alg) # Print the final job for reference purposes -print job +printfunc (job) # End of AthExJobOptions_BasicJobOptions.py diff --git a/Control/AthenaExamples/AthExJobOptions/share/AthExJobOptions_CustomToolJobOptions.py b/Control/AthenaExamples/AthExJobOptions/share/AthExJobOptions_CustomToolJobOptions.py index bc55ed09d8c4..a002e6438051 100755 --- a/Control/AthenaExamples/AthExJobOptions/share/AthExJobOptions_CustomToolJobOptions.py +++ b/Control/AthenaExamples/AthExJobOptions/share/AthExJobOptions_CustomToolJobOptions.py @@ -22,7 +22,7 @@ job.MyTopAlg.TheTool.Factor = 14. # Another custom configured tool to use from AthExJobOptions.CustomToolUsingTool2 import CustomToolUsingTool2 job += TopAlgorithm( 'YourTopAlg' ) -print job.YourTopAlg.properties() +printfunc (job.YourTopAlg.properties()) job.YourTopAlg.OutputKey = 'YourKey' job.YourTopAlg.TheTool = CustomToolUsingTool2( 'CustomTool2' ) job.YourTopAlg.TheTool.Factor = 18. @@ -36,6 +36,6 @@ job.YourTopAlg.TheTool.Factor = 18. theApp.EvtMax = 2 # Print the final job for reference purposes -print job +printfunc (job) # End of AthExJobOptions_CustomTopAlgorithmJobOptions.py diff --git a/Control/AthenaExamples/AthExJobOptions/share/AthExJobOptions_CustomTopAlgorithmJobOptions.py b/Control/AthenaExamples/AthExJobOptions/share/AthExJobOptions_CustomTopAlgorithmJobOptions.py index c8bc6a8e96e3..73d7d388760e 100755 --- a/Control/AthenaExamples/AthExJobOptions/share/AthExJobOptions_CustomTopAlgorithmJobOptions.py +++ b/Control/AthenaExamples/AthExJobOptions/share/AthExJobOptions_CustomTopAlgorithmJobOptions.py @@ -26,6 +26,6 @@ assert( job.MyCustomAlg.RndmFactor == 33. ) theApp.EvtMax = 2 # Print the final job for reference purposes -print job +printfunc (job) # End of AthExJobOptions_CustomTopAlgorithmJobOptions.py -- GitLab