1414import tempfile
1515import unittest
1616from pathlib import Path
17+ from test import CustomTestCase
1718
1819import numpy as np
1920import pandas as pd
@@ -371,7 +372,7 @@ def test_write_stan_json_bad(self):
371372 write_stan_json (file_bad , dict_badtype_nested )
372373
373374
374- class ReadStanCsvTest (unittest . TestCase ):
375+ class ReadStanCsvTest (CustomTestCase ):
375376 def test_check_sampler_csv_1 (self ):
376377 csv_good = os .path .join (DATAFILES_PATH , 'bernoulli_output_1.csv' )
377378 dict = check_sampler_csv (
@@ -386,13 +387,13 @@ def test_check_sampler_csv_1(self):
386387 self .assertEqual (10 , dict ['draws_sampling' ])
387388 self .assertEqual (8 , len (dict ['column_names' ]))
388389
389- with self .assertRaisesRegex (
390+ with self .assertRaisesRegexNested (
390391 ValueError , 'config error, expected thin = 2'
391392 ):
392393 check_sampler_csv (
393394 path = csv_good , iter_warmup = 100 , iter_sampling = 20 , thin = 2
394395 )
395- with self .assertRaisesRegex (
396+ with self .assertRaisesRegexNested (
396397 ValueError , 'config error, expected save_warmup'
397398 ):
398399 check_sampler_csv (
@@ -401,7 +402,7 @@ def test_check_sampler_csv_1(self):
401402 iter_sampling = 10 ,
402403 save_warmup = True ,
403404 )
404- with self .assertRaisesRegex (ValueError , 'expected 1000 draws' ):
405+ with self .assertRaisesRegexNested (ValueError , 'expected 1000 draws' ):
405406 check_sampler_csv (path = csv_good , iter_warmup = 100 )
406407
407408 def test_check_sampler_csv_2 (self ):
@@ -411,34 +412,34 @@ def test_check_sampler_csv_2(self):
411412
412413 def test_check_sampler_csv_3 (self ):
413414 csv_bad = os .path .join (DATAFILES_PATH , 'output_bad_cols.csv' )
414- with self .assertRaisesRegex (Exception , '8 items' ):
415+ with self .assertRaisesRegexNested (Exception , '8 items' ):
415416 check_sampler_csv (csv_bad )
416417
417418 def test_check_sampler_csv_4 (self ):
418419 csv_bad = os .path .join (DATAFILES_PATH , 'output_bad_rows.csv' )
419- with self .assertRaisesRegex (Exception , 'found 9' ):
420+ with self .assertRaisesRegexNested (Exception , 'found 9' ):
420421 check_sampler_csv (csv_bad )
421422
422423 def test_check_sampler_csv_metric_1 (self ):
423424 csv_bad = os .path .join (DATAFILES_PATH , 'output_bad_metric_1.csv' )
424- with self .assertRaisesRegex (Exception , 'expecting metric' ):
425+ with self .assertRaisesRegexNested (Exception , 'expecting metric' ):
425426 check_sampler_csv (csv_bad )
426427
427428 def test_check_sampler_csv_metric_2 (self ):
428429 csv_bad = os .path .join (DATAFILES_PATH , 'output_bad_metric_2.csv' )
429- with self .assertRaisesRegex (Exception , 'invalid step size' ):
430+ with self .assertRaisesRegexNested (Exception , 'invalid step size' ):
430431 check_sampler_csv (csv_bad )
431432
432433 def test_check_sampler_csv_metric_3 (self ):
433434 csv_bad = os .path .join (DATAFILES_PATH , 'output_bad_metric_3.csv' )
434- with self .assertRaisesRegex (
435+ with self .assertRaisesRegexNested (
435436 Exception , 'invalid or missing mass matrix specification'
436437 ):
437438 check_sampler_csv (csv_bad )
438439
439440 def test_check_sampler_csv_metric_4 (self ):
440441 csv_bad = os .path .join (DATAFILES_PATH , 'output_bad_metric_4.csv' )
441- with self .assertRaisesRegex (
442+ with self .assertRaisesRegexNested (
442443 Exception , 'invalid or missing mass matrix specification'
443444 ):
444445 check_sampler_csv (csv_bad )
@@ -474,15 +475,17 @@ def test_check_sampler_csv_thin(self):
474475 self .assertEqual (dict ['max_depth' ], 11 )
475476 self .assertEqual (dict ['delta' ], 0.98 )
476477
477- with self .assertRaisesRegex (ValueError , 'config error' ):
478+ with self .assertRaisesRegexNested (ValueError , 'config error' ):
478479 check_sampler_csv (
479480 path = csv_file ,
480481 is_fixed_param = False ,
481482 iter_sampling = 490 ,
482483 iter_warmup = 490 ,
483484 thin = 9 ,
484485 )
485- with self .assertRaisesRegex (ValueError , 'expected 490 draws, found 70' ):
486+ with self .assertRaisesRegexNested (
487+ ValueError , 'expected 490 draws, found 70'
488+ ):
486489 check_sampler_csv (
487490 path = csv_file ,
488491 is_fixed_param = False ,
0 commit comments