Belle II Software  release-05-02-19
tutorials.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 import os
5 import sys
6 import subprocess
7 import unittest
8 import glob
9 from basf2 import find_file
10 from b2test_utils import clean_working_directory
11 
12 
13 class TutorialsTest(unittest.TestCase):
14  """Test to run all tutorials. Will fail if no tutorial directory is found."""
15 
16 
17  broken_tutorials = ['B2A702-ContinuumSuppression_MVATrain.py', # BII-4246
18  'B2A703-ContinuumSuppression_MVAExpert.py', # BII-4246
19  'B2A503-ReadDecayHash.py', # BII-4254
20  ]
21 
22  @unittest.skipIf(not os.getenv('BELLE2_EXAMPLES_DATA_DIR'),
23  "$BELLE2_EXAMPLES_DATA_DIR not found.")
24  @unittest.skipIf(not os.getenv('BELLE2_VALIDATION_DATA_DIR'),
25  "$BELLE2_VALIDATION_DATA_DIR not found.")
26  def test_tutorials(self):
27  """
28  Test supported tutorials.
29  """
30  all_tutorials = sorted(glob.glob(find_file('analysis/examples/tutorials/') + "*.py"))
31  for tutorial in all_tutorials:
32  filename = os.path.basename(tutorial)
33  if filename not in self.broken_tutorials:
34  with self.subTest(msg=filename):
35  result = subprocess.run(['basf2', '-n1', tutorial], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
36  if result.returncode != 0:
37  # failure running tutorial so let's print the output
38  # on stderr so it's not split from output of unittest
39  # done like this since we don't want to decode/encode utf8
40  sys.stdout.buffer.write(result.stdout)
41  self.assertEqual(result.returncode, 0)
42 
43 
44 if __name__ == '__main__':
45  with clean_working_directory():
46  unittest.main()
tutorials.TutorialsTest
Definition: tutorials.py:13
tutorials.TutorialsTest.broken_tutorials
list broken_tutorials
list of the broken tutorials (to be removed when they are individually fixed)
Definition: tutorials.py:17
tutorials.TutorialsTest.test_tutorials
def test_tutorials(self)
Definition: tutorials.py:26