Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_metric_missing(self):
metric_file = os.path.join(DATAFILES_PATH, 'no_such_file.json')
with self.assertRaisesRegex(Exception, 'No such file or directory'):
read_metric(metric_file)
def test_metric_rdump_bad_1(self):
metric_file = os.path.join(DATAFILES_PATH, 'metric_bad_1.data.R')
with self.assertRaisesRegex(
Exception, 'bad or missing entry "inv_metric"'
):
read_metric(metric_file)
def test_metric_rdump_bad_2(self):
metric_file = os.path.join(DATAFILES_PATH, 'metric_bad_2.data.R')
with self.assertRaisesRegex(
Exception, 'bad or missing entry "inv_metric"'
):
read_metric(metric_file)
def test_metric_json_matrix(self):
metric_file = os.path.join(DATAFILES_PATH, 'metric_dense.data.json')
dims = read_metric(metric_file)
self.assertEqual(2, len(dims))
self.assertEqual(dims[0], dims[1])
def test_metric_rdump_matrix(self):
metric_file = os.path.join(DATAFILES_PATH, 'metric_dense.data.R')
dims = read_metric(metric_file)
self.assertEqual(2, len(dims))
self.assertEqual(dims[0], dims[1])
len(self.metric), len(self.chain_ids)
)
)
names_set = set(self.metric)
if len(names_set) != len(self.metric):
raise ValueError(
'each chain must have its own metric file,'
' found duplicates in metric files list.'
)
for i in range(len(self.metric)):
if not os.path.exists(self.metric[i]):
raise ValueError(
'no such file {}'.format(self.metric[i])
)
if i == 0:
dims = read_metric(self.metric[i])
else:
dims2 = read_metric(self.metric[i])
if len(dims) != len(dims2):
raise ValueError(
'metrics files {}, {},'
' inconsistent metrics'.format(
self.metric[0], self.metric[i]
)
)
for j in range(len(dims)):
if dims[j] != dims2[j]:
raise ValueError(
'metrics files {}, {},'
' inconsistent metrics'.format(
self.metric[0], self.metric[i]
)
'step_size must be > 0, found {}'.format(
self.step_size[i]
)
)
if self.metric is not None:
dims = None
if isinstance(self.metric, str):
if self.metric in ['diag', 'diag_e']:
self.metric = 'diag_e'
elif self.metric in ['dense', 'dense_e']:
self.metric = 'dense_e'
else:
if not os.path.exists(self.metric):
raise ValueError('no such file {}'.format(self.metric))
dims = read_metric(self.metric)
elif isinstance(self.metric, list):
if len(self.metric) != len(self.chain_ids):
raise ValueError(
'number of metric files must match number of chains '
' found {} metric files for {} chains '.format(
len(self.metric), len(self.chain_ids)
)
)
names_set = set(self.metric)
if len(names_set) != len(self.metric):
raise ValueError(
'each chain must have its own metric file,'
' found duplicates in metric files list.'
)
for i in range(len(self.metric)):
if not os.path.exists(self.metric[i]):
for step_size in self.step_size:
if step_size < 0:
raise ValueError(
'step_size must be > 0, found {}'.format(step_size)
)
if self.metric is not None:
dims = []
if isinstance(self.metric, str):
if self.metric in ['diag', 'diag_e']:
self.metric = 'diag_e'
elif self.metric in ['dense', 'dense_e']:
self.metric = 'dense_e'
else:
if not os.path.exists(self.metric):
raise ValueError('no such file {}'.format(self.metric))
dims = read_metric(self.metric)
elif isinstance(self.metric, (list, tuple)):
if len(self.metric) != chains:
raise ValueError(
'number of metric files must match number of chains,'
' found {} metric files for {} chains'.format(
len(self.metric), chains
)
)
names_set = set(self.metric)
if len(names_set) != len(self.metric):
raise ValueError(
'each chain must have its own metric file,'
' found duplicates in metric files list.'
)
for i, metric in enumerate(self.metric):
if not os.path.exists(metric):
'number of metric files must match number of chains,'
' found {} metric files for {} chains'.format(
len(self.metric), chains
)
)
names_set = set(self.metric)
if len(names_set) != len(self.metric):
raise ValueError(
'each chain must have its own metric file,'
' found duplicates in metric files list.'
)
for i, metric in enumerate(self.metric):
if not os.path.exists(metric):
raise ValueError('no such file {}'.format(metric))
if i == 0:
dims = read_metric(metric)
else:
dims2 = read_metric(metric)
if len(dims) != len(dims2):
raise ValueError(
'metrics files {}, {},'
' inconsistent metrics'.format(
self.metric[0], metric
)
)
for dim, dim2 in zip(dims, dims2):
if dim != dim2:
raise ValueError(
'metrics files {}, {},'
' inconsistent metrics'.format(
self.metric[0], metric
)