Jpp  debug
the software that should make you happy
Classes | Functions | Variables
run_tests Namespace Reference

Classes

class  TestSuite
 
class  TestCase
 

Functions

def main ()
 
def write_junit_xml (test_results)
 
def print_captured_output (test_results)
 
def safe_str (obj)
 
def run_tests (tests_dir)
 

Variables

 unichr = chr
 
string __author__ = "Tamas Gal"
 
string __credits__ = "Brian Beyer"
 
string __license__ = "MIT"
 
string __email__ = "tgal@km3net.de"
 
string __status__ = "Development"
 
 TESTS_DIR = sys.argv[1]
 
string JUNIT_XML = 'out/junit_{}.xml'.format(os.path.basename(TESTS_DIR))
 
string INFO = '\033[94m'
 
string OK = '\033[92m'
 
string FAIL = '\033[91m'
 
string RST = '\033[0m'
 
string BOLD = '\033[1m'
 

Function Documentation

◆ main()

def run_tests.main ( )

Definition at line 50 of file run_tests.py.

50 def main():
51  test_results = run_tests(TESTS_DIR)
52  n_tests = len(test_results)
53  n_failed_tests = sum(1 for r in test_results.values() if r[0] > 0)
54  total_time = sum(r[1] for r in test_results.values())
55 
56  print("\n{}"
57  "Test summary\n"
58  "============\n{}"
59  "Total number of tests: {}\n{}"
60  "Failed tests: {}{}\n"
61  "Elapsed time: {:.1f}s\n".format(
62  INFO, RST, n_tests, BOLD + FAIL if n_failed_tests > 0 else OK,
63  n_failed_tests, RST, total_time))
64 
65  write_junit_xml(test_results)
66 
67  if n_failed_tests > 0:
68  print_captured_output(test_results)
69  exit(1)
70  else:
71  exit(0)
72 
73 
std::ostream & print(std::ostream &out, const JTestSummary &summary, const char delimiter=' ', const bool useColors=true)
Print test summary.
def print_captured_output(test_results)
Definition: run_tests.py:90
def write_junit_xml(test_results)
Definition: run_tests.py:74
def main()
Definition: run_tests.py:50

◆ write_junit_xml()

def run_tests.write_junit_xml (   test_results)
Generate XML file according to JUnit specs

Definition at line 74 of file run_tests.py.

74 def write_junit_xml(test_results):
75  """Generate XML file according to JUnit specs"""
76  test_cases = []
77  for test_script, (exit_code, t, stdout, stderr) in test_results.items():
78  test_case = TestCase(test_script,
79  elapsed_sec=t,
80  stdout=stdout,
81  stderr=stderr)
82  if exit_code > 0:
83  test_case.add_error_info('non-zero exit-code: %d' % exit_code)
84  test_cases.append(test_case)
85  test_suite = TestSuite("Jpp Test Suite", test_cases)
86  with open(JUNIT_XML, 'w') as f:
87  TestSuite.to_file(f, [test_suite])
88 
89 
T * open(const std::string &file_name)
Open file.
Definition: JeepToolkit.hh:351

◆ print_captured_output()

def run_tests.print_captured_output (   test_results)
Prints the STDOUT and STDERR of failing test scripts

Definition at line 90 of file run_tests.py.

90 def print_captured_output(test_results):
91  """Prints the STDOUT and STDERR of failing test scripts"""
92  print("{}"
93  "Captured output of failing tests\n"
94  "================================\n{}".format(INFO, RST))
95  for test_script, (exit_code, t, stdout, stderr) in test_results.items():
96  if exit_code > 0:
97  print("{}\n{}\n".format(test_script, len(test_script) * '-'))
98  print('{}stdout:{}\n{}\n{}stderr:{}\n{}'.format(
99  OK + BOLD, RST, stdout, FAIL + BOLD, RST, stderr))
100 
101 

◆ safe_str()

def run_tests.safe_str (   obj)

