Skip to content

Commit 34163f9

Browse files
committed
Use context manager for catching errors.
1 parent 810fda7 commit 34163f9

File tree

4 files changed

+9
-17
lines changed

4 files changed

+9
-17
lines changed

test/test_generate_quantities.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,9 @@ def test_timeout(self):
480480
stan = os.path.join(DATAFILES_PATH, 'timeout.stan')
481481
timeout_model = CmdStanModel(stan_file=stan)
482482
fit = timeout_model.sample(data={'loop': 0}, chains=1, iter_sampling=10)
483-
self.assertRaisesRegex(
484-
RuntimeError, 'processing timed out',
485-
timeout_model.generate_quantities, timeout=0.1,
486-
mcmc_sample=fit, data={'loop': 1},
487-
)
483+
with self.assertRaisesRegex(RuntimeError, 'processing timed out'):
484+
timeout_model.generate_quantities(timeout=0.1, mcmc_sample=fit,
485+
data={'loop': 1})
488486

489487

490488
if __name__ == '__main__':

test/test_optimize.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -637,10 +637,8 @@ def test_attrs(self):
637637
def test_timeout(self):
638638
stan = os.path.join(DATAFILES_PATH, 'timeout.stan')
639639
timeout_model = CmdStanModel(stan_file=stan)
640-
self.assertRaisesRegex(
641-
RuntimeError, 'processing timed out', timeout_model.optimize,
642-
data={'loop': 1}, timeout=0.1,
643-
)
640+
with self.assertRaisesRegex(RuntimeError, 'processing timed out'):
641+
timeout_model.optimize(data={'loop': 1}, timeout=0.1)
644642

645643

646644
if __name__ == '__main__':

test/test_sample.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,10 +1916,8 @@ def test_diagnostics(self):
19161916
def test_timeout(self):
19171917
stan = os.path.join(DATAFILES_PATH, 'timeout.stan')
19181918
timeout_model = CmdStanModel(stan_file=stan)
1919-
self.assertRaisesRegex(
1920-
RuntimeError, 'processing timed out', timeout_model.sample,
1921-
timeout=0.1, chains=1, data={'loop': 1},
1922-
)
1919+
with self.assertRaisesRegex(RuntimeError, 'processing timed out'):
1920+
timeout_model.sample(timeout=0.1, chains=1, data={'loop': 1})
19231921

19241922

19251923
if __name__ == '__main__':

test/test_variational.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,8 @@ def test_attrs(self):
294294
def test_timeout(self):
295295
stan = os.path.join(DATAFILES_PATH, 'timeout.stan')
296296
timeout_model = CmdStanModel(stan_file=stan)
297-
self.assertRaisesRegex(
298-
RuntimeError, 'processing timed out', timeout_model.variational,
299-
timeout=0.1, data={'loop': 1}, show_console=True,
300-
)
297+
with self.assertRaisesRegex(RuntimeError, 'processing timed out'):
298+
timeout_model.variational(timeout=0.1, data={'loop': 1})
301299

302300

303301
if __name__ == '__main__':

0 commit comments

Comments
 (0)