diff --git a/Phys/CommonParticles/CMakeLists.txt b/Phys/CommonParticles/CMakeLists.txt index af3212cc038e14efe4ef75fd70b02c88e1ecb038..c8549f944bed3c8464f56357e5028514d2f0eb50 100644 --- a/Phys/CommonParticles/CMakeLists.txt +++ b/Phys/CommonParticles/CMakeLists.txt @@ -1,5 +1,5 @@ ############################################################################### -# (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration # +# (c) Copyright 2000-2020 CERN for the benefit of the LHCb Collaboration # # # # This software is distributed under the terms of the GNU General Public # # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # @@ -19,4 +19,5 @@ gaudi_depends_on_subdirs(Phys/DaVinciKernel gaudi_install_python_modules() -gaudi_add_test(QMTest QMTEST) +gaudi_add_test(pytest + COMMAND python -m pytest -v ${CMAKE_CURRENT_SOURCE_DIR}/tests) diff --git a/Phys/CommonParticles/python/CommonParticles/StdTightDplus.py b/Phys/CommonParticles/python/CommonParticles/StdTightDplus.py index 9b24b7a59b5b7537269b668aff2057a7eeef019d..d215fdbd23d42a255a7e4c6b638623a2fd544b44 100644 --- a/Phys/CommonParticles/python/CommonParticles/StdTightDplus.py +++ b/Phys/CommonParticles/python/CommonParticles/StdTightDplus.py @@ -60,7 +60,7 @@ locations.update(updateDoD(StdVeryTightDsplus2KKPi)) ########################################################################################## # D+ -> 3 pi is a clone of D+ -> K Pi Pi # -from StdLooseDplus import StdLooseDplus2KPiPi +from CommonParticles.StdLooseDplus import StdLooseDplus2KPiPi StdTightDplus2PiPiPi = StdLooseDplus2KPiPi.clone("StdTightDplus2PiPiPi") StdTightDplus2PiPiPi.Inputs = ["Phys/StdLoosePions/Particles"] StdTightDplus2PiPiPi.DecayDescriptor = "[D+ -> pi- pi+ pi+]cc" diff --git a/Phys/CommonParticles/tests/qmtest/commonparticles.qms/test_inputlocations_consistency.qmt b/Phys/CommonParticles/tests/qmtest/commonparticles.qms/test_inputlocations_consistency.qmt deleted file mode 100644 index 5f4d30f62f37296036ce4631f098ff569544860f..0000000000000000000000000000000000000000 --- a/Phys/CommonParticles/tests/qmtest/commonparticles.qms/test_inputlocations_consistency.qmt +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - $COMMONPARTICLESROOT/tests/test_inputlocations_consistency.py - - diff --git a/Phys/CommonParticles/tests/qmtest/commonparticles.qms/test_load_modules.qmt b/Phys/CommonParticles/tests/qmtest/commonparticles.qms/test_load_modules.qmt deleted file mode 100644 index 55ece493f96eeb70064b8070abc42e5608c63f04..0000000000000000000000000000000000000000 --- a/Phys/CommonParticles/tests/qmtest/commonparticles.qms/test_load_modules.qmt +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - $COMMONPARTICLESROOT/tests/test_load_modules.py - - diff --git a/Phys/CommonParticles/tests/test_inputlocations_consistency.py b/Phys/CommonParticles/tests/test_inputlocations_consistency.py index 548932d8f14dcf593ab8333ab21afac0ecfab3f3..0475ba25a9df4c8d10fbc3765247d579f566e82e 100755 --- a/Phys/CommonParticles/tests/test_inputlocations_consistency.py +++ b/Phys/CommonParticles/tests/test_inputlocations_consistency.py @@ -1,6 +1,6 @@ #!/usr/bin/env python ############################################################################### -# (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration # +# (c) Copyright 2000-2020 CERN for the benefit of the LHCb Collaboration # # # # This software is distributed under the terms of the GNU General Public # # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # @@ -9,38 +9,23 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -#$Id: test_load_modules.py,v 1.1 2010-04-22 14:44:53 jpalac Exp $ ''' Test loading various CommonParticles in the Stripping environment. Needs to be extended. ''' __author__ = 'Juan Palacios juan.palacios@nikhef.nl' -import sys -sys.path.append('../python') -from CommonParticles import StandardBasic, StandardIntermediate +def test(): + from CommonParticles import StandardBasic, StandardIntermediate -outputLocations = list(StandardBasic.locations.keys()) + list( - StandardIntermediate.locations.keys()) + outputLocations = list(StandardBasic.locations) + list( + StandardIntermediate.locations) -algs = list(StandardBasic.locations.values()) + list( - StandardIntermediate.locations.values()) + algs = list(StandardBasic.locations.values()) + list( + StandardIntermediate.locations.values()) -errors = {} - -message = "" - -for alg in algs: - if not hasattr(alg, 'Inputs'): continue - locs = alg.Inputs - for loc in locs: - if not loc in outputLocations: - message += "ERROR: Algorithm " + alg.name( - ) + ".Input " + loc + " not in output locations\n" - errors[alg.name()] = loc - -if len(errors) > 0: - sys.stderr.write('test_inputlocations_consistency: FAIL\n') - sys.stderr.write(message) -else: - sys.stdout.write('test_inputlocations_consistency: PASS\n') + for alg in algs: + if not hasattr(alg, 'Inputs'): continue + for inputLocation in alg.Inputs: + assert inputLocation in outputLocations, \ + 'Algorithm {}.Input {} not in output locations'.format(alg, inputLocation) diff --git a/Phys/CommonParticles/tests/test_load_modules.py b/Phys/CommonParticles/tests/test_load_modules.py index 5ae75ef8324a757dc8fb3290b74d99f55205322c..befdff5cb5dc6bf0fbf8e5c55d49890cd8cbf453 100755 --- a/Phys/CommonParticles/tests/test_load_modules.py +++ b/Phys/CommonParticles/tests/test_load_modules.py @@ -1,6 +1,6 @@ #!/usr/bin/env python ############################################################################### -# (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration # +# (c) Copyright 2000-2020 CERN for the benefit of the LHCb Collaboration # # # # This software is distributed under the terms of the GNU General Public # # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # @@ -9,17 +9,11 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ############################################################################### -#$Id: test_load_modules.py,v 1.1 2010-04-22 14:44:53 jpalac Exp $ ''' Test loading various CommonParticles in the Analysis environment. Needs to be extended. ''' -from past.builtins import cmp -from builtins import filter __author__ = 'Juan Palacios juan.palacios@nikhef.nl' -import sys -sys.path.append('../python') - def test_load_utils(): from CommonParticles import Utils @@ -43,35 +37,3 @@ def test_load_standard_intermediate(): def test_load_all(): import CommonParticles - - -if '__main__' == __name__: - - import sys - - test_names = [k for k in list(locals().keys()) if k.count('test_') > 0] - - __tests = [x for x in locals().items() if x[0] in test_names] - - message = '' - summary = '\n' - length = len(sorted(test_names, - cmp=lambda x, y: cmp(len(y), len(x)))[0]) + 2 - - for test in __tests: - try: - test[1]() - message = 'PASS' - except: - message = "FAIL" - summary += test[0].ljust(length) + ':' + message.rjust(10) + '\n' - - if summary.count('FAIL') > 0: - message = 'FAIL' - wr = sys.stderr.write - else: - message = 'PASS' - wr = sys.stdout.write - - summary += 'Global'.ljust(length) + ':' + message.rjust(10) + '\n\n' - wr(summary) diff --git a/Phys/JetAccessories/python/JetAccessories/ParticleFlow_Config.py b/Phys/JetAccessories/python/JetAccessories/ParticleFlow_Config.py index d29e78975e29e3107a4f8b6071aac6d68a5ee16c..0b1b725f724986b1e83b5f722d8b021b5389586f 100644 --- a/Phys/JetAccessories/python/JetAccessories/ParticleFlow_Config.py +++ b/Phys/JetAccessories/python/JetAccessories/ParticleFlow_Config.py @@ -227,7 +227,7 @@ class ParticleFlowConf(object): alg.TrackSelectorType = "DelegatingTrackSelector" alg.addTool(DelegatingTrackSelector, name="TrackSelector") tracktypes = TrackCuts.keys() - alg.TrackSelector.TrackTypes = self.TrackSelector.keys() + alg.TrackSelector.TrackTypes = list(self.TrackSelector) for type in tracktypes: self.setupTypeTrackSelector(type, alg.TrackSelector, TrackCuts) diff --git a/Phys/LoKiPhys/CMakeLists.txt b/Phys/LoKiPhys/CMakeLists.txt index 5191b71b038907c96979ae75524b8908ef19b300..7e8207aaa55ed1599d8da851aca690cef90a15ff 100644 --- a/Phys/LoKiPhys/CMakeLists.txt +++ b/Phys/LoKiPhys/CMakeLists.txt @@ -49,4 +49,5 @@ endif() gaudi_install_python_modules() -gaudi_add_test(QMTest QMTEST) +gaudi_add_test(pytest + COMMAND python -m pytest -v ${CMAKE_CURRENT_SOURCE_DIR}/python/LoKiPhys/tests.py) diff --git a/Phys/LoKiPhys/python/LoKiPhys/Phys.py b/Phys/LoKiPhys/python/LoKiPhys/Phys.py index 59bfee6b84b5f77885789f9ccda6b7979cb44caf..2853d7ad23f68b5536c5bd2cd0422a5fb6325382 100755 --- a/Phys/LoKiPhys/python/LoKiPhys/Phys.py +++ b/Phys/LoKiPhys/python/LoKiPhys/Phys.py @@ -1,6 +1,6 @@ #!/usr/bin/env python ############################################################################### -# (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration # +# (c) Copyright 2000-2020 CERN for the benefit of the LHCb Collaboration # # # # This software is distributed under the terms of the GNU General Public # # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # @@ -400,7 +400,8 @@ for t in (LHCb.Particle, LHCb.Vertex, LHCb.VertexBase, LHCb.RecVertex, LHCb.Track, LHCb.CaloDigit, LHCb.CaloCluster, LHCb.CaloHypo): _SR = cpp.SmartRef(t) - _SR.__nonzero__ = lambda s: bool(s.target()) + _SR.__bool__ = lambda s: bool(s.target()) + _SR.__nonzero__ = _SR.__bool__ # Python 2 compatibility _SR.__repr__ = _LCF._repr_SR_ _SR.__str__ = _LCF._str_SR_ _SR.__getattr__ = _LCF._getattr_SR_ diff --git a/Phys/LoKiPhys/python/LoKiPhys/tests.py b/Phys/LoKiPhys/python/LoKiPhys/tests.py index 7f14ab122385a0899b6f692bf917c60b45a4e5f3..08b55afcf57fdce0c54feaab998328e6c26c7396 100755 --- a/Phys/LoKiPhys/python/LoKiPhys/tests.py +++ b/Phys/LoKiPhys/python/LoKiPhys/tests.py @@ -1,6 +1,6 @@ #!/usr/bin/env python ############################################################################### -# (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration # +# (c) Copyright 2000-2020 CERN for the benefit of the LHCb Collaboration # # # # This software is distributed under the terms of the GNU General Public # # Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # @@ -41,15 +41,14 @@ from LoKiCore.math import * # ============================================================================= ## The most trivial test function -def test0(): +def test_basic(): """ The most trivial test function """ from LoKiPhys.decorators import _decorated print('LoKiPhysTest: decorated objects %s' % len(_decorated)) - pass ## the test function for various "functional streamers" -def test1(): +def test_function_streamers(): """ The test function for various 'functional streamers' """ @@ -93,7 +92,7 @@ def test1(): ## tets smart references -def test2(): +def test_smart_references(): ## ## simple check @@ -117,38 +116,12 @@ def test2(): except AssertionError as e: print(e) - print(80 * '*') - ## test monitoring stuff -def test3(): +def test_monitoring(): p = LHCb.Particle() a = monitor(PT) print(a(p)) - - print(80 * '*') - - -# ============================================================================= -## Perform all known tests -def testAll(): - """ - Perform all known tests - """ - test0() - test1() - test2() ## smart referemnces - test3() - - -# ============================================================================= -if '__main__' == __name__: - testAll() - # ============================================================================= - - # ============================================================================= - # The END - # ============================================================================= diff --git a/Phys/LoKiPhys/tests/qmtest/lokiphys0.qmt b/Phys/LoKiPhys/tests/qmtest/lokiphys0.qmt deleted file mode 100644 index 9693e1545a9dcb67e90006c3e7f51acf5d95ce5e..0000000000000000000000000000000000000000 --- a/Phys/LoKiPhys/tests/qmtest/lokiphys0.qmt +++ /dev/null @@ -1,15 +0,0 @@ - - - - - ../../python/LoKiPhys/tests.py - diff --git a/Phys/SelPy/python/SelPy/utils.py b/Phys/SelPy/python/SelPy/utils.py index 586eec36bbc8fc598a8c508ce3d361f5434c03ff..9e3887ace2a2bd008112176cf7a5d8b456e9931e 100644 --- a/Phys/SelPy/python/SelPy/utils.py +++ b/Phys/SelPy/python/SelPy/utils.py @@ -292,10 +292,10 @@ def update_dict_overlap(dict0, dict1): Replace entries from dict0 with those from dict1 that have keys present in dict0. """ - overlap_keys = filter(dict1.has_key, dict0.keys()) result = dict(dict0) - for key in overlap_keys: - result[key] = dict1[key] + for key in dict0: + if key in dict1: + result[key] = dict1[key] return result