From 0486b6ccecb87fb9f6def3194997da77c9fdbb0d Mon Sep 17 00:00:00 2001 From: Vanya Belyaev Date: Thu, 22 Feb 2024 10:47:52 +0100 Subject: [PATCH] fix warnings/tests interference --- ostap/CMakeLists.txt | 4 ++-- ostap/core/core.py | 16 +++++++++++++--- ostap/fitting/pdfbasic.py | 13 +++++++++---- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/ostap/CMakeLists.txt b/ostap/CMakeLists.txt index fc69b528..aa2e5013 100644 --- a/ostap/CMakeLists.txt +++ b/ostap/CMakeLists.txt @@ -249,7 +249,7 @@ foreach(filename ${files}) else () add_test (NAME ${tname} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/Testing/Temporary COMMAND python ${OSTAP_TEST_PYTHON_WARNINGS} ${filename} ) endif () - set_tests_properties(${tname} PROPERTIES TIMEOUT 5000 ) + set_tests_properties(${tname} PROPERTIES TIMEOUT 5000 ENVIRONMENT OSTAP_CMAKE_TEST=1 ) endforeach() file(GLOB allfiles "${CMAKE_INSTALL_PREFIX}/${OSTAP_PYTHON_SITE_LOCAL}/ostap/*/*.py") list(SORT allfiles) @@ -285,7 +285,7 @@ foreach(filename ${allfiles}) add_test (NAME ${testname} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/Testing/Temporary COMMAND python ${OSTAP_TEST_PYTHON_WARNINGS} ${filename} ) - set_tests_properties(${testname} PROPERTIES TIMEOUT 5000 ) + set_tests_properties(${testname} PROPERTIES TIMEOUT 5000 ENVIRONMENT OSTAP_CMAKE_TEST=1 ) endforeach() diff --git a/ostap/core/core.py b/ostap/core/core.py index 0cc6f331..654e7aaf 100644 --- a/ostap/core/core.py +++ b/ostap/core/core.py @@ -73,9 +73,10 @@ 'var_separators' , ## defalt separators for the string expressions ## 'cidict_fun' , ## key transformation for case-insensitive keys ingoring underscores + ## + 'in_test' , ## Are we in CMAKE-test regime? ) # ============================================================================= -import math, sys, os, re from sys import version_info as python_version from builtins import range from ostap.math.base import ( Ostap , std , cpp , @@ -90,7 +91,7 @@ from ostap.core.meta_info import root_info from ostap.core.ostap_types import integer_types, sequence_types, string_types from ostap.utils.basic import NoContext, loop_items, items_loop -import ROOT, cppyy +import ROOT, cppyy, math, sys, os, re # ============================================================================= ## ROOT.ROOT.EnableThreadSafety() # ============================================================================= @@ -1112,7 +1113,16 @@ def split_string ( line , if ROOT.ROOT.IsImplicitMTEnabled() : logger.debug ("Implicit MT is disabled") ROOT.ROOT.DisableImplicitMT () - + + + +# ============================================================================= +## Are we in CMAKE-test regime? +def in_test () : + """ Are we in CMAKE-test regime?""" + return os.environ.get( 'OSTAP_CMAKE_TEST', False) + + # ============================================================================= _decorated_classes_ = ( ROOT.TObject , diff --git a/ostap/fitting/pdfbasic.py b/ostap/fitting/pdfbasic.py index 1fb07af9..283a7bcc 100644 --- a/ostap/fitting/pdfbasic.py +++ b/ostap/fitting/pdfbasic.py @@ -37,7 +37,7 @@ import ostap.fitting.roocollections from builtins import range from ostap.core.core import ( Ostap , VE , hID , dsID , rootID, - valid_pointer , + valid_pointer , in_test , roo_silent , rootWarning ) from ostap.math.base import iszero , frexp10 from ostap.core.ostap_types import ( is_integer , string_types , @@ -53,7 +53,7 @@ from ostap.fitting.roocmdarg import check_arg , nontrivial_arg , flat_args , command from ostap.core.meta_info import root_info import ostap.histos.histos -import ROOT, math, random +import ROOT, math, random, warnings # ============================================================================= from ostap.logger.logger import getLogger if '__main__' == __name__ : logger = getLogger ( 'ostap.fitting.basic' ) @@ -587,8 +587,13 @@ def fit_to ( self , model , data , *options ) : from ostap.fitting.roocmdarg import command cmd = command ( *options ) - return Ostap.MoreRooFit.fitTo ( model , data , cmd ) - + if not in_test () : + return Ostap.MoreRooFit.fitTo ( model , data , cmd ) + + with warnings.catch_warnings(): + warnings.simplefilter("default") + return Ostap.MoreRooFit.fitTo ( model , data , cmd ) + # ================================================================================ ## helper method to draw set of components