Definition at line 102 of file run_tests.py.

102 def safe_str(obj):
103  return obj.decode('utf-8').encode('ascii', 'ignore').decode('ascii')
104 
105 
def safe_str(obj)
Definition: run_tests.py:102

◆ run_tests()

def run_tests.run_tests (   tests_dir)
Runs each script in the tests directory and returns the results.

Parameters
----------
tests_dir: str
  The path to the test dir, containing the test scripts (`*.sh`).

Returns
-------
dict: key = script path, value = (exit_code, elapsed_time, stdout, stderr)

Definition at line 106 of file run_tests.py.

106 def run_tests(tests_dir):
107  """Runs each script in the tests directory and returns the results.
108 
109  Parameters
110  ----------
111  tests_dir: str
112  The path to the test dir, containing the test scripts (`*.sh`).
113 
114  Returns
115  -------
116  dict: key = script path, value = (exit_code, elapsed_time, stdout, stderr)
117 
118  """
119  test_results = {}
120 
121  for subdir in sorted(glob(join(tests_dir, '*'))):
122  component_group = basename(subdir)
123  print("\n{}{}\n{}{}".format(INFO, component_group,
124  len(component_group) * '=', RST))
125  for test_script in sorted(glob(join(subdir, '*.sh')) + glob(join(subdir, '*.csh'))):
126  print("+ {}".format(test_script), end=' => ')
127  sys.stdout.flush()
128  start_time = time()
129  proc = Popen(test_script, stdout=PIPE, stderr=PIPE)
130  out, err = [safe_str(t) for t in proc.communicate()]
131  exit_code = proc.wait()
132  delta_t = time() - start_time
133  test_results[test_script] = (exit_code, delta_t, out, err)
134  print(" ({:.2f} s) ".format(delta_t), end='')
135  sys.stdout.flush()
136  if exit_code > 0:
137  print("{}FAILED (exit code {}){}".format(FAIL, exit_code, RST))
138  sys.stdout.flush()
139  else:
140  print("{}OK{}".format(OK, RST))
141  sys.stdout.flush()
142 
143  return test_results
144 
145 
JRange< T, JComparator_t > join(const JRange< T, JComparator_t > &first, const JRange< T, JComparator_t > &second)
Join ranges.
Definition: JRange.hh:659
def run_tests(tests_dir)
Definition: run_tests.py:106

Variable Documentation

◆ unichr

run_tests.unichr = chr

Definition at line 29 of file run_tests.py.

◆ __author__

string run_tests.__author__ = "Tamas Gal"
private

Definition at line 31 of file run_tests.py.

◆ __credits__

string run_tests.__credits__ = "Brian Beyer"
private

Definition at line 32 of file run_tests.py.

◆ __license__

string run_tests.__license__ = "MIT"
private

Definition at line 33 of file run_tests.py.

◆ __email__

string run_tests.__email__ = "tgal@km3net.de"
private

Definition at line 34 of file run_tests.py.

◆ __status__

string run_tests.__status__ = "Development"
private

Definition at line 35 of file run_tests.py.

◆ TESTS_DIR

run_tests.TESTS_DIR = sys.argv[1]

Definition at line 37 of file run_tests.py.

◆ JUNIT_XML

string run_tests.JUNIT_XML = 'out/junit_{}.xml'.format(os.path.basename(TESTS_DIR))

Definition at line 38 of file run_tests.py.

◆ INFO

run_tests.INFO = '\033[94m'

Definition at line 41 of file run_tests.py.

◆ OK

run_tests.OK = '\033[92m'

Definition at line 42 of file run_tests.py.

◆ FAIL

run_tests.FAIL = '\033[91m'

Definition at line 43 of file run_tests.py.

◆ RST

run_tests.RST = '\033[0m'

Definition at line 44 of file run_tests.py.

◆ BOLD

run_tests.BOLD = '\033[1m'

Definition at line 45 of file run_tests.py.