import unittest
import logging
import os
import sys
import argparse
import toolbox_scs as tb
import toolbox_scs.misc as tbm
from toolbox_scs.util.exceptions import ToolBoxPathError
# -----------------------------------------------------------------------------
# global test settings
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
[docs]suites = {"bunch-pattern-decoding": (
"test_isppl",
"test_issase1",
"test_issase3",
"test_extractBunchPattern",
"test_pulsePatternInfo",
)
}
[docs]class TestDataAccess(unittest.TestCase):
@classmethod
[docs] def setUpClass(cls):
run = tb.load_run(proposalNB, runNB)
mnemonic = tb.mnemonics["bunchPatternTable"]
cls._bpt = run.get_array(*mnemonic.values())
@classmethod
[docs] def tearDownClass(cls):
pass
[docs] def tearDown(self):
pass
[docs] def test_isppl(self):
cls = self.__class__
bpt_decoded = tbm.is_ppl(cls._bpt)
self.assertEqual(bpt_decoded.values[0][0],1)
[docs] def test_issase1(self):
cls = self.__class__
bpt_decoded = tbm.is_sase_3(cls._bpt)
self.assertEqual(bpt_decoded.values[0][0],0)
[docs] def test_issase3(self):
cls = self.__class__
bpt_decoded = tbm.is_sase_3(cls._bpt)
self.assertEqual(bpt_decoded.values[0][0],0)
[docs] def test_pulsePatternInfo(self):
pass
[docs]def list_suites():
print("\nPossible test suites:\n" + "-" * 79)
for key in suites:
print(key)
print("-" * 79 + "\n")
[docs]def suite(*tests):
suite = unittest.TestSuite()
for test in tests:
suite.addTest(TestDataAccess(test))
return suite
[docs]def start_tests(*cliargs):
logging.basicConfig(level=logging.DEBUG)
log_root = logging.getLogger(__name__)
try:
for test_suite in cliargs:
if test_suite in suites:
runner = unittest.TextTestRunner(verbosity=2)
runner.run(suite(*suites[test_suite]))
else:
log_root.warning(
"Unknown suite: '{}'".format(test_suite))
pass
except Exception as err:
log_root.error("Unecpected error: {}".format(err),
exc_info=True)
pass
if __name__ == '__main__':
[docs] parser = argparse.ArgumentParser()
parser.add_argument('--list-suites',
action='store_true',
help='list possible test suites')
parser.add_argument('--run-suites', metavar='S',
nargs='+', action='store',
help='a list of valid test suites')
args = parser.parse_args()
if args.list_suites:
list_suites()
if args.run_suites:
start_tests(*args.run_suites)