Skip to content

Commit

Permalink
Add new function so total number or errors/failures reported by setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
josh-willis committed Sep 11, 2013
1 parent 3f73c59 commit 1dae029
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 18 deletions.
4 changes: 2 additions & 2 deletions test/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from pycbc.types import *
from pycbc.scheme import *
import numpy
from utils import array_base, parse_args_all_schemes
from utils import array_base, parse_args_all_schemes, simple_exit
import sys
import os
import tempfile
Expand Down Expand Up @@ -516,4 +516,4 @@ def __init__(self,*args):

if __name__ == '__main__':
results = unittest.TextTestRunner(verbosity=2).run(suite)

simple_exit(results)
3 changes: 2 additions & 1 deletion test/test_array_lal.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from pycbc.types import *
from pycbc.scheme import *
from lal import LIGOTimeGPS as LTG
from utils import array_base, parse_args_all_schemes
from utils import array_base, parse_args_all_schemes, simple_exit

_scheme, _context = parse_args_all_schemes("lal() method")

Expand Down Expand Up @@ -116,3 +116,4 @@ def test_array_lal_errors(self):

if __name__ == '__main__':
results = unittest.TextTestRunner(verbosity=2).run(suite)
simple_exit(results)
3 changes: 2 additions & 1 deletion test/test_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
import pycbc.fft
import unittest
import sys
from utils import parse_args_all_schemes
from utils import parse_args_all_schemes, simple_exit
from lal import LIGOTimeGPS as LTG
import lal as _lal

Expand Down Expand Up @@ -782,3 +782,4 @@ def test_rev_complex_fs(self):
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(klass))

results = unittest.TextTestRunner(verbosity=2).run(suite)
simple_exit(results)
3 changes: 2 additions & 1 deletion test/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import os
import subprocess
import sys
from utils import parse_args_cpu_only
from utils import parse_args_cpu_only, simple_exit

# Frame tests only need to happen on the CPU
parse_args_cpu_only("Frame I/O")
Expand Down Expand Up @@ -138,3 +138,4 @@ def test_frame(self):
for klass in TestClasses:
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(klass))
results = unittest.TextTestRunner(verbosity=2).run(suite)
simple_exit(results)
3 changes: 2 additions & 1 deletion test/test_frequencyseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import sys
import os
import tempfile
from utils import array_base, parse_args_all_schemes
from utils import array_base, parse_args_all_schemes, simple_exit

_scheme, _context = parse_args_all_schemes("FrequencySeries")

Expand Down Expand Up @@ -562,3 +562,4 @@ def __init__(self, *args):

if __name__ == '__main__':
results = unittest.TextTestRunner(verbosity=2).run(suite)
simple_exit(results)
3 changes: 2 additions & 1 deletion test/test_injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from glue.ligolw import ligolw
from glue.ligolw import lsctables
from glue.ligolw import utils
from utils import parse_args_cpu_only
from utils import parse_args_cpu_only, simple_exit

# Injection tests only need to happen on the CPU
parse_args_cpu_only("Injections")
Expand Down Expand Up @@ -163,3 +163,4 @@ def test_injection_absence(self):

if __name__ == '__main__':
results = unittest.TextTestRunner(verbosity=2).run(suite)
simple_exit(results)
3 changes: 2 additions & 1 deletion test/test_lalwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import numpy
from numpy import dtype, float32, float64, complex64, complex128
import unittest
from utils import parse_args_all_schemes
from utils import parse_args_all_schemes, simple_exit
import sys
from lal import LIGOTimeGPS as LTG

Expand Down Expand Up @@ -457,3 +457,4 @@ def test_Argout(self):
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(klass))

results = unittest.TextTestRunner(verbosity=2).run(suite)
simple_exit(results)
3 changes: 2 additions & 1 deletion test/test_matchedfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from math import sqrt
import pycbc.fft
import numpy
from utils import parse_args_all_schemes
from utils import parse_args_all_schemes, simple_exit

_scheme, _context = parse_args_all_schemes("Matched Filter")

Expand Down Expand Up @@ -145,3 +145,4 @@ def test_errors(self):

