Jpp  18.0.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 run_tests
 
def decode
 

Variables

tuple PY2 = sys.version_info<(3, 0, 0)
 
 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 52 of file run_tests.py.

52 
53 def main():
54  test_results = run_tests(TESTS_DIR)
55  n_tests = len(test_results)
56  n_failed_tests = sum(1 for r in test_results.values() if r[0] > 0)
57  total_time = sum(r[1] for r in test_results.values())
58 
59  print("\n{}"
60  "Test summary\n"
61  "============\n{}"
62  "Total number of tests: {}\n{}"
63  "Failed tests: {}{}\n"
64  "Elapsed time: {:.1f}s\n".format(
65  INFO, RST, n_tests, BOLD + FAIL if n_failed_tests > 0 else OK,
66  n_failed_tests, RST, total_time))
67 
68  write_junit_xml(test_results)
69 
70  if n_failed_tests > 0:
71  print_captured_output(test_results)
72  exit(1)
73  else:
74  exit(0)
75 
exit
Definition: JPizza.sh:36
def print_captured_output
Definition: run_tests.py:92
print
Definition: JConvertDusj.sh:44
def main
Definition: run_tests.py:52
def write_junit_xml
Definition: run_tests.py:76
def run_tests.write_junit_xml (   test_results)
Generate XML file according to JUnit specs

Definition at line 76 of file run_tests.py.

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

Definition at line 92 of file run_tests.py.

92 
93 def print_captured_output(test_results):
94  """Prints the STDOUT and STDERR of failing test scripts"""
95  print("{}"
96  "Captured output of failing tests\n"
97  "================================\n{}".format(INFO, RST))
98  for test_script, (exit_code, t, stdout, stderr) in test_results.items():
99  if exit_code > 0:
100  print("{}\n{}\n".format(test_script, len(test_script) * '-'))
101  print('{}stdout:{}\n{}\n{}stderr:{}\n{}'.format(
102  OK + BOLD, RST, stdout.decode('utf-8'), FAIL + BOLD, RST,
103  stderr.decode('utf-8')))
104 
def print_captured_output
Definition: run_tests.py:92
print
Definition: JConvertDusj.sh:44
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 105 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'))):
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 = 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 
JRange< T, JComparator_t > join(const JRange< T, JComparator_t > &first, const JRange< T, JComparator_t > &second)
Join ranges.
Definition: JRange.hh:659
print
Definition: JConvertDusj.sh:44
def run_tests
Definition: run_tests.py:105
def run_tests.decode (   var,
  encoding 
)
If not already unicode, decode it.

Definition at line 145 of file run_tests.py.

146 def decode(var, encoding):
147  """
148  If not already unicode, decode it.
149  """
150  if PY2:
151  if isinstance(var, unicode):
152  ret = var
153  elif isinstance(var, str):
154  if encoding:
155  ret = var.decode(encoding)
156  else:
157  ret = unicode(var)
158  else:
159  ret = unicode(var)
160  else:
161  ret = str(var)
162  return ret
163 
def decode
Definition: run_tests.py:145

Variable Documentation

tuple run_tests.PY2 = sys.version_info<(3, 0, 0)

Definition at line 26 of file run_tests.py.

run_tests.unichr = chr

Definition at line 31 of file run_tests.py.

string run_tests.__author__ = "Tamas Gal"

Definition at line 33 of file run_tests.py.

string run_tests.__credits__ = "Brian Beyer"

Definition at line 34 of file run_tests.py.

string run_tests.__license__ = "MIT"

Definition at line 35 of file run_tests.py.

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

Definition at line 36 of file run_tests.py.

string run_tests.__status__ = "Development"

Definition at line 37 of file run_tests.py.

list run_tests.TESTS_DIR = sys.argv[1]

Definition at line 39 of file run_tests.py.

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

Definition at line 40 of file run_tests.py.

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

Definition at line 43 of file run_tests.py.

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

Definition at line 44 of file run_tests.py.

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

Definition at line 45 of file run_tests.py.

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

Definition at line 46 of file run_tests.py.

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

Definition at line 47 of file run_tests.py.