Skip to content

Commit

Permalink
reintroducing unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangWaltenberger committed Jan 22, 2025
1 parent 38a35dc commit 92b7b12
Show file tree
Hide file tree
Showing 1,970 changed files with 1,455,486 additions and 0 deletions.
25 changes: 25 additions & 0 deletions unittests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
all: test

test:
./runCompleteTestSuite.py -v -n

test_norecipes:
./runCompleteTestSuite.py -v

reduced:
./runCompleteTestSuite.py -r -v

obs:
py.test -v

run_coverage:
coverage run runCompleteTestSuite.py

coverage:
coverage report --omit="/usr/lib/*,testFiles/scanExample/*,*/.local/*,unitTestOutput/*,test*py,test*py" -i
rm -rf htmlcov/
coverage html --omit="/usr/lib/*,testFiles/scanExample/*,*/.local/*,unitTestOutput/*,test*py,test*py" -i
cp htmlcov/* ../../smodels.github.io/coverage/

notebook:
ipython notebook
1 change: 1 addition & 0 deletions unittests/T1tttt_comb_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
smodelsOutputDefault = {'OutputStatus': {'sigmacut': 0.03, 'minmassgap': 5.0, 'maxcond': 0.2, 'ncpus': -6, 'file status': 1, 'decomposition status': 1, 'warnings': 'Input file ok', 'input file': 'testFiles/slha/T1tttt.slha', 'database version': 'unittest211', 'smodels version': '2.2.0'}, 'ExptRes': [{'maxcond': 0.0, 'theory prediction (fb)': 4.669625, 'upper limit (fb)': 0.081354, 'expected upper limit (fb)': 0.081354, 'TxNames': ['T1tttt'], 'Mass (GeV)': [[675.0, 200.0], [675.0, 200.0]], 'AnalysisID': 'CMS-SUS-16-050-agg', 'DataSetID': 'ar55', 'AnalysisSqrts (TeV)': 13.0, 'lumi (fb-1)': 35.9, 'dataType': 'efficiencyMap', 'r': 57.39884, 'r_expected': 57.39884, 'Width (GeV)': [['prompt', 'stable'], ['prompt', 'stable']], 'likelihood': 3.938979304647101e-74, 'l_max': 0.2513719, 'l_SM': 0.2513719}, {'maxcond': 0.0, 'theory prediction (fb)': 4309.035, 'upper limit (fb)': 141.1736, 'expected upper limit (fb)': None, 'TxNames': ['T1tttt'], 'Mass (GeV)': [[675.0, 200.0], [675.0, 200.0]], 'AnalysisID': 'CMS-PAS-SUS-15-002', 'DataSetID': None, 'AnalysisSqrts (TeV)': 13.0, 'lumi (fb-1)': 2.2, 'dataType': 'upperLimit', 'r': 30.52296, 'r_expected': None, 'Width (GeV)': [['prompt', 'stable'], ['prompt', 'stable']]}, {'maxcond': 0.0, 'theory prediction (fb)': 572.1689, 'upper limit (fb)': 62.581, 'expected upper limit (fb)': 92.717, 'TxNames': ['T1tttt'], 'Mass (GeV)': [[675.0, 200.0], [675.0, 200.0]], 'AnalysisID': 'CMS-PAS-SUS-12-026', 'DataSetID': None, 'AnalysisSqrts (TeV)': 8.0, 'lumi (fb-1)': 9.2, 'dataType': 'upperLimit', 'r': 9.142854, 'r_expected': 6.171133, 'Width (GeV)': [['prompt', 'stable'], ['prompt', 'stable']]}, {'maxcond': 0.0, 'theory prediction (fb)': 2.369623, 'upper limit (fb)': 0.4, 'expected upper limit (fb)': 0.433, 'TxNames': ['T1tttt'], 'Mass (GeV)': [[675.0, 200.0], [675.0, 200.0]], 'AnalysisID': 'ATLAS-CONF-2013-037', 'DataSetID': 'SRbC3', 'AnalysisSqrts (TeV)': 8.0, 'lumi (fb-1)': 20.7, 'dataType': 'efficiencyMap', 'r': 5.924058, 'r_expected': 5.472571, 'Width (GeV)': [['prompt', 'stable'], ['prompt', 'stable']], 'likelihood': 8.800609000000001e-17, 'l_max': 0.02067189, 'l_SM': 0.02067189}, {'maxcond': 0.0, 'theory prediction (fb)': 2.962771, 'upper limit (fb)': 0.5171654, 'expected upper limit (fb)': 0.3654986, 'TxNames': ['T1tttt'], 'Mass (GeV)': [[675.0, 200.0], [675.0, 200.0]], 'AnalysisID': 'CMS-SUS-13-012', 'DataSetID': '8NJetinf_1000HT1250_200MHTinf', 'AnalysisSqrts (TeV)': 8.0, 'lumi (fb-1)': 19.5, 'dataType': 'efficiencyMap', 'r': 5.728866, 'r_expected': 8.106107, 'Width (GeV)': [['prompt', 'stable'], ['prompt', 'stable']], 'likelihood': 1.949589e-18, 'l_max': 0.0265176, 'l_SM': 0.02060875}], 'CombinedRes': [{'AnalysisID': 'CMS-SUS-13-012,CMS-SUS-16-050-agg', 'r': 110.3102, 'r_expected': 116.688, 'likelihood': 7.679392482807625e-92, 'l_max': 0.008212736, 'l_SM': 0.005180459}], 'Total xsec for missing topologies (fb)': 0.0, 'missing topologies': [], 'Total xsec for missing topologies with displaced decays (fb)': 0.0, 'missing topologies with displaced decays': [], 'Total xsec for missing topologies with prompt decays (fb)': 0.0, 'missing topologies with prompt decays': [], 'Total xsec for topologies outside the grid (fb)': 0.0, 'topologies outside the grid': []}
51 changes: 51 additions & 0 deletions unittests/T6bbHH_pyhf_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
smodelsOutputDefault = {
'OutputStatus' : {
'sigmacut' : 0.03,
'minmassgap' : 5.0,
'maxcond' : 0.2,
'ncpus' : -1,
'model' : 'share.models.mssm',
'checkinput' : True,
'doinvisible' : True,
'docompress' : True,
'computestatistics' : False,
'testcoverage' : True,
'combinesrs' : True,
'file status' : 1,
'decomposition status' : 1,
'warnings' : 'Input file ok',
'input file' : './testFiles/slha/T6bbHH_pyhf.slha',
'database version' : 'unittest211',
'smodels version' : '2.2.0'
},
'ExptRes' : [
{
'maxcond' : 0.0,
'theory prediction (fb)' : 0.10091,
'upper limit (fb)' : 0.08247307,
'expected upper limit (fb)' : 0.1200876,
'TxNames' : ['T6bbHH'],
'Mass (GeV)' : [[1400.0, 1000.0, 60.0], [1400.0, 1000.0, 60.0]],
'AnalysisID' : 'ATLAS-SUSY-2018-31',
'DataSetID' : '(combined)',
'AnalysisSqrts (TeV)' : 13.0,
'lumi (fb-1)' : 139.0,
'dataType' : 'combined',
'r' : 1.223551,
'r_expected' : 0.8403036,
'Width (GeV)' : [[1.0, 1.0, 'stable'], [1.0, 1.0, 'stable']],
'nll' : 51.35556035013835,
'nll_min' : 48.38229103232457,
'nll_SM' : 48.38229103232457
}
],
'Total xsec for missing topologies (fb)' : 0.0,
'missing topologies' : [],
'Total xsec for missing topologies with displaced decays (fb)' : 0.0,
'missing topologies with displaced decays' : [],
'Total xsec for missing topologies with prompt decays (fb)' : 0.0,
'missing topologies with prompt decays' : [],
'Total xsec for topologies outside the grid (fb)' : 0.0,
'topologies outside the grid' : []
}

1 change: 1 addition & 0 deletions unittests/bad_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
smodelsOutputDefault = {'OutputStatus': {'minmassgap': 5.0, 'input file': '/home/walten/git/smodels/inputFiles/slha/I_dont_exist.slha', 'decomposition status': -2, 'warnings': 'Unknown input type: None', 'ncpus': -1, 'maxcond': 0.2, 'smodels version': '1.1.1', 'database version': 'unittest', 'sigmacut': 0.03, 'file status': -5}}
26 changes: 26 additions & 0 deletions unittests/buildPickles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python3

import glob, shutil, os

def rmOldPickles():
files = glob.glob ( "**/*.pcl", recursive=True )
files += glob.glob ( "**/.*.pcl", recursive=True )
for f in files:
if not "notebookTests" in f:
print ( f"[buildPickles] rm {f}" )
os.unlink ( f )

