Jpp  18.4.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Functions | Variables
run_tests Namespace Reference

Classes

class  TestSuite
 
class  TestCase
 

Functions

def main
 
def write_junit_xml
 
def print_captured_output
 
def safe_str
 
def run_tests
 

Variables

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

Function Documentation

def run_tests.main ( )

Definition at line 50 of file run_tests.py.

50 
51 def main():
52  test_results = run_tests(TESTS_DIR)
53  n_tests = len(test_results)
54  n_failed_tests = sum(1 for r in test_results.values() if r[0] > 0)
55  total_time = sum(r[1] for r in test_results.values())
56 
57  print("\n{}"
58  "Test summary\n"
59  "============\n{}"
60  "Total number of tests: {}\n{}"
61  "Failed tests: {}{}\n"
62  "Elapsed time: {:.1f}s\n".format(
63  INFO, RST, n_tests, BOLD + FAIL if n_failed_tests > 0 else OK,
64  n_failed_tests, RST, total_time))
65 
66  write_junit_xml(test_results)
67 
68  if n_failed_tests > 0:
69  print_captured_output(test_results)
70  exit(1)
71  else:
72  exit(0)
73 
exit
Definition: JPizza.sh:36
def print_captured_output
Definition: run_tests.py:90
print
Definition: JConvertDusj.sh:44
def main
Definition: run_tests.py:50
def write_junit_xml
Definition: run_tests.py:74
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 
75 def write_junit_xml(test_results):
76  """Generate XML file according to JUnit specs"""
77  test_cases = []
78  for test_script, (exit_code, t, stdout, stderr) in test_results.items():
79  test_case = TestCase(test_script,
80  elapsed_sec=t,
81  stdout=stdout,
82  stderr=stderr)
83  if exit_code > 0:
84  test_case.add_error_info('non-zero exit-code: %d' % exit_code)
85  test_cases.append(test_case)
86  test_suite = TestSuite("Jpp Test Suite", test_cases)
87  with open(JUNIT_XML, 'w') as f:
88  TestSuite.to_file(f, [test_suite])
89 
T * open(const std::string &file_name)
Open file.
Definition: JeepToolkit.hh:346
def write_junit_xml
Definition: run_tests.py:74
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 
91 def print_captured_output(test_results):
92  """Prints the STDOUT and STDERR of failing test scripts"""
93  print("{}"
94  "Captured output of failing tests\n"
95  "================================\n{}".format(INFO, RST))
96  for test_script, (exit_code, t, stdout, stderr) in test_results.items():
97  if exit_code > 0:
98  print("{}\n{}\n".format(test_script, len(test_script) * '-'))
99  print('{}stdout:{}\n{}\n{}stderr:{}\n{}'.format(
100  OK + BOLD, RST, stdout, FAIL + BOLD, RST, stderr))
101 
def print_captured_output
Definition: run_tests.py:90
print
Definition: JConvertDusj.sh:44
def run_tests.safe_str (   obj)

Definition at line 102 of file run_tests.py.

103 def safe_str(obj):
104  return obj.decode('utf-8').encode('ascii', 'ignore').decode('ascii')
105 
def safe_str
Definition: run_tests.py:102
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.

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

Variable Documentation

run_tests.unichr = chr

Definition at line 29 of file run_tests.py.

string run_tests.__author__ = "Tamas Gal"

Definition at line 31 of file run_tests.py.

string run_tests.__credits__ = "Brian Beyer"

Definition at line 32 of file run_tests.py.

string run_tests.__license__ = "MIT"

Definition at line 33 of file run_tests.py.

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

Definition at line 34 of file run_tests.py.

string run_tests.__status__ = "Development"

Definition at line 35 of file run_tests.py.

list run_tests.TESTS_DIR = sys.argv[1]

Definition at line 37 of file run_tests.py.

string run_tests.JUNIT_XML = 'out/junit_{}.xml'

Definition at line 38 of file run_tests.py.

string run_tests.INFO = '\033[94m'

Definition at line 41 of file run_tests.py.

string run_tests.OK = '\033[92m'

Definition at line 42 of file run_tests.py.

string run_tests.FAIL = '\033[91m'

Definition at line 43 of file run_tests.py.

string run_tests.RST = '\033[0m'

Definition at line 44 of file run_tests.py.

string run_tests.BOLD = '\033[1m'

Definition at line 45 of file run_tests.py.