Belle II Software development
test_embedding_example.py
1#!/usr/bin/env python3
2
3
10
11import os
12import sys
13import subprocess
14import unittest
15from basf2 import find_file
16from b2test_utils import clean_working_directory
17
18
19class TestEmbedding(unittest.TestCase):
20 """Test to run the embedding example."""
21
22 @unittest.skipIf(not os.getenv('BELLE2_EXAMPLES_DATA_DIR'),
23 "$BELLE2_EXAMPLES_DATA_DIR not found.")
24 def testEmbedding(self):
25 """
26 Test the embedding example.
27 """
28 embedding_example = find_file('analysis/examples/embedding/embedding.py')
29
30 result = subprocess.run(['basf2', embedding_example], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
31 if result.returncode != 0:
32 # failure running tutorial so let's print the output
33 # on stderr so it's not split from output of unittest
34 # done like this since we don't want to decode/encode utf8
35 sys.stdout.buffer.write(result.stdout)
36
37 self.assertEqual(result.returncode, 0)
38
39
40if __name__ == '__main__':
41 with clean_working_directory():
42 unittest.main()