def buildDatabases():
from smodels.experiment.databaseObj import Database
versionfiles = glob.glob ( "*/version" )
for versionfile in versionfiles:
dbpath = versionfile.replace("/version","")
print ( dbpath )
try:
db = Database ( dbpath )
except Exception as e:
print ( f"error: {e}" )

if __name__ == "__main__":
rmOldPickles()
buildDatabases()
185 changes: 185 additions & 0 deletions unittests/checkInterpolation.ipynb

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions unittests/convertNotebook2Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python3

"""
.. module:: convertNotebook2Test
:synopsis: Reads the cells from a notebook and store the output from each cell execution.
.. moduleauthor:: Andre Lessa <lessa.a.p@gmail.com>
"""
import sys
import os
import json
import pickle

def getNotebookData(notebookFile,savePickle=True):

if not os.path.isfile(notebookFile):
print('File %s not found' %notebookFile)
return None

with open(notebookFile,'r') as f:
data = json.load(f)

cells = data['cells']
outputDict = {}
for cell in cells:
cell_type = cell['cell_type']
if cell_type != 'code':
continue
cell_count = cell['execution_count']
if cell_count is None:
continue

outputList = [[outStr.replace('\n','') for outStr in c['text']]
for c in cell['outputs'] if c['output_type'] == 'stream']
outputDict[cell_count] = outputList

if savePickle:
outputFile = notebookFile
outputFile = outputFile.replace('.ipynb','_output.pcl')
pickle.dump(outputDict,open(outputFile,'wb'))
return outputDict


if __name__ == "__main__":
import argparse
ap = argparse.ArgumentParser('Convert the notebook output to a pickle file to be used as a unit test')
ap.add_argument('-f','--filename', help='path to the notebook file')
args = ap.parse_args()


getNotebookData(args.filename)
Loading

0 comments on commit 92b7b12

Please sign in to comment.