Commit 7ee3f75b authored by James Kennington's avatar James Kennington
Browse files

add stderr attr for easy access

parent 1a226786
Pipeline #282476 passed with stage
in 2 minutes and 42 seconds
......@@ -146,6 +146,8 @@ class Classifier:
self._stdout = StringIO()
self._stderr = StringIO()
self._pipe_manager = wurlitzer.Wurlitzer(stdout=self._stdout, stderr=self._stderr)
self.stdout = None
self.stderr = None
def __enter__(self):
self._pipe_manager.__enter__()
......@@ -155,14 +157,16 @@ class Classifier:
# Closeout pipe manager
self._pipe_manager.__exit__(exc_type, exc_val, exc_tb)
# close pipes
# close pipes and read
self._stdout.seek(0)
self._stderr.seek(0)
stderr = self._stderr.read()
if stderr:
self.stdout = self._stdout.read()
self.stderr = self._stderr.read()
if self.stderr:
# TODO make this more sophisticated / controllable
logging.error(stderr)
logging.error(self.stderr)
# Classify error
c = self.classify(exc_val)
......
......@@ -121,5 +121,31 @@ class TestLalRules:
with error.classify(rules=[error.LAL_RULE_SIM_INPUT_DOMAIN]) as c:
_ = lalsim.SimInspiralFD(**parameters)
print(c)
def test_stderr_capture(self):
parameters = {
'm1': -1, # Invalid input of negative mass
'm2': 1,
'S1x': 0.,
'S1y': 0.,
'S1z': 0.,
'S2x': 0.,
'S2y': 0.,
'S2z': 0.,
}
parameters['distance'] = 1.e6 * lal.PC_SI
parameters['inclination'] = 0.
parameters['phiRef'] = 0.
parameters['longAscNodes'] = 0.
parameters['eccentricity'] = 0.
parameters['meanPerAno'] = 0.
parameters['deltaF'] = 1.
parameters['f_min'] = 10.
parameters['f_max'] = 512.
parameters['f_ref'] = 0.
parameters['LALparams'] = None
parameters['approximant'] = lalsim.GetApproximantFromString('IMRPhenomD')
try:
with error.classify(rules=[error.LAL_RULE_SIM_INPUT_DOMAIN]) as c:
_ = lalsim.SimInspiralFD(**parameters)
except error.LalSimInputDomainError:
assert c.stderr[:10] == 'XLAL Error'
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment