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