if __name__ == '__main__':
results = unittest.TextTestRunner(verbosity=2).run(suite)
simple_exit(results)
3 changes: 2 additions & 1 deletion test/test_pnutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import unittest
from pycbc.pnutils import *
from pycbc.scheme import *
from utils import parse_args_cpu_only
from utils import parse_args_cpu_only, simple_exit

# We only need CPU tests
parse_args_cpu_only("PN Utilities")
Expand Down Expand Up @@ -69,3 +69,4 @@ def test_mass1_mass2_to_mchirp_eta(self):

if __name__ == '__main__':
results = unittest.TextTestRunner(verbosity=2).run(suite)
simple_exit(results)
3 changes: 2 additions & 1 deletion test/test_psd.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from pycbc.fft import ifft
import unittest
import numpy
from utils import parse_args_all_schemes
from utils import parse_args_all_schemes, simple_exit

_scheme, _context = parse_args_all_schemes("PSD")

Expand Down Expand Up @@ -139,3 +139,4 @@ def test_estimate_welch_medianmean(self):

if __name__ == '__main__':
results = unittest.TextTestRunner(verbosity=2).run(suite)
simple_exit(results)
3 changes: 2 additions & 1 deletion test/test_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from pycbc.types import *
from pycbc.filter import *
from pycbc.scheme import *
from utils import parse_args_all_schemes
from utils import parse_args_all_schemes, simple_exit

_scheme, _context = parse_args_all_schemes("Resampling")

Expand Down Expand Up @@ -70,3 +70,4 @@ def test_resample_errors(self):

if __name__ == '__main__':
results = unittest.TextTestRunner(verbosity=2).run(suite)
simple_exit(results)
3 changes: 2 additions & 1 deletion test/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from pycbc.scheme import *
import numpy
import lal
from utils import array_base, parse_args_all_schemes
from utils import array_base, parse_args_all_schemes, simple_exit
import sys
import os
import tempfile
Expand Down Expand Up @@ -559,3 +559,4 @@ def __init__(self, *args):

if __name__ == '__main__':
results = unittest.TextTestRunner(verbosity=2).run(suite)
simple_exit(results)
3 changes: 2 additions & 1 deletion test/test_waveform.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from pycbc.waveform import *
import pycbc.fft
import numpy
from utils import parse_args_all_schemes
from utils import parse_args_all_schemes, simple_exit

_scheme, _context = parse_args_all_schemes("Waveform")

Expand Down Expand Up @@ -107,3 +107,4 @@ def test_errors(self):

if __name__ == '__main__':
results = unittest.TextTestRunner(verbosity=2).run(suite)
simple_exit(results)
26 changes: 22 additions & 4 deletions test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"""

import pycbc
from sys import exit
from sys import exit as _exit
from optparse import OptionParser, OptionValueError
from pycbc.scheme import CPUScheme, CUDAScheme, OpenCLScheme
from numpy import dtype, float32, float64, complex64, complex128
Expand Down Expand Up @@ -139,6 +139,24 @@ def parse_args_cpu_only(feature_str):

return

def simple_exit(results):
"""
A simpler version of exit_based_on_results(); this function causes the script
to exit normally with return value of zero if and only if all tests within the
script passed and had no errors. Otherwise it returns the number of failures
plus the number of errors
Parameters
----------
results: an instance of unittest.TestResult, returned (for instance) from a call such as
results = unittest.TextTestRunner(verbosity=2).run(suite)
"""
if results.wasSuccessful():
_exit(0)
else:
nfail = len(results.errors)+len(results.failures)
_exit(nfail)

def exit_based_on_results(results):
"""
A probably-obsolete function to exit from a unit test-script with a status that depends
Expand All @@ -164,11 +182,11 @@ def exit_based_on_results(results):
NotImpErrors +=1
break
if results.wasSuccessful():
sys.exit(0)
_exit(0)
elif len(results.failures)==0 and len(results.errors)==NotImpErrors:
sys.exit(1)
_exit(1)
else:
sys.exit(2)
_exit(2)

# Copied over from base_array.py so we can refactor it to remove
# the scheme shuffling and take advantage of the new equality/almost
Expand Down

0 comments on commit 1dae029

Please sign in to comment.