From e7e0f89b1fadd94ed9cba2d7f58d71a7f50c62bf Mon Sep 17 00:00:00 2001 From: Frank Winklmeier <frank.winklmeier@cern.ch> Date: Fri, 30 Apr 2021 11:29:17 +0200 Subject: [PATCH] PhotonVertexSelection: fix unit test Fix the unit test. Replace the usage of the obscure `AthenaStopperAlg` with the builtin feature of `AppMgr`. Also make the test actually run on some events instead of just setting up the job. --- .../PhotonVertexSelection/CMakeLists.txt | 5 +++-- .../test/testPhotonVertexSelection.py | 20 ++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/PhysicsAnalysis/ElectronPhotonID/PhotonVertexSelection/CMakeLists.txt b/PhysicsAnalysis/ElectronPhotonID/PhotonVertexSelection/CMakeLists.txt index 9cd1a70bd5a8..e8b6972bd274 100644 --- a/PhysicsAnalysis/ElectronPhotonID/PhotonVertexSelection/CMakeLists.txt +++ b/PhysicsAnalysis/ElectronPhotonID/PhotonVertexSelection/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration # Declare the package name: atlas_subdir( PhotonVertexSelection ) @@ -30,5 +30,6 @@ atlas_add_dictionary( PhotonVertexSelectionDict # Test(s) in the package: if( NOT XAOD_ANALYSIS ) atlas_add_test( PhotonVertexSelection_test - SCRIPT test/testPhotonVertexSelection.py ) + SCRIPT test/testPhotonVertexSelection.py + POST_EXEC_SCRIPT nopost.sh ) endif() diff --git a/PhysicsAnalysis/ElectronPhotonID/PhotonVertexSelection/test/testPhotonVertexSelection.py b/PhysicsAnalysis/ElectronPhotonID/PhotonVertexSelection/test/testPhotonVertexSelection.py index 6417a171668e..208e1b849927 100755 --- a/PhysicsAnalysis/ElectronPhotonID/PhotonVertexSelection/test/testPhotonVertexSelection.py +++ b/PhysicsAnalysis/ElectronPhotonID/PhotonVertexSelection/test/testPhotonVertexSelection.py @@ -1,12 +1,15 @@ #!/usr/bin/env python -# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration __doc__ = """Script / jobOptions to test PhotonVertexSelectionTool using an AOD from mc15_13TeV:mc15_13TeV.341000.PowhegPythia8EvtGen_CT10_AZNLOCTEQ6L1_ggH125_gamgam.merge.AOD.e3806_s2608_r7772_r7676""" __author__ = "Bruno Lenzi" -defaultFile = "$ASG_TEST_FILE_MC" +import os +import sys + +defaultFile = os.environ.get("ASG_TEST_FILE_MC", None) defaultNevents = 5 def printMethod(x): @@ -39,7 +42,7 @@ def printOutput(container, tool, printMethod = printMethod): def setupAthenaJob(algoClass, inputfile = defaultFile, EvtMax = None): "Setup athena job" import AthenaPoolCnvSvc.ReadAthenaPool # EventSelector - from AthenaCommon.AppMgr import ServiceMgr as svcMgr + from AthenaCommon.AppMgr import ServiceMgr as svcMgr, theApp svcMgr.EventSelector.InputCollections = [inputfile] @@ -63,16 +66,15 @@ def setupAthenaJob(algoClass, inputfile = defaultFile, EvtMax = None): testAlg = AlgFactory(algoClass, PhotonVertexSelectionTool = PhotonVertexSelectionTool)() - # Maximum events - if EvtMax: - from Configurables import AthenaStopperAlg - AlgFactory( AthenaStopperAlg, StopCount=EvtMax )() + from AthenaCommon.Constants import INFO + theApp.setOutputLevel(INFO) + theApp.run( EvtMax ) # -------------------------------- # Athena algorithm and setup # -------------------------------- import os -if not 'ROOTCOREBIN' in os.environ: +if 'ROOTCOREBIN' not in os.environ: from AthenaPython import PyAthena from AthenaPython.PyAthena import StatusCode @@ -82,7 +84,7 @@ if not 'ROOTCOREBIN' in os.environ: super(TestPhotonVertexSelection,self).__init__(name = name, containerName = containerName, **kw) def initialize(self): - self.msg.info("initializing [%s]", self.name()) + self.msg.info("initializing [%s]", self.name) self.vertexTool = PyAthena.py_tool(self.PhotonVertexSelectionTool.getFullName(), iface='CP::IPhotonVertexSelectionTool') if not self.vertexTool: -- GitLab