From 5e568e1bd398fb9a0342b485834a8ac8cccf6c42 Mon Sep 17 00:00:00 2001 From: jburnim Date: Mon, 11 Mar 2024 10:29:40 -0700 Subject: [PATCH] Update assertRaisesRegexp -> assertRaisesRegex PiperOrigin-RevId: 614713466 --- UNITTEST.md | 4 +-- .../inference_gym/internal/test_util_test.py | 8 ++--- .../python/bijectors/bijector_test.py | 34 +++++++++---------- .../python/bijectors/blockwise_test.py | 4 +-- .../python/bijectors/chain_test.py | 2 +- .../bijectors/correlation_cholesky_test.py | 4 +-- .../python/bijectors/cumsum_test.py | 8 ++--- .../python/bijectors/fill_triangular_test.py | 4 +-- .../bijectors/masked_autoregressive_test.py | 16 ++++----- .../python/bijectors/permute_test.py | 10 +++--- .../python/bijectors/power_test.py | 2 +- .../python/bijectors/real_nvp_test.py | 14 ++++---- .../python/bijectors/reshape_test.py | 12 +++---- .../bijectors/scale_matvec_diag_test.py | 2 +- .../scale_matvec_linear_operator_test.py | 8 ++--- .../bijectors/scale_matvec_tril_test.py | 2 +- .../python/bijectors/split_test.py | 12 +++---- .../python/bijectors/transpose_test.py | 12 +++---- .../distributions/autoregressive_test.py | 16 ++++----- .../distributions/batch_broadcast_test.py | 8 ++--- .../distributions/batch_reshape_test.py | 14 ++++---- .../python/distributions/binomial_test.py | 2 +- .../python/distributions/blockwise_test.py | 4 +-- .../python/distributions/categorical_test.py | 2 +- .../python/distributions/cholesky_lkj_test.py | 2 +- .../continuous_bernoulli_test.py | 4 +-- .../distributions/deterministic_test.py | 24 ++++++------- .../dirichlet_multinomial_test.py | 2 +- .../python/distributions/dirichlet_test.py | 2 +- .../distribution_properties_test.py | 2 +- .../python/distributions/distribution_test.py | 24 ++++++------- .../exponentially_modified_gaussian_test.py | 2 +- .../distributions/finite_discrete_test.py | 8 ++--- .../distributions/generalized_normal_test.py | 2 +- .../python/distributions/half_cauchy_test.py | 6 ++-- .../python/distributions/half_normal_test.py | 2 +- .../distributions/half_student_t_test.py | 2 +- .../distributions/hidden_markov_model_test.py | 28 +++++++-------- .../python/distributions/independent_test.py | 12 +++---- .../python/distributions/johnson_su_test.py | 2 +- .../joint_distribution_auto_batched_test.py | 2 +- .../joint_distribution_coroutine_test.py | 14 ++++---- .../joint_distribution_named_test.py | 6 ++-- .../joint_distribution_sequential_test.py | 8 ++--- .../distributions/kullback_leibler_test.py | 8 ++--- .../python/distributions/laplace_test.py | 2 +- .../distributions/linear_gaussian_ssm_test.py | 8 ++--- .../python/distributions/lkj_test.py | 2 +- .../python/distributions/logistic_test.py | 2 +- .../python/distributions/markov_chain_test.py | 4 +-- .../python/distributions/multinomial_test.py | 2 +- .../multivariate_student_t_test.py | 8 ++--- .../python/distributions/mvn_diag_test.py | 2 +- .../python/distributions/normal_test.py | 4 +-- .../distributions/onehot_categorical_test.py | 4 +-- .../distributions/ordered_logistic_test.py | 2 +- .../distributions/plackett_luce_test.py | 4 +-- .../distributions/power_spherical_test.py | 4 +-- .../relaxed_onehot_categorical_test.py | 4 +-- .../python/distributions/sample_test.py | 4 +-- .../stopping_ratio_logistic_test.py | 2 +- .../distributions/von_mises_fisher_test.py | 2 +- .../python/distributions/wishart_test.py | 6 ++-- .../joint_distribution_pinned_test.py | 4 +-- ..._gaussian_process_regression_model_test.py | 6 ++-- .../multitask_gaussian_process_test.py | 6 ++-- .../nn/util/random_variable_test.py | 4 +-- .../sequential/iterated_filter_test.py | 2 +- .../sts_gibbs/gibbs_sampler_test.py | 6 ++-- .../vi/surrogate_posteriors_test.py | 2 +- .../util/trainable_linear_operators_test.py | 2 +- .../internal/backend/numpy/numpy_test.py | 2 +- .../python/internal/distribution_util_test.py | 4 +-- .../python/internal/slicing_test.py | 2 +- .../python/internal/structural_tuple_test.py | 34 +++++++++---------- .../internal/vectorization_util_test.py | 4 +-- .../distribution_tensor_coercible_test.py | 2 +- .../python/math/integration_test.py | 4 +-- .../python/math/interpolation_test.py | 6 ++-- .../python/math/ode/ode_test.py | 2 +- .../python/math/scan_associative_test.py | 4 +-- .../python/mcmc/diagnostic_test.py | 8 ++--- .../python/mcmc/internal/util_test.py | 4 +-- .../python/mcmc/replica_exchange_mc_test.py | 2 +- .../python/monte_carlo/expectation_test.py | 4 +-- .../loss_not_decreasing_test.py | 2 +- .../python/stats/sample_stats_test.py | 6 ++-- .../python/sts/components/sum_test.py | 2 +- 88 files changed, 278 insertions(+), 278 deletions(-) diff --git a/UNITTEST.md b/UNITTEST.md index 5a6487f20f..7524eab3a5 100644 --- a/UNITTEST.md +++ b/UNITTEST.md @@ -118,13 +118,13 @@ class _DistributionTest(tf.test.TestCase): class DistributionTest_StaticShape(_DistributionTest): ... def assertRaisesError(self, msg): - return self.assertRaisesRegexp(Exception, msg) + return self.assertRaisesRegex(Exception, msg) class DistributionTest_DynamicShape(_DistributionTest): ... def assertRaisesError(self, msg): if tf.executing_eagerly(): - return self.assertRaisesRegexp(Exception, msg) + return self.assertRaisesRegex(Exception, msg) return self.assertRaisesOpError(msg) del _DistributionTest # Don't run tests for the base class. diff --git a/spinoffs/inference_gym/inference_gym/internal/test_util_test.py b/spinoffs/inference_gym/inference_gym/internal/test_util_test.py index 24860b2568..9a03695569 100644 --- a/spinoffs/inference_gym/inference_gym/internal/test_util_test.py +++ b/spinoffs/inference_gym/inference_gym/internal/test_util_test.py @@ -175,7 +175,7 @@ def testCorrectGroundTruthWithHMC(self): def testBadGroundTruthWithHMC(self): """Tests that an error is raised if the ground truth is wrong.""" model = TestModel(ground_truth_mean=-1000.) - with self.assertRaisesRegexp(AssertionError, 'Not equal to tolerance'): + with self.assertRaisesRegex(AssertionError, 'Not equal to tolerance'): self.validate_ground_truth_using_hmc( model, num_chains=4, @@ -195,7 +195,7 @@ def testCorrectGroundTruthWithMC(self): def testBadGroundTruthWithMC(self): """Tests that an error is raised if the ground truth is wrong.""" model = TestModel(ground_truth_mean=-10.) - with self.assertRaisesRegexp(AssertionError, 'Not equal to tolerance'): + with self.assertRaisesRegex(AssertionError, 'Not equal to tolerance'): self.validate_ground_truth_using_monte_carlo( model, num_samples=4000, @@ -210,8 +210,8 @@ def testCorrectMaterialization(self): def testBadMaterialization(self): """Tests that an error is raised if dataset materialization is wrong.""" dataset = np.zeros(5) - with self.assertRaisesRegexp(AssertionError, - 'Erroneously materialized dataset'): + with self.assertRaisesRegex(AssertionError, + 'Erroneously materialized dataset'): self.validate_deferred_materialization( functools.partial(TestModelWithDataset, materialize_dataset=True), dataset=dataset) diff --git a/tensorflow_probability/python/bijectors/bijector_test.py b/tensorflow_probability/python/bijectors/bijector_test.py index fa93ed77f2..76c4cb5467 100644 --- a/tensorflow_probability/python/bijectors/bijector_test.py +++ b/tensorflow_probability/python/bijectors/bijector_test.py @@ -88,20 +88,20 @@ def __init__(self): self.assertAllEqual(shape, inverse_event_shape_) self.assertAllEqual(shape, bij.inverse_event_shape(shape)) - with self.assertRaisesRegexp(NotImplementedError, - 'inverse not implemented'): + with self.assertRaisesRegex(NotImplementedError, + 'inverse not implemented'): bij.inverse(0) - with self.assertRaisesRegexp(NotImplementedError, - 'forward not implemented'): + with self.assertRaisesRegex(NotImplementedError, + 'forward not implemented'): bij.forward(0) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( NotImplementedError, 'Cannot derive `inverse_log_det_jacobian`'): bij.inverse_log_det_jacobian(0, event_ndims=0) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( NotImplementedError, 'Cannot derive `forward_log_det_jacobian`'): bij.forward_log_det_jacobian(0, event_ndims=0) @@ -140,14 +140,14 @@ def _forward(self, x): b32 = _TypedIdentity(tf.float32) self.assertEqual(tf.float32, b32(0).dtype) self.assertEqual(tf.float32, b32(x32).dtype) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( error_clazz, 'Tensor conversion requested dtype'): b32.forward(x64) b64 = _TypedIdentity(tf.float64) self.assertEqual(tf.float64, b64(0).dtype) self.assertEqual(tf.float64, b64(x64).dtype) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( error_clazz, 'Tensor conversion requested dtype'): b64.forward(x32) @@ -583,20 +583,20 @@ def _forward_log_det_jacobian(self, x): class BijectorTestEventNdims(test_util.TestCase): def assertRaisesError(self, msg): - return self.assertRaisesRegexp(Exception, msg) + return self.assertRaisesRegex(Exception, msg) def testBijectorNonIntegerEventNdims(self): bij = ExpOnlyJacobian() - with self.assertRaisesRegexp(ValueError, 'Expected integer'): + with self.assertRaisesRegex(ValueError, 'Expected integer'): bij.forward_log_det_jacobian(1., event_ndims=1.5) - with self.assertRaisesRegexp(ValueError, 'Expected integer'): + with self.assertRaisesRegex(ValueError, 'Expected integer'): bij.inverse_log_det_jacobian(1., event_ndims=1.5) def testBijectorArrayEventNdims(self): bij = ExpOnlyJacobian() - with self.assertRaisesRegexp(ValueError, 'Expected scalar'): + with self.assertRaisesRegex(ValueError, 'Expected scalar'): bij.forward_log_det_jacobian(1., event_ndims=(1, 2)) - with self.assertRaisesRegexp(ValueError, 'Expected scalar'): + with self.assertRaisesRegex(ValueError, 'Expected scalar'): bij.inverse_log_det_jacobian(1., event_ndims=(1, 2)) def testBijectorDynamicEventNdims(self): @@ -1034,9 +1034,9 @@ def testInverseWithEventDimsOmitted(self): def testReduceEventNdimsForwardRaiseError(self): x = [[[1., 2.], [3., 4.]]] bij = ExpOnlyJacobian(forward_min_event_ndims=1) - with self.assertRaisesRegexp(ValueError, 'must be at least'): + with self.assertRaisesRegex(ValueError, 'must be at least'): bij.forward_log_det_jacobian(x, event_ndims=0) - with self.assertRaisesRegexp(ValueError, 'Input must have rank at least'): + with self.assertRaisesRegex(ValueError, 'Input must have rank at least'): bij.forward_log_det_jacobian(x, event_ndims=4) def testReduceEventNdimsInverse(self): @@ -1055,9 +1055,9 @@ def testReduceEventNdimsInverse(self): def testReduceEventNdimsInverseRaiseError(self): x = [[[1., 2.], [3., 4.]]] bij = ExpOnlyJacobian(forward_min_event_ndims=1) - with self.assertRaisesRegexp(ValueError, 'must be at least'): + with self.assertRaisesRegex(ValueError, 'must be at least'): bij.inverse_log_det_jacobian(x, event_ndims=0) - with self.assertRaisesRegexp(ValueError, 'Input must have rank at least'): + with self.assertRaisesRegex(ValueError, 'Input must have rank at least'): bij.inverse_log_det_jacobian(x, event_ndims=4) def testReduceEventNdimsForwardConstJacobian(self): diff --git a/tensorflow_probability/python/bijectors/blockwise_test.py b/tensorflow_probability/python/bijectors/blockwise_test.py index dfe6dde7c9..39d5c6f6d6 100644 --- a/tensorflow_probability/python/bijectors/blockwise_test.py +++ b/tensorflow_probability/python/bijectors/blockwise_test.py @@ -240,11 +240,11 @@ def testNameOneBijector(self): self.assertStartsWith(bijector.name, 'blockwise_of_exp') def testRaisesEmptyBijectors(self): - with self.assertRaisesRegexp(ValueError, '`bijectors` must not be empty'): + with self.assertRaisesRegex(ValueError, '`bijectors` must not be empty'): blockwise.Blockwise(bijectors=[]) def testRaisesBadBlocks(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, r'`block_sizes` must be `None`, or a vector of the same length as ' r'`bijectors`. Got a `Tensor` with shape \(2L?,\) and `bijectors` of ' diff --git a/tensorflow_probability/python/bijectors/chain_test.py b/tensorflow_probability/python/bijectors/chain_test.py index 7cb5af0b43..e68cef3ca4 100644 --- a/tensorflow_probability/python/bijectors/chain_test.py +++ b/tensorflow_probability/python/bijectors/chain_test.py @@ -272,7 +272,7 @@ def testMinEventNdimsWithPartiallyDependentJointMap(self): dependent_as_chain._parts_interact) def testInvalidChainNdimsRaisesError(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, "Differences between `event_ndims` and `min_event_ndims must be equal"): chain.Chain( diff --git a/tensorflow_probability/python/bijectors/correlation_cholesky_test.py b/tensorflow_probability/python/bijectors/correlation_cholesky_test.py index 8d43bbb9f0..36f44d92d8 100644 --- a/tensorflow_probability/python/bijectors/correlation_cholesky_test.py +++ b/tensorflow_probability/python/bijectors/correlation_cholesky_test.py @@ -149,14 +149,14 @@ def testShapeError(self): b = fill_triangular.FillTriangular(validate_args=True) x_shape_bad = tf.TensorShape([5, 4, 7]) - with self.assertRaisesRegexp(ValueError, 'is not a triangular number'): + with self.assertRaisesRegex(ValueError, 'is not a triangular number'): b.forward_event_shape(x_shape_bad) with self.assertRaisesOpError('is not a triangular number'): self.evaluate( b.forward_event_shape_tensor(tensorshape_util.as_list(x_shape_bad))) y_shape_bad = tf.TensorShape([5, 4, 4, 3]) - with self.assertRaisesRegexp(ValueError, 'Matrix must be square'): + with self.assertRaisesRegex(ValueError, 'Matrix must be square'): b.inverse_event_shape(y_shape_bad) with self.assertRaisesOpError('Matrix must be square'): self.evaluate( diff --git a/tensorflow_probability/python/bijectors/cumsum_test.py b/tensorflow_probability/python/bijectors/cumsum_test.py index 72c95ee7a4..aa927614b0 100644 --- a/tensorflow_probability/python/bijectors/cumsum_test.py +++ b/tensorflow_probability/python/bijectors/cumsum_test.py @@ -29,11 +29,11 @@ class _CumsumBijectorTest(test_util.TestCase): """Tests correctness of the cumsum bijector.""" def testInvalidAxis(self): - with self.assertRaisesRegexp(ValueError, - r'Argument `axis` must be negative.*'): + with self.assertRaisesRegex(ValueError, + r'Argument `axis` must be negative.*'): cumsum.Cumsum(axis=0, validate_args=True) - with self.assertRaisesRegexp(TypeError, - r'Argument `axis` is not an `int` type\.*'): + with self.assertRaisesRegex(TypeError, + r'Argument `axis` is not an `int` type\.*'): cumsum.Cumsum(axis=-1., validate_args=True) def testBijector(self): diff --git a/tensorflow_probability/python/bijectors/fill_triangular_test.py b/tensorflow_probability/python/bijectors/fill_triangular_test.py index 93198ee510..7458439217 100644 --- a/tensorflow_probability/python/bijectors/fill_triangular_test.py +++ b/tensorflow_probability/python/bijectors/fill_triangular_test.py @@ -80,14 +80,14 @@ def testShapeError(self): b = fill_triangular.FillTriangular(validate_args=True) x_shape_bad = tf.TensorShape([5, 4, 7]) - with self.assertRaisesRegexp(ValueError, 'is not a triangular number'): + with self.assertRaisesRegex(ValueError, 'is not a triangular number'): b.forward_event_shape(x_shape_bad) with self.assertRaisesOpError('is not a triangular number'): self.evaluate( b.forward_event_shape_tensor(tensorshape_util.as_list(x_shape_bad))) y_shape_bad = tf.TensorShape([5, 4, 3, 2]) - with self.assertRaisesRegexp(ValueError, 'Matrix must be square'): + with self.assertRaisesRegex(ValueError, 'Matrix must be square'): b.inverse_event_shape(y_shape_bad) with self.assertRaisesOpError('Matrix must be square'): self.evaluate( diff --git a/tensorflow_probability/python/bijectors/masked_autoregressive_test.py b/tensorflow_probability/python/bijectors/masked_autoregressive_test.py index 11e126fff6..cbae66d443 100644 --- a/tensorflow_probability/python/bijectors/masked_autoregressive_test.py +++ b/tensorflow_probability/python/bijectors/masked_autoregressive_test.py @@ -437,7 +437,7 @@ def testInvertMutuallyConsistent(self): rtol=0.03) def testVectorBijectorRaises(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, "Bijectors with `forward_min_event_ndims` > 0 are not supported"): @@ -450,7 +450,7 @@ def bijector_fn(*args, **kwargs): maf.forward([1., 2.]) def testRankChangingBijectorRaises(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, "Bijectors which alter `event_ndims` are not supported."): def bijector_fn(*args, **kwargs): @@ -931,7 +931,7 @@ def test_doc_string_images_case_2(self): class ConditionalTests(test_util.TestCase): def test_conditional_missing_event_shape(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, "`event_shape` must be provided when `conditional` is True"): @@ -939,7 +939,7 @@ def test_conditional_missing_event_shape(self): params=2, conditional=True, conditional_event_shape=[4]) def test_conditional_missing_conditional_shape(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, "`conditional_event_shape` must be provided when `conditional` is True" ): @@ -948,7 +948,7 @@ def test_conditional_missing_conditional_shape(self): params=2, conditional=True, event_shape=[4]) def test_conditional_incorrect_layers(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, "`conditional_input_layers` must be \"first_layers\" or \"all_layers\"" ): @@ -961,7 +961,7 @@ def test_conditional_incorrect_layers(self): conditional_input_layers="non-existent-option") def test_conditional_false_with_shape(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, "`conditional_event_shape` passed but `conditional` is set to False."): @@ -969,7 +969,7 @@ def test_conditional_false_with_shape(self): params=2, conditional_event_shape=[4]) def test_conditional_wrong_shape(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, "Parameter `conditional_event_shape` must describe a rank-1 shape"): @@ -980,7 +980,7 @@ def test_conditional_wrong_shape(self): conditional_event_shape=[10, 4]) def test_conditional_missing_tensor(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, "`conditional_input` must be passed as a named argument"): made = masked_autoregressive.AutoregressiveNetwork( diff --git a/tensorflow_probability/python/bijectors/permute_test.py b/tensorflow_probability/python/bijectors/permute_test.py index cce4e5b439..9101e0fcab 100644 --- a/tensorflow_probability/python/bijectors/permute_test.py +++ b/tensorflow_probability/python/bijectors/permute_test.py @@ -30,7 +30,7 @@ class PermuteBijectorTest(test_util.TestCase): """Tests correctness of the Permute bijector.""" def assertRaisesError(self, msg): - return self.assertRaisesRegexp(Exception, msg) + return self.assertRaisesRegex(Exception, msg) def setUp(self): self._rng = np.random.RandomState(42) @@ -101,7 +101,7 @@ def testPreservesShape(self): def testNonPermutationAssertion(self): message = 'must contain exactly one of each of' - with self.assertRaisesRegexp(Exception, message): + with self.assertRaisesRegex(Exception, message): permutation = np.int32([1, 0, 1]) bijector = permute.Permute(permutation=permutation, validate_args=True) x = np.random.randn(4, 2, 3) @@ -111,7 +111,7 @@ def testVariableNonPermutationAssertion(self): message = 'must contain exactly one of each of' permutation = tf.Variable(np.int32([1, 0, 1])) self.evaluate(permutation.initializer) - with self.assertRaisesRegexp(Exception, message): + with self.assertRaisesRegex(Exception, message): bijector = permute.Permute(permutation=permutation, validate_args=True) x = np.random.randn(4, 2, 3) _ = self.evaluate(bijector.forward(x)) @@ -121,14 +121,14 @@ def testModifiedVariableNonPermutationAssertion(self): permutation = tf.Variable(np.int32([1, 0, 2])) self.evaluate(permutation.initializer) bijector = permute.Permute(permutation=permutation, validate_args=True) - with self.assertRaisesRegexp(Exception, message): + with self.assertRaisesRegex(Exception, message): with tf.control_dependencies([permutation.assign([1, 0, 1])]): x = np.random.randn(4, 2, 3) _ = self.evaluate(bijector.forward(x)) def testPermutationTypeAssertion(self): message = 'should be `int`-like' - with self.assertRaisesRegexp(Exception, message): + with self.assertRaisesRegex(Exception, message): permutation = np.float32([2, 0, 1]) bijector = permute.Permute(permutation=permutation, validate_args=True) x = np.random.randn(4, 2, 3) diff --git a/tensorflow_probability/python/bijectors/power_test.py b/tensorflow_probability/python/bijectors/power_test.py index eed3fce303..9b761799da 100644 --- a/tensorflow_probability/python/bijectors/power_test.py +++ b/tensorflow_probability/python/bijectors/power_test.py @@ -107,7 +107,7 @@ def testPowerOddInteger(self): rtol=1e-7) def testZeroPowerRaisesError(self): - with self.assertRaisesRegexp(Exception, 'must be non-zero'): + with self.assertRaisesRegex(Exception, 'must be non-zero'): b = power_lib.Power(power=0., validate_args=True) b.forward(1.) diff --git a/tensorflow_probability/python/bijectors/real_nvp_test.py b/tensorflow_probability/python/bijectors/real_nvp_test.py index 43dce97222..90be664d51 100644 --- a/tensorflow_probability/python/bijectors/real_nvp_test.py +++ b/tensorflow_probability/python/bijectors/real_nvp_test.py @@ -251,7 +251,7 @@ def _real_nvp_kwargs(self): class RealNVPTestCommon(test_util.TestCase): def testMatrixBijectorRaises(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'Bijectors with `forward_min_event_ndims` > 1 are not supported'): @@ -263,7 +263,7 @@ def bijector_fn(*args, **kwargs): rnvp.forward([1., 2.]) def testRankChangingBijectorRaises(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'Bijectors which alter `event_ndims` are not supported.'): def bijector_fn(*args, **kwargs): @@ -275,13 +275,13 @@ def bijector_fn(*args, **kwargs): rnvp.forward([1., 2.]) def testNonIntegerNumMaskedRaises(self): - with self.assertRaisesRegexp(TypeError, '`num_masked` must be an integer'): + with self.assertRaisesRegex(TypeError, '`num_masked` must be an integer'): real_nvp.RealNVP( num_masked=0.5, shift_and_log_scale_fn=lambda x, _: (x, x)) def testNonFloatFractionMaskedRaises(self): - with self.assertRaisesRegexp(TypeError, - '`fraction_masked` must be a float'): + with self.assertRaisesRegex(TypeError, + '`fraction_masked` must be a float'): real_nvp.RealNVP( fraction_masked=1, shift_and_log_scale_fn=lambda x, _: (x, x)) @@ -292,7 +292,7 @@ def testNonFloatFractionMaskedRaises(self): ('UpperBoundary', 1.), ) def testBadFractionRaises(self, fraction_masked): - with self.assertRaisesRegexp(ValueError, '`fraction_masked` must be in'): + with self.assertRaisesRegex(ValueError, '`fraction_masked` must be in'): real_nvp.RealNVP( fraction_masked=fraction_masked, shift_and_log_scale_fn=lambda x, _: (x, x)) @@ -304,7 +304,7 @@ def testBadFractionRaises(self, fraction_masked): ('UpperBoundary', 1), ) def testBadNumMaskRaises(self, num_masked): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'Number of masked units {} must be smaller than the event size 1' .format(num_masked)): diff --git a/tensorflow_probability/python/bijectors/reshape_test.py b/tensorflow_probability/python/bijectors/reshape_test.py index 65ef0d4fb1..f00dd793bc 100644 --- a/tensorflow_probability/python/bijectors/reshape_test.py +++ b/tensorflow_probability/python/bijectors/reshape_test.py @@ -212,7 +212,7 @@ def build_shapes(self, shape_in, shape_out): return shape_in, shape_out def assertRaisesError(self, msg): - return self.assertRaisesRegexp(Exception, msg) + return self.assertRaisesRegex(Exception, msg) def testEventShape(self): shape_in_static = tf.TensorShape([2, 3]) @@ -348,7 +348,7 @@ def build_shapes(self, shape_in, shape_out): def assertRaisesError(self, msg): if tf.executing_eagerly(): - return self.assertRaisesRegexp(Exception, msg) + return self.assertRaisesRegex(Exception, msg) return self.assertRaisesOpError(msg) def testEventShape(self): @@ -405,12 +405,12 @@ def testUnknownShapeRank(self): unknown_shape = tf1.placeholder_with_default([2, 2], shape=None) known_shape = [2, 2] - with self.assertRaisesRegexp(NotImplementedError, - 'must be statically known.'): + with self.assertRaisesRegex(NotImplementedError, + 'must be statically known.'): reshape.Reshape(event_shape_out=unknown_shape) - with self.assertRaisesRegexp(NotImplementedError, - 'must be statically known.'): + with self.assertRaisesRegex(NotImplementedError, + 'must be statically known.'): reshape.Reshape(event_shape_out=known_shape, event_shape_in=unknown_shape) def testScalarInVectorOut(self): diff --git a/tensorflow_probability/python/bijectors/scale_matvec_diag_test.py b/tensorflow_probability/python/bijectors/scale_matvec_diag_test.py index fb6e7ae0b7..9f44878bd4 100644 --- a/tensorflow_probability/python/bijectors/scale_matvec_diag_test.py +++ b/tensorflow_probability/python/bijectors/scale_matvec_diag_test.py @@ -72,7 +72,7 @@ def testBatch(self, is_static): bijector.inverse_log_det_jacobian(x, event_ndims=1)) def testRaisesWhenSingular(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( Exception, 'Singular operator: Diagonal contained zero values'): bijector = scale_matvec_diag.ScaleMatvecDiag( diff --git a/tensorflow_probability/python/bijectors/scale_matvec_linear_operator_test.py b/tensorflow_probability/python/bijectors/scale_matvec_linear_operator_test.py index b03b0a6594..5d622ef1a5 100644 --- a/tensorflow_probability/python/bijectors/scale_matvec_linear_operator_test.py +++ b/tensorflow_probability/python/bijectors/scale_matvec_linear_operator_test.py @@ -167,12 +167,12 @@ def testOperatorBroadcast(self): # Broadcasting of event shape components with batched LinearOperators # raises. - with self.assertRaisesRegexp(ValueError, 'bijector parameters changes'): + with self.assertRaisesRegex(ValueError, 'bijector parameters changes'): self.evaluate(bijector.forward_log_det_jacobian(x, event_ndims=[2, 2])) # Broadcasting of event shape components with batched LinearOperators # raises for `ldj_reduce_ndims > batch_ndims`. - with self.assertRaisesRegexp(ValueError, 'bijector parameters changes'): + with self.assertRaisesRegex(ValueError, 'bijector parameters changes'): self.evaluate(bijector.forward_log_det_jacobian(x, event_ndims=[3, 3])) def testEventShapeBroadcast(self): @@ -192,7 +192,7 @@ def testEventShapeBroadcast(self): [y_.shape for y_ in bijector.inverse(x)]) # Broadcasting of inputs within `ldj_reduce_shape` raises. - with self.assertRaisesRegexp(ValueError, 'left of `min_event_ndims`'): + with self.assertRaisesRegex(ValueError, 'left of `min_event_ndims`'): self.evaluate(bijector.forward_log_det_jacobian(x, event_ndims=[2, 2])) def testAlignedEventDims(self): @@ -200,7 +200,7 @@ def testAlignedEventDims(self): op = self.build_operator() bijector = scale_matvec_linear_operator.ScaleMatvecLinearOperatorBlock( op, validate_args=True) - with self.assertRaisesRegexp(ValueError, 'equal for all elements'): + with self.assertRaisesRegex(ValueError, 'equal for all elements'): self.evaluate(bijector.forward_log_det_jacobian(x, event_ndims=[1, 2])) diff --git a/tensorflow_probability/python/bijectors/scale_matvec_tril_test.py b/tensorflow_probability/python/bijectors/scale_matvec_tril_test.py index 44448ea3ae..96f9e47557 100644 --- a/tensorflow_probability/python/bijectors/scale_matvec_tril_test.py +++ b/tensorflow_probability/python/bijectors/scale_matvec_tril_test.py @@ -54,7 +54,7 @@ def testBatch(self, is_static): bijector.inverse_log_det_jacobian(x, event_ndims=1)) def testRaisesWhenSingular(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( Exception, '.*Singular operator: Diagonal contained zero values.*'): bijector = scale_matvec_tril.ScaleMatvecTriL( diff --git a/tensorflow_probability/python/bijectors/split_test.py b/tensorflow_probability/python/bijectors/split_test.py index 23022ce62d..3cf2fd25d1 100644 --- a/tensorflow_probability/python/bijectors/split_test.py +++ b/tensorflow_probability/python/bijectors/split_test.py @@ -91,14 +91,14 @@ def testCompositeTensor(self): def testAssertRaisesNonVectorSplitSizes(self): split_sizes = self.build_input([[1, 2, 2]]) - with self.assertRaisesRegexp(ValueError, 'must be an integer or 1-D'): + with self.assertRaisesRegex(ValueError, 'must be an integer or 1-D'): split.Split(split_sizes, validate_args=True) def testAssertRaisesWrongNumberOfOutputs(self): split_sizes = self.build_input([5, 3, -1]) y = [np.random.rand(2, i) for i in [5, 3, 1, 2]] bijector = split.Split(split_sizes, validate_args=True) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, "don't have the same sequence length"): self.evaluate(bijector.inverse(y)) @@ -106,14 +106,14 @@ def testAssertRaisesNumSplitsNonDivisible(self): num_splits = 3 x = np.random.rand(4, 5, 6) bijector = split.Split(num_splits, axis=-2, validate_args=True) - with self.assertRaisesRegexp(ValueError, 'number of splits'): + with self.assertRaisesRegex(ValueError, 'number of splits'): self.evaluate(bijector.forward(x)) def testAssertRaisesWrongNumSplits(self): num_splits = 4 y = [np.random.rand(2, 3)] * 3 bijector = split.Split(num_splits, validate_args=True) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, "don't have the same sequence length"): self.evaluate(bijector.inverse(y)) @@ -165,7 +165,7 @@ def build_input(self, x): return tf.convert_to_tensor(x) def assertRaisesError(self, msg): - return self.assertRaisesRegexp(Exception, msg) + return self.assertRaisesRegex(Exception, msg) @parameterized.named_parameters( {'testcase_name': 'fully_determined_split_sizes', @@ -345,7 +345,7 @@ def testEventShape(self, num_or_size_splits, expected_split_sizes): def testAssertRaisesUnknownNumSplits(self): split_sizes = tf1.placeholder_with_default([-1, 2, 1], shape=[None]) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'must have a statically-known number of elements'): split.Split(num_or_size_splits=split_sizes, validate_args=True) diff --git a/tensorflow_probability/python/bijectors/transpose_test.py b/tensorflow_probability/python/bijectors/transpose_test.py index 0add6def8d..d8b1960089 100644 --- a/tensorflow_probability/python/bijectors/transpose_test.py +++ b/tensorflow_probability/python/bijectors/transpose_test.py @@ -110,7 +110,7 @@ def testTransposeFromEventNdim(self): def testInvalidPermException(self): msg = '`perm` must be a valid permutation vector.' if self.is_static or tf.executing_eagerly(): - with self.assertRaisesRegexp(ValueError, msg): + with self.assertRaisesRegex(ValueError, msg): bijector = transpose.Transpose(perm=[1, 2], validate_args=True) else: with self.assertRaisesOpError(msg): @@ -121,7 +121,7 @@ def testInvalidPermException(self): def testInvalidEventNdimsException(self): msg = '`rightmost_transposed_ndims` must be non-negative.' - with self.assertRaisesRegexp(ValueError, msg): + with self.assertRaisesRegex(ValueError, msg): transpose.Transpose(rightmost_transposed_ndims=-1, validate_args=True) def testTransformedDist(self): @@ -214,7 +214,7 @@ def testPartialStaticPermEventShapes(self): def testNonNegativeAssertion(self): message = '`rightmost_transposed_ndims` must be non-negative' - with self.assertRaisesRegexp(Exception, message): + with self.assertRaisesRegex(Exception, message): ndims = np.int32(-3) bijector = transpose.Transpose( rightmost_transposed_ndims=ndims, validate_args=True) @@ -223,7 +223,7 @@ def testNonNegativeAssertion(self): def testNonPermutationAssertion(self): message = '`perm` must be a valid permutation vector' - with self.assertRaisesRegexp(Exception, message): + with self.assertRaisesRegex(Exception, message): permutation = np.int32([1, 0, 1]) bijector = transpose.Transpose(perm=permutation, validate_args=True) x = np.random.randn(4, 2, 3) @@ -233,7 +233,7 @@ def testVariableNonPermutationAssertion(self): message = '`perm` must be a valid permutation vector' permutation = tf.Variable(np.int32([1, 0, 1])) self.evaluate(permutation.initializer) - with self.assertRaisesRegexp(Exception, message): + with self.assertRaisesRegex(Exception, message): bijector = transpose.Transpose(perm=permutation, validate_args=True) x = np.random.randn(4, 2, 3) _ = self.evaluate(bijector.forward(x)) @@ -243,7 +243,7 @@ def testModifiedVariableNonPermutationAssertion(self): permutation = tf.Variable(np.int32([1, 0, 2])) self.evaluate(permutation.initializer) bijector = transpose.Transpose(perm=permutation, validate_args=True) - with self.assertRaisesRegexp(Exception, message): + with self.assertRaisesRegex(Exception, message): with tf.control_dependencies([permutation.assign([1, 0, 1])]): x = np.random.randn(4, 2, 3) _ = self.evaluate(bijector.forward(x)) diff --git a/tensorflow_probability/python/distributions/autoregressive_test.py b/tensorflow_probability/python/distributions/autoregressive_test.py index 3e96b59e1c..891b9f6a13 100644 --- a/tensorflow_probability/python/distributions/autoregressive_test.py +++ b/tensorflow_probability/python/distributions/autoregressive_test.py @@ -211,8 +211,8 @@ def fn(sample=0.): return normal.Normal(loc=tf.zeros_like(sample), scale=1.) num_steps = [4, 4, 4] - with self.assertRaisesRegexp(Exception, - 'Argument `num_steps` must be a scalar'): + with self.assertRaisesRegex(Exception, + 'Argument `num_steps` must be a scalar'): ar = autoregressive.Autoregressive( fn, num_steps=num_steps, validate_args=True) self.evaluate(ar.sample(seed=test_util.test_seed())) @@ -222,8 +222,8 @@ def fn(sample=0.): ar = autoregressive.Autoregressive( fn, num_steps=num_steps, validate_args=True) self.evaluate(ar.sample(seed=test_util.test_seed())) - with self.assertRaisesRegexp(Exception, - 'Argument `num_steps` must be a scalar'): + with self.assertRaisesRegex(Exception, + 'Argument `num_steps` must be a scalar'): with tf.control_dependencies([num_steps.assign([17, 3])]): self.evaluate(ar.sample(seed=test_util.test_seed())) @@ -232,8 +232,8 @@ def fn(sample=0.): return normal.Normal(loc=tf.zeros_like(sample), scale=1.) num_steps = 0 - with self.assertRaisesRegexp(Exception, - 'Argument `num_steps` must be positive'): + with self.assertRaisesRegex(Exception, + 'Argument `num_steps` must be positive'): ar = autoregressive.Autoregressive( fn, num_steps=num_steps, validate_args=True) self.evaluate(ar.sample(seed=test_util.test_seed())) @@ -243,8 +243,8 @@ def fn(sample=0.): ar = autoregressive.Autoregressive( fn, num_steps=num_steps, validate_args=True) self.evaluate(ar.sample(seed=test_util.test_seed())) - with self.assertRaisesRegexp(Exception, - 'Argument `num_steps` must be positive'): + with self.assertRaisesRegex(Exception, + 'Argument `num_steps` must be positive'): with tf.control_dependencies([num_steps.assign(-9)]): self.evaluate(ar.sample(seed=test_util.test_seed())) diff --git a/tensorflow_probability/python/distributions/batch_broadcast_test.py b/tensorflow_probability/python/distributions/batch_broadcast_test.py index 92e6595f0b..7f0ef2fe45 100644 --- a/tensorflow_probability/python/distributions/batch_broadcast_test.py +++ b/tensorflow_probability/python/distributions/batch_broadcast_test.py @@ -260,7 +260,7 @@ def test_default_bijector(self, data): self.evaluate(tf.identity(obs)) def test_bcast_to_errors(self): - with self.assertRaisesRegexp(ValueError, 'is incompatible with'): + with self.assertRaisesRegex(ValueError, 'is incompatible with'): batch_broadcast.BatchBroadcast( normal.Normal(tf.range(3.), 0.), to_shape=[2, 1]) @@ -273,7 +273,7 @@ def test_bcast_to_errors(self): validate_args=True).log_prob(0.)) def test_bcast_with_errors(self): - with self.assertRaisesRegexp(ValueError, 'Incompatible shapes'): + with self.assertRaisesRegex(ValueError, 'Incompatible shapes'): batch_broadcast.BatchBroadcast( normal.Normal(tf.range(3.), 0.), with_shape=[2, 4]) @@ -287,10 +287,10 @@ def test_bcast_with_errors(self): validate_args=True).log_prob(0.)) def test_bcast_both_error(self): - with self.assertRaisesRegexp(ValueError, 'Exactly one of'): + with self.assertRaisesRegex(ValueError, 'Exactly one of'): batch_broadcast.BatchBroadcast(normal.Normal(0., 1.), [3], to_shape=[3]) - with self.assertRaisesRegexp(ValueError, 'Exactly one of'): + with self.assertRaisesRegex(ValueError, 'Exactly one of'): batch_broadcast.BatchBroadcast(normal.Normal(0., 1.)) diff --git a/tensorflow_probability/python/distributions/batch_reshape_test.py b/tensorflow_probability/python/distributions/batch_reshape_test.py index ec46ad240b..fb0b71bb93 100644 --- a/tensorflow_probability/python/distributions/batch_reshape_test.py +++ b/tensorflow_probability/python/distributions/batch_reshape_test.py @@ -467,7 +467,7 @@ def test_bad_reshape_size(self): scale_diag=scale_ph, validate_args=True) if self.is_static_shape or tf.executing_eagerly(): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, (r'`batch_shape` size \(6\) must match ' r'`distribution\.batch_shape` size \(2\)')): batch_reshape.BatchReshape( @@ -504,7 +504,7 @@ def test_non_positive_shape(self): scale_diag=scale_ph, validate_args=True) if self.is_static_shape or tf.executing_eagerly(): - with self.assertRaisesRegexp(ValueError, r'.*must be >=(-1| 0).*'): + with self.assertRaisesRegex(ValueError, r'.*must be >=(-1| 0).*'): batch_reshape.BatchReshape( distribution=mvn, batch_shape=new_batch_shape_ph, @@ -539,7 +539,7 @@ def test_non_vector_shape(self): scale_diag=scale_ph, validate_args=True) if self.is_static_shape: - with self.assertRaisesRegexp(ValueError, r'.*must be a vector.*'): + with self.assertRaisesRegex(ValueError, r'.*must be a vector.*'): batch_reshape.BatchReshape( distribution=mvn, batch_shape=new_batch_shape_ph, @@ -571,11 +571,11 @@ def test_broadcasting_explicitly_unsupported(self): x_114 = self.dtype([2, 12, 3, 23]).reshape(1, 1, 4) if self.is_static_shape or tf.executing_eagerly(): - with self.assertRaisesRegexp(NotImplementedError, - 'too few batch and event dims'): + with self.assertRaisesRegex(NotImplementedError, + 'too few batch and event dims'): poisson_141_reshaped.log_prob(x_4) - with self.assertRaisesRegexp(NotImplementedError, - 'unexpected batch and event shape'): + with self.assertRaisesRegex(NotImplementedError, + 'unexpected batch and event shape'): poisson_141_reshaped.log_prob(x_114) return diff --git a/tensorflow_probability/python/distributions/binomial_test.py b/tensorflow_probability/python/distributions/binomial_test.py index 3786a6d123..d05839adf2 100644 --- a/tensorflow_probability/python/distributions/binomial_test.py +++ b/tensorflow_probability/python/distributions/binomial_test.py @@ -37,7 +37,7 @@ def testAssertionsOneOfProbsAndLogits(self): ValueError, 'Construct `Binomial` with `probs` or `logits`'): self.evaluate(binomial_lib.Binomial(total_count=10)) - with self.assertRaisesRegexp(ValueError, 'but not both'): + with self.assertRaisesRegex(ValueError, 'but not both'): self.evaluate(binomial_lib.Binomial(total_count=10, probs=0.5, logits=0.)) def testInvalidProbabilities(self): diff --git a/tensorflow_probability/python/distributions/blockwise_test.py b/tensorflow_probability/python/distributions/blockwise_test.py index 0dec21b182..0bb5fd5a47 100644 --- a/tensorflow_probability/python/distributions/blockwise_test.py +++ b/tensorflow_probability/python/distributions/blockwise_test.py @@ -115,7 +115,7 @@ def model(): self.assertAllClose(x_, y_) def testVaryingBatchShapeErrorStatic(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'Distributions must have the same `batch_shape`'): blockwise.Blockwise( [ @@ -167,7 +167,7 @@ def testAssertValidSample(self): validate_args=True, ) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'must have at least one dimension'): self.evaluate(dist.prob(3.)) diff --git a/tensorflow_probability/python/distributions/categorical_test.py b/tensorflow_probability/python/distributions/categorical_test.py index 94bc37c6da..671881e848 100644 --- a/tensorflow_probability/python/distributions/categorical_test.py +++ b/tensorflow_probability/python/distributions/categorical_test.py @@ -654,7 +654,7 @@ def testAssertionsProbs(self): def testAssertionsLogits(self): x = deferred_tensor.TransformedVariable(0., identity.Identity(), shape=None) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'Argument `logits` must have rank at least 1.'): d = categorical.Categorical(logits=x, validate_args=True) self.evaluate([v.initializer for v in d.variables]) diff --git a/tensorflow_probability/python/distributions/cholesky_lkj_test.py b/tensorflow_probability/python/distributions/cholesky_lkj_test.py index 1ae4c1f03e..823bda1cae 100644 --- a/tensorflow_probability/python/distributions/cholesky_lkj_test.py +++ b/tensorflow_probability/python/distributions/cholesky_lkj_test.py @@ -153,7 +153,7 @@ def _get_transformed_sample_and_log_prob(lkj_exp_sample, lkj_exp_log_prob, def testDimensionGuard(self, dtype): testee_lkj = cholesky_lkj.CholeskyLKJ( dimension=3, concentration=dtype([1., 4.])) - with self.assertRaisesRegexp(ValueError, 'dimension mismatch'): + with self.assertRaisesRegex(ValueError, 'dimension mismatch'): testee_lkj.log_prob(tf.eye(4)) def testZeroDimension(self, dtype): diff --git a/tensorflow_probability/python/distributions/continuous_bernoulli_test.py b/tensorflow_probability/python/distributions/continuous_bernoulli_test.py index 6ffe512b04..50c62a5e9a 100644 --- a/tensorflow_probability/python/distributions/continuous_bernoulli_test.py +++ b/tensorflow_probability/python/distributions/continuous_bernoulli_test.py @@ -616,11 +616,11 @@ def halfway(x): ) if tf.executing_eagerly(): return - with self.assertRaisesRegexp( + with self.assertRaisesRegex( (ValueError, tf.errors.InvalidArgumentError), 'Index out of range.*input has only 4 dims'): check(make_slicer[19, tf.newaxis, 2, ..., :, 0, 4]) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( (ValueError, tf.errors.InvalidArgumentError), 'slice index.*out of bounds', ): diff --git a/tensorflow_probability/python/distributions/deterministic_test.py b/tensorflow_probability/python/distributions/deterministic_test.py index f455dea7fb..893ab43bc3 100644 --- a/tensorflow_probability/python/distributions/deterministic_test.py +++ b/tensorflow_probability/python/distributions/deterministic_test.py @@ -240,14 +240,14 @@ def testVariableAssertions(self): self.evaluate(dist.log_prob(1.)) self.evaluate(atol.assign(-1.)) - with self.assertRaisesRegexp((ValueError, tf.errors.InvalidArgumentError), - 'Condition x >= 0'): + with self.assertRaisesRegex((ValueError, tf.errors.InvalidArgumentError), + 'Condition x >= 0'): self.evaluate(dist.log_prob(1.)) self.evaluate(atol.assign(0.1)) self.evaluate(rtol.assign(-1.)) - with self.assertRaisesRegexp((ValueError, tf.errors.InvalidArgumentError), - 'Condition x >= 0'): + with self.assertRaisesRegex((ValueError, tf.errors.InvalidArgumentError), + 'Condition x >= 0'): self.evaluate(dist.log_prob(1.)) @@ -282,15 +282,15 @@ def testShapeUknown(self): def testInvalidTolRaises(self): loc = rng.rand(2, 3, 4).astype(np.float32) - with self.assertRaisesRegexp((ValueError, tf.errors.InvalidArgumentError), - 'Condition x >= 0'): + with self.assertRaisesRegex((ValueError, tf.errors.InvalidArgumentError), + 'Condition x >= 0'): dist = det.VectorDeterministic(loc, atol=-1, validate_args=True) self.evaluate(dist.prob(loc)) def testInvalidXRaises(self): loc = rng.rand(2, 3, 4).astype(np.float32) - with self.assertRaisesRegexp((ValueError, tf.errors.InvalidArgumentError), - 'rank at least 1'): + with self.assertRaisesRegex((ValueError, tf.errors.InvalidArgumentError), + 'rank at least 1'): dist = det.VectorDeterministic(loc, atol=1, validate_args=True) self.evaluate(dist.prob(0.)) @@ -438,14 +438,14 @@ def testVariableAssertions(self): self.evaluate(dist.log_prob([1.])) self.evaluate(atol.assign(-1.)) - with self.assertRaisesRegexp((ValueError, tf.errors.InvalidArgumentError), - 'Condition x >= 0'): + with self.assertRaisesRegex((ValueError, tf.errors.InvalidArgumentError), + 'Condition x >= 0'): self.evaluate(dist.log_prob([1.])) self.evaluate(atol.assign(0.1)) self.evaluate(rtol.assign(-1.)) - with self.assertRaisesRegexp((ValueError, tf.errors.InvalidArgumentError), - 'Condition x >= 0'): + with self.assertRaisesRegex((ValueError, tf.errors.InvalidArgumentError), + 'Condition x >= 0'): self.evaluate(dist.log_prob([1.])) @parameterized.named_parameters( diff --git a/tensorflow_probability/python/distributions/dirichlet_multinomial_test.py b/tensorflow_probability/python/distributions/dirichlet_multinomial_test.py index 5023ba4cac..a49869d267 100644 --- a/tensorflow_probability/python/distributions/dirichlet_multinomial_test.py +++ b/tensorflow_probability/python/distributions/dirichlet_multinomial_test.py @@ -481,7 +481,7 @@ def testAssertionCategoricalEventShape(self): total_count = tf.constant(10.0, dtype=tf.float16) too_many_classes = 2**11 + 1 concentration = tf.Variable(tf.ones(too_many_classes, tf.float16)) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'Number of classes exceeds `dtype` precision'): dm.DirichletMultinomial(total_count, concentration, validate_args=True) diff --git a/tensorflow_probability/python/distributions/dirichlet_test.py b/tensorflow_probability/python/distributions/dirichlet_test.py index bb96c2776e..a5696cc8fa 100644 --- a/tensorflow_probability/python/distributions/dirichlet_test.py +++ b/tensorflow_probability/python/distributions/dirichlet_test.py @@ -332,7 +332,7 @@ def testGradients(self): def testAssertions(self): x = deferred_tensor.TransformedVariable(0.3679, exp.Exp(), shape=None) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'Argument `concentration` must have rank at least 1.'): d = dirichlet.Dirichlet(concentration=x, validate_args=True) self.evaluate([v.initializer for v in d.variables]) diff --git a/tensorflow_probability/python/distributions/distribution_properties_test.py b/tensorflow_probability/python/distributions/distribution_properties_test.py index 7fe221bbd8..aedd30a3ca 100644 --- a/tensorflow_probability/python/distributions/distribution_properties_test.py +++ b/tensorflow_probability/python/distributions/distribution_properties_test.py @@ -677,7 +677,7 @@ def ok(name): # Check that all distributions still register as non-iterable despite # defining __getitem__. (Because __getitem__ magically makes an object # iterable for some reason.) - with self.assertRaisesRegexp(TypeError, 'not iterable'): + with self.assertRaisesRegex(TypeError, 'not iterable'): iter(dist) # Test slicing diff --git a/tensorflow_probability/python/distributions/distribution_test.py b/tensorflow_probability/python/distributions/distribution_test.py index 7c7c93bcef..1d03bb39c8 100644 --- a/tensorflow_probability/python/distributions/distribution_test.py +++ b/tensorflow_probability/python/distributions/distribution_test.py @@ -593,20 +593,20 @@ def __init__(self): allow_nan_stats=False) terrible_distribution = TerribleDistribution() - with self.assertRaisesRegexp( + with self.assertRaisesRegex( NotImplementedError, 'prob is not implemented'): terrible_distribution.prob(1.) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( NotImplementedError, 'log_prob is not implemented'): terrible_distribution.log_prob(1.) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( NotImplementedError, 'cdf is not implemented'): terrible_distribution.cdf(1.) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( NotImplementedError, 'log_cdf is not implemented'): terrible_distribution.log_cdf(1.) - with self.assertRaisesRegexp(NotImplementedError, - 'unnormalized_log_prob is not implemented'): + with self.assertRaisesRegex(NotImplementedError, + 'unnormalized_log_prob is not implemented'): terrible_distribution.unnormalized_log_prob(1.) def testUnnormalizedProbDerivation(self): @@ -647,7 +647,7 @@ def _log_prob(self, _): def testNotIterable(self): normal = normal_lib.Normal(loc=0., scale=1.) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( TypeError, '\'Normal\' object is not iterable' ): @@ -880,7 +880,7 @@ def testNotImplemented(self): for name in ['sample', 'log_prob', 'prob', 'log_cdf', 'cdf', 'log_survival_function', 'survival_function']: method = getattr(d, name) - with self.assertRaisesRegexp(ValueError, 'b1.*b2'): + with self.assertRaisesRegex(ValueError, 'b1.*b2'): if name == 'sample': method([], seed=test_util.test_seed(), arg1='b1', arg2='b2') else: @@ -928,12 +928,12 @@ def raise_only_conditional_fn(arg1, arg2): # pylint:disable=unused-argument for log_m, m in zip(hidden_logspace_methods, regular_methods): setattr(dist, log_m, raise_with_input_fn) method = getattr(dist, m) - with self.assertRaisesRegexp(ValueError, 'b1.*b2'): + with self.assertRaisesRegex(ValueError, 'b1.*b2'): method(1.0, arg1='b1', arg2='b2') setattr(dist, '_stddev', raise_only_conditional_fn) method = getattr(dist, 'variance') - with self.assertRaisesRegexp(ValueError, 'b1.*b2'): + with self.assertRaisesRegex(ValueError, 'b1.*b2'): method(arg1='b1', arg2='b2') def testDefaultMethodLogSpaceInvocations(self): @@ -953,12 +953,12 @@ def raise_only_conditional_fn(arg1, arg2): # pylint:disable=unused-argument for m, log_m in zip(hidden_methods, regular_logspace_methods): setattr(dist, m, raise_with_input_fn) method = getattr(dist, log_m) - with self.assertRaisesRegexp(ValueError, 'b1.*b2'): + with self.assertRaisesRegex(ValueError, 'b1.*b2'): method(1.0, arg1='b1', arg2='b2') setattr(dist, '_variance', raise_only_conditional_fn) method = getattr(dist, 'stddev') - with self.assertRaisesRegexp(ValueError, 'b1.*b2'): + with self.assertRaisesRegex(ValueError, 'b1.*b2'): method(arg1='b1', arg2='b2') diff --git a/tensorflow_probability/python/distributions/exponentially_modified_gaussian_test.py b/tensorflow_probability/python/distributions/exponentially_modified_gaussian_test.py index d63339bb8b..ede2c73e66 100644 --- a/tensorflow_probability/python/distributions/exponentially_modified_gaussian_test.py +++ b/tensorflow_probability/python/distributions/exponentially_modified_gaussian_test.py @@ -232,7 +232,7 @@ def testVariableScale(self): self.evaluate(d.mean()) def testIncompatibleArgShapes(self): - with self.assertRaisesRegexp(Exception, r'compatible shapes'): + with self.assertRaisesRegex(Exception, r'compatible shapes'): d = emg.ExponentiallyModifiedGaussian( loc=tf.zeros([2, 3], dtype=self.dtype), scale=tf.ones([4, 1], dtype=self.dtype), diff --git a/tensorflow_probability/python/distributions/finite_discrete_test.py b/tensorflow_probability/python/distributions/finite_discrete_test.py index fc64e84d0b..5faadf9352 100644 --- a/tensorflow_probability/python/distributions/finite_discrete_test.py +++ b/tensorflow_probability/python/distributions/finite_discrete_test.py @@ -413,7 +413,7 @@ class FiniteDiscreteFromVariableTest(test_util.TestCase): def testAssertionLastDimensionOfOutcomesAndLogits(self): x = tf.Variable([0., -1., -2., -3.]) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'Last dimension of outcomes and logits must be equal size.'): d = finite_discrete.FiniteDiscrete([1., 2., 4.], @@ -424,7 +424,7 @@ def testAssertionLastDimensionOfOutcomesAndLogits(self): def testAssertionLastDimensionOfOutcomesAndProbs(self): x = tf.Variable([0.1, 0.4, 0.3, 0.2]) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'Last dimension of outcomes and probs must be equal size.'): d = finite_discrete.FiniteDiscrete([1., 2., 4.], probs=x, @@ -434,7 +434,7 @@ def testAssertionLastDimensionOfOutcomesAndProbs(self): def testAssertionOutcomesRanks(self): x = tf.Variable([0.1, 0.4, 0.3, 0.2]) - with self.assertRaisesRegexp(ValueError, 'Rank of outcomes must be 1.'): + with self.assertRaisesRegex(ValueError, 'Rank of outcomes must be 1.'): d = finite_discrete.FiniteDiscrete([[1., 2., 3., 4.], [5., 6., 7., 8.]], probs=x, validate_args=True) @@ -443,7 +443,7 @@ def testAssertionOutcomesRanks(self): def testAssertionOutcomesSize(self): x = tf.Variable([]) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'Size of outcomes must be greater than 0.'): d = finite_discrete.FiniteDiscrete( tf.zeros([0], tf.float32), probs=x, validate_args=True) diff --git a/tensorflow_probability/python/distributions/generalized_normal_test.py b/tensorflow_probability/python/distributions/generalized_normal_test.py index 7248c31e7f..c760c9229b 100644 --- a/tensorflow_probability/python/distributions/generalized_normal_test.py +++ b/tensorflow_probability/python/distributions/generalized_normal_test.py @@ -449,7 +449,7 @@ def testIncompatibleArgShapesGraph(self): power = tf.Variable(tf.ones([2, 3], dtype=self.dtype), shape=tf.TensorShape(None), name='pow') self.evaluate(power.initializer) - with self.assertRaisesRegexp(Exception, r'compatible shapes'): + with self.assertRaisesRegex(Exception, r'compatible shapes'): d = generalized_normal.GeneralizedNormal( loc=tf.zeros([4, 1], dtype=self.dtype), scale=tf.ones([4, 1], dtype=self.dtype), diff --git a/tensorflow_probability/python/distributions/half_cauchy_test.py b/tensorflow_probability/python/distributions/half_cauchy_test.py index c1cbb894f5..ebdc4c1be5 100644 --- a/tensorflow_probability/python/distributions/half_cauchy_test.py +++ b/tensorflow_probability/python/distributions/half_cauchy_test.py @@ -278,7 +278,7 @@ def testHalfCauchyMean(self): scale = self._create_placeholder_with_default(1., name='scale') dist = half_cauchy.HalfCauchy( loc, scale, allow_nan_stats=False, validate_args=True) - with self.assertRaisesRegexp(ValueError, 'is undefined'): + with self.assertRaisesRegex(ValueError, 'is undefined'): self.evaluate(dist.mean()) dist = half_cauchy.HalfCauchy( @@ -292,7 +292,7 @@ def testHalfCauchyVariance(self): dist = half_cauchy.HalfCauchy( loc, scale, allow_nan_stats=False, validate_args=True) - with self.assertRaisesRegexp(ValueError, 'is undefined'): + with self.assertRaisesRegex(ValueError, 'is undefined'): self.evaluate(dist.variance()) dist = half_cauchy.HalfCauchy( @@ -306,7 +306,7 @@ def testHalfCauchyStddev(self): dist = half_cauchy.HalfCauchy( loc, scale, allow_nan_stats=False, validate_args=True) - with self.assertRaisesRegexp(ValueError, 'is undefined'): + with self.assertRaisesRegex(ValueError, 'is undefined'): self.evaluate(dist.stddev()) dist = half_cauchy.HalfCauchy( diff --git a/tensorflow_probability/python/distributions/half_normal_test.py b/tensorflow_probability/python/distributions/half_normal_test.py index b20b93021f..aaf7ae8ed0 100644 --- a/tensorflow_probability/python/distributions/half_normal_test.py +++ b/tensorflow_probability/python/distributions/half_normal_test.py @@ -41,7 +41,7 @@ def assertAllFinite(self, array): def assertRaisesError(self, msg): if tf.executing_eagerly(): - return self.assertRaisesRegexp(Exception, msg) + return self.assertRaisesRegex(Exception, msg) return self.assertRaisesOpError(msg) def _testParamShapes(self, sample_shape, expected): diff --git a/tensorflow_probability/python/distributions/half_student_t_test.py b/tensorflow_probability/python/distributions/half_student_t_test.py index ae64e9b928..9c327a8d5f 100644 --- a/tensorflow_probability/python/distributions/half_student_t_test.py +++ b/tensorflow_probability/python/distributions/half_student_t_test.py @@ -604,7 +604,7 @@ def testAssertParamsAreFloats(self): df = tf.Variable(14, dtype=tf.int32) loc = tf.Variable(0, dtype=tf.int32) scale = tf.Variable(1, dtype=tf.int32) - with self.assertRaisesRegexp(ValueError, 'Expected floating point'): + with self.assertRaisesRegex(ValueError, 'Expected floating point'): half_student_t.HalfStudentT( df=df, loc=loc, scale=scale, validate_args=True) diff --git a/tensorflow_probability/python/distributions/hidden_markov_model_test.py b/tensorflow_probability/python/distributions/hidden_markov_model_test.py index dad86d8058..11a96cbf1b 100644 --- a/tensorflow_probability/python/distributions/hidden_markov_model_test.py +++ b/tensorflow_probability/python/distributions/hidden_markov_model_test.py @@ -1782,7 +1782,7 @@ def test_integer_initial_state_assertion(self): num_steps = 2 message = 'is not over integers' - with self.assertRaisesRegexp(Exception, message): + with self.assertRaisesRegex(Exception, message): model = hidden_markov_model.HiddenMarkovModel( normal.Normal(loc=0.0, scale=1.0), categorical.Categorical(probs=transition_matrix), @@ -1798,7 +1798,7 @@ def test_integer_transition_state_assertion(self): num_steps = 2 message = 'is not over integers' - with self.assertRaisesRegexp(Exception, message): + with self.assertRaisesRegex(Exception, message): model = hidden_markov_model.HiddenMarkovModel( categorical.Categorical(probs=initial_prob), normal.Normal(loc=0.0, scale=1.0), @@ -1816,7 +1816,7 @@ def test_scalar_num_steps_assertion(self): num_steps = np.array([2, 3]) message = '`num_steps` must be a scalar' - with self.assertRaisesRegexp(Exception, message): + with self.assertRaisesRegex(Exception, message): model = hidden_markov_model.HiddenMarkovModel( categorical.Categorical(probs=initial_prob), categorical.Categorical(probs=transition_matrix), @@ -1834,7 +1834,7 @@ def test_variable_num_steps_assertion(self): num_steps = tf.Variable(np.array([2, 3])) message = '`num_steps` must be a scalar' - with self.assertRaisesRegexp(Exception, message): + with self.assertRaisesRegex(Exception, message): model = hidden_markov_model.HiddenMarkovModel( categorical.Categorical(probs=initial_prob), categorical.Categorical(probs=transition_matrix), @@ -1852,7 +1852,7 @@ def test_num_steps_greater1_assertion(self): num_steps = 0 message = '`num_steps` must be at least 1' - with self.assertRaisesRegexp(Exception, message): + with self.assertRaisesRegex(Exception, message): model = hidden_markov_model.HiddenMarkovModel( categorical.Categorical(probs=initial_prob), categorical.Categorical(probs=transition_matrix), @@ -1870,7 +1870,7 @@ def test_initial_scalar_assertion(self): num_steps = 2 message = 'must have scalar' - with self.assertRaisesRegexp(Exception, message): + with self.assertRaisesRegex(Exception, message): model = hidden_markov_model.HiddenMarkovModel( sample.Sample( categorical.Categorical(probs=initial_prob), sample_shape=2), @@ -1889,7 +1889,7 @@ def test_batch_agreement_assertion(self): num_steps = 1 message = 'must agree on' - with self.assertRaisesRegexp(Exception, message): + with self.assertRaisesRegex(Exception, message): model = hidden_markov_model.HiddenMarkovModel( categorical.Categorical(probs=initial_prob), categorical.Categorical(probs=transition_matrix), @@ -1911,7 +1911,7 @@ def test_variable_batch_agreement_assertion(self): num_steps = 1 message = 'must agree on' - with self.assertRaisesRegexp(Exception, message): + with self.assertRaisesRegex(Exception, message): model = hidden_markov_model.HiddenMarkovModel( categorical.Categorical(probs=initial_prob), categorical.Categorical(probs=transition_matrix), @@ -1943,7 +1943,7 @@ def test_modified_variable_batch_agreement_assertion(self): categorical.Categorical(probs=observation_probs), num_steps=num_steps, validate_args=True) - with self.assertRaisesRegexp(Exception, message): + with self.assertRaisesRegex(Exception, message): with tf.control_dependencies([ transition_matrix.assign(transition_matrix_data2)]): _ = self.evaluate(model.sample()) @@ -1959,7 +1959,7 @@ def test_non_scalar_transition_batch(self): num_steps = 4 - with self.assertRaisesRegexp(Exception, 'can\'t have scalar batches'): + with self.assertRaisesRegex(Exception, 'can\'t have scalar batches'): model = hidden_markov_model.HiddenMarkovModel( categorical.Categorical(probs=initial_prob), categorical.Categorical(probs=transition_matrix), @@ -1981,7 +1981,7 @@ def test_variable_non_scalar_transition_batch(self): num_steps = 4 - with self.assertRaisesRegexp(Exception, 'can\'t have scalar batches'): + with self.assertRaisesRegex(Exception, 'can\'t have scalar batches'): model = hidden_markov_model.HiddenMarkovModel( categorical.Categorical(probs=initial_prob), categorical.Categorical(probs=transition_matrix), @@ -2010,7 +2010,7 @@ def test_modified_variable_non_scalar_transition_batch(self): num_steps=num_steps, validate_args=True) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( Exception, 'have scalar batches'): with tf.control_dependencies([ @@ -2052,7 +2052,7 @@ def test_time_varying_transition_batch_size(self): num_steps = 5 - with self.assertRaisesRegexp(Exception, 'matches num_steps - 1.'): + with self.assertRaisesRegex(Exception, 'matches num_steps - 1.'): model = hidden_markov_model.HiddenMarkovModel( categorical.Categorical(probs=initial_prob), categorical.Categorical(probs=transition_matrix), @@ -2070,7 +2070,7 @@ def test_time_varying_observation_batch_size(self): num_steps = 6 - with self.assertRaisesRegexp(Exception, 'matches num_steps.'): + with self.assertRaisesRegex(Exception, 'matches num_steps.'): model = hidden_markov_model.HiddenMarkovModel( categorical.Categorical(probs=initial_prob), categorical.Categorical(probs=transition_matrix), diff --git a/tensorflow_probability/python/distributions/independent_test.py b/tensorflow_probability/python/distributions/independent_test.py index 22424bbcd4..fadf71c32c 100644 --- a/tensorflow_probability/python/distributions/independent_test.py +++ b/tensorflow_probability/python/distributions/independent_test.py @@ -46,7 +46,7 @@ class IndependentDistributionTest(test_util.TestCase): def assertRaises(self, error_class, msg): if tf.executing_eagerly(): - return self.assertRaisesRegexp(error_class, msg) + return self.assertRaisesRegex(error_class, msg) return self.assertRaisesOpError(msg) def testSampleAndLogProbUnivariate(self): @@ -180,7 +180,7 @@ def testKLRaises(self): reinterpreted_batch_ndims=0, validate_args=True) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'Event shapes do not match'): kullback_leibler.kl_divergence(ind1, ind2) @@ -195,7 +195,7 @@ def testKLRaises(self): reinterpreted_batch_ndims=0, validate_args=True) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( NotImplementedError, 'different event shapes'): kullback_leibler.kl_divergence(ind1, ind2) @@ -219,7 +219,7 @@ def testKlWithDynamicShapes(self): self.assertAllEqual((4, 5), kl.shape) with tf.control_dependencies([loc2.assign(np.zeros((4, 5, 3, 2)))]): - with self.assertRaisesRegexp(Exception, 'Event shapes do not match'): + with self.assertRaisesRegex(Exception, 'Event shapes do not match'): self.evaluate(dist1.kl_divergence(dist2)) def testKLScalarToMultivariate(self): @@ -387,8 +387,8 @@ def __init__(self, logits): self._parameters = {'logits': logits} d = IndepBern1d(tf.zeros([4, 5, 6])) - with self.assertRaisesRegexp(NotImplementedError, - 'does not support batch slicing'): + with self.assertRaisesRegex(NotImplementedError, + 'does not support batch slicing'): d[:3] # pylint: disable=pointless-statement class IndepBern1dSliceable(IndepBern1d): diff --git a/tensorflow_probability/python/distributions/johnson_su_test.py b/tensorflow_probability/python/distributions/johnson_su_test.py index b22aadf9ea..e126fd5fab 100644 --- a/tensorflow_probability/python/distributions/johnson_su_test.py +++ b/tensorflow_probability/python/distributions/johnson_su_test.py @@ -571,7 +571,7 @@ def testVariableScale(self): def testIncompatibleArgShapes(self): scale = tf1.placeholder_with_default(tf.ones([4, 1]), shape=None) - with self.assertRaisesRegexp(Exception, r'Incompatible shapes'): + with self.assertRaisesRegex(Exception, r'Incompatible shapes'): d = johnson_su.JohnsonSU( skewness=1., tailweight=2., diff --git a/tensorflow_probability/python/distributions/joint_distribution_auto_batched_test.py b/tensorflow_probability/python/distributions/joint_distribution_auto_batched_test.py index 50f42d5655..da6c826a41 100644 --- a/tensorflow_probability/python/distributions/joint_distribution_auto_batched_test.py +++ b/tensorflow_probability/python/distributions/joint_distribution_auto_batched_test.py @@ -288,7 +288,7 @@ def coroutine_auto(): # This model's broadcasting behavior is a footgun (it can break inference # routines and cause silently incorrect optimization); it should be # disallowed by `validate_args`. - with self.assertRaisesRegexp( + with self.assertRaisesRegex( Exception, ('Component batch shapes are inconsistent|' 'Broadcasting probably indicates an error in model specification')): diff --git a/tensorflow_probability/python/distributions/joint_distribution_coroutine_test.py b/tensorflow_probability/python/distributions/joint_distribution_coroutine_test.py index 68bdbd2a6f..93759cc814 100644 --- a/tensorflow_probability/python/distributions/joint_distribution_coroutine_test.py +++ b/tensorflow_probability/python/distributions/joint_distribution_coroutine_test.py @@ -436,7 +436,7 @@ def dist(): joint = jdc.JointDistributionCoroutine(dist, validate_args=True) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( Exception, 'must be wrapped in `Root`'): self.evaluate(joint.sample(2, seed=test_util.test_seed())) @@ -473,11 +473,11 @@ def _convert_ndarray_to_list(x): *value[:1], **dict(value_with_names[1:]))) self.assertAllEqual(lp_value_positional, lp_args_then_kwargs) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, r'Joint distribution expected values for [0-9] components'): d.log_prob(badvar=27.) - with self.assertRaisesRegexp(ValueError, 'unexpected keyword argument'): + with self.assertRaisesRegex(ValueError, 'unexpected keyword argument'): d.log_prob(*value, extra_arg=27.) def test_log_prob_with_manual_kwargs(self): @@ -495,7 +495,7 @@ def dist(): yield Root(normal.Normal(0., 1., name='a')) yield Root(normal.Normal(0., 1., name='a')) - with self.assertRaisesRegexp(ValueError, 'Duplicated distribution name: a'): + with self.assertRaisesRegex(ValueError, 'Duplicated distribution name: a'): dist.log_prob((1, 2)) @parameterized.named_parameters( @@ -532,7 +532,7 @@ def dist(): joint = jdc.JointDistributionCoroutine(dist, validate_args=True) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( Exception, 'are not consistent with `sample_shape`'): self.evaluate(joint.sample([3, 5], seed=test_util.test_seed())) @@ -551,7 +551,7 @@ def dist(): joint = jdc.JointDistributionCoroutine(dist, validate_args=True) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( Exception, 'are not consistent with `sample_shape`'): self.evaluate(joint.sample([3, 5], seed=test_util.test_seed())) @@ -1337,7 +1337,7 @@ def dist(): d = jdc.JointDistributionCoroutine(dist, validate_args=True) - with self.assertRaisesRegexp(TypeError, r'Expected int for argument'): + with self.assertRaisesRegex(TypeError, r'Expected int for argument'): d.sample(seed=samplers.zeros_seed()) def test_pinning(self): diff --git a/tensorflow_probability/python/distributions/joint_distribution_named_test.py b/tensorflow_probability/python/distributions/joint_distribution_named_test.py index e36d74e4ee..7297042708 100644 --- a/tensorflow_probability/python/distributions/joint_distribution_named_test.py +++ b/tensorflow_probability/python/distributions/joint_distribution_named_test.py @@ -308,9 +308,9 @@ def test_can_call_log_prob_with_kwargs(self): lp_kwargs = self.evaluate(d.log_prob(a=a, e=e, x=x)) self.assertAllClose(lp_value_positional, lp_kwargs) - with self.assertRaisesRegexp(ValueError, - 'Joint distribution with unordered variables ' - "can't take positional args"): + with self.assertRaisesRegex(ValueError, + 'Joint distribution with unordered variables ' + "can't take positional args"): lp_kwargs = d.log_prob(e, a, x) @parameterized.named_parameters( diff --git a/tensorflow_probability/python/distributions/joint_distribution_sequential_test.py b/tensorflow_probability/python/distributions/joint_distribution_sequential_test.py index 58fbc0c1bb..1ccc6c3a6c 100644 --- a/tensorflow_probability/python/distributions/joint_distribution_sequential_test.py +++ b/tensorflow_probability/python/distributions/joint_distribution_sequential_test.py @@ -430,11 +430,11 @@ def _convert_ndarray_to_list(x): *value[:1], **dict(value_with_names[1:]))) self.assertAllEqual(lp_value_positional, lp_args_then_kwargs) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, r'Joint distribution expected values for [0-9] components'): d.log_prob(badvar=27.) - with self.assertRaisesRegexp(ValueError, 'unexpected keyword argument'): + with self.assertRaisesRegex(ValueError, 'unexpected keyword argument'): d.log_prob(*value, extra_arg=27.) def test_can_call_prob_with_args_and_kwargs(self): @@ -925,7 +925,7 @@ def test_ignores_trivial_names(self): self.assertAllEqual(dist_names, ['z', 'y']) def test_inconsistent_names_raise_error(self): - with self.assertRaisesRegexp(ValueError, 'Inconsistent names'): + with self.assertRaisesRegex(ValueError, 'Inconsistent names'): # Refers to first variable as both `z` and `x`. jds._resolve_distribution_names( dist_fn_args=[None, ['z'], ['x', 'w']], @@ -933,7 +933,7 @@ def test_inconsistent_names_raise_error(self): leaf_name='y', instance_names=[None, None, None]) - with self.assertRaisesRegexp(ValueError, 'Inconsistent names'): + with self.assertRaisesRegex(ValueError, 'Inconsistent names'): # Refers to first variable as `x`, but it was explicitly named `z`. jds._resolve_distribution_names( dist_fn_args=[None, ['x']], diff --git a/tensorflow_probability/python/distributions/kullback_leibler_test.py b/tensorflow_probability/python/distributions/kullback_leibler_test.py index 337f353612..b2c6ab9c70 100644 --- a/tensorflow_probability/python/distributions/kullback_leibler_test.py +++ b/tensorflow_probability/python/distributions/kullback_leibler_test.py @@ -99,14 +99,14 @@ def testRegistrationFailures(self): class MyDist(normal.Normal): pass - with self.assertRaisesRegexp(TypeError, "must be callable"): + with self.assertRaisesRegex(TypeError, "must be callable"): kullback_leibler.RegisterKL(MyDist, MyDist)("blah") # First registration is OK kullback_leibler.RegisterKL(MyDist, MyDist)(lambda a, b: None) # Second registration fails - with self.assertRaisesRegexp(ValueError, "has already been registered"): + with self.assertRaisesRegex(ValueError, "has already been registered"): kullback_leibler.RegisterKL(MyDist, MyDist)(lambda a, b: None) def testExactRegistrationsAllMatch(self): @@ -185,8 +185,8 @@ def __init__(self): validate_args=True, allow_nan_stats=True) - with self.assertRaisesRegexp(NotImplementedError, - "No KL(distribution_a || distribution_b)"): + with self.assertRaisesRegex(NotImplementedError, + "No KL(distribution_a || distribution_b)"): kullback_leibler.kl_divergence(MyDist(), MyDist()) diff --git a/tensorflow_probability/python/distributions/laplace_test.py b/tensorflow_probability/python/distributions/laplace_test.py index 9a52b6c49c..ef8910abc7 100644 --- a/tensorflow_probability/python/distributions/laplace_test.py +++ b/tensorflow_probability/python/distributions/laplace_test.py @@ -368,7 +368,7 @@ def testAssertsPositiveScaleAfterMutation(self): def testAssertParamsAreFloats(self): loc = tf.convert_to_tensor(0, dtype=tf.int32) scale = tf.convert_to_tensor(1, dtype=tf.int32) - with self.assertRaisesRegexp(ValueError, 'Expected floating point'): + with self.assertRaisesRegex(ValueError, 'Expected floating point'): laplace.Laplace(loc=loc, scale=scale) diff --git a/tensorflow_probability/python/distributions/linear_gaussian_ssm_test.py b/tensorflow_probability/python/distributions/linear_gaussian_ssm_test.py index 62a1d8a34d..489379a8f1 100644 --- a/tensorflow_probability/python/distributions/linear_gaussian_ssm_test.py +++ b/tensorflow_probability/python/distributions/linear_gaussian_ssm_test.py @@ -943,8 +943,8 @@ def testMaskWhenTimeSeriesHasSampleShape(self): big_mask = np.random.randn(*np.concatenate( [[1, 2, 3], sample_shape, [num_timesteps]], axis=0)) > 0 - with self.assertRaisesRegexp(ValueError, - 'mask cannot have higher rank than x'): + with self.assertRaisesRegex(ValueError, + 'mask cannot have higher rank than x'): (log_likelihoods, filtered_means, filtered_covs, _, _, _, _) = model.forward_filter( x=observed_time_series, mask=big_mask) @@ -1628,7 +1628,7 @@ def testTooManyDimsThrowsError(self): class AugmentSampleShapeTestStatic(test_util.TestCase, _AugmentSampleShapeTest): def assertRaisesError(self, msg): - return self.assertRaisesRegexp(Exception, msg) + return self.assertRaisesRegex(Exception, msg) def build_inputs(self, full_batch_shape, partial_batch_shape): @@ -1648,7 +1648,7 @@ class AugmentSampleShapeTestDynamic(test_util.TestCase, def assertRaisesError(self, msg): if tf.executing_eagerly(): - return self.assertRaisesRegexp(Exception, msg) + return self.assertRaisesRegex(Exception, msg) else: return self.assertRaisesOpError(msg) diff --git a/tensorflow_probability/python/distributions/lkj_test.py b/tensorflow_probability/python/distributions/lkj_test.py index a596272c6c..85dbf4082d 100644 --- a/tensorflow_probability/python/distributions/lkj_test.py +++ b/tensorflow_probability/python/distributions/lkj_test.py @@ -315,7 +315,7 @@ def testSampleConsistentLogProbInterval5(self, dtype): def testDimensionGuard(self, dtype): testee_dist = lkj.LKJ( dimension=3, concentration=dtype([1., 4.]), validate_args=True) - with self.assertRaisesRegexp(ValueError, 'dimension mismatch'): + with self.assertRaisesRegex(ValueError, 'dimension mismatch'): testee_dist.log_prob(dtype(np.eye(4))) def testAssertValidCorrelationMatrix(self, dtype): diff --git a/tensorflow_probability/python/distributions/logistic_test.py b/tensorflow_probability/python/distributions/logistic_test.py index 8a84e0ddce..5b44ae35d3 100644 --- a/tensorflow_probability/python/distributions/logistic_test.py +++ b/tensorflow_probability/python/distributions/logistic_test.py @@ -210,7 +210,7 @@ def testAssertsPositiveScaleAfterMutation(self): def testAssertParamsAreFloats(self): loc = tf.convert_to_tensor(0, dtype=tf.int32) scale = tf.convert_to_tensor(1, dtype=tf.int32) - with self.assertRaisesRegexp(ValueError, "Expected floating point"): + with self.assertRaisesRegex(ValueError, "Expected floating point"): logistic.Logistic(loc=loc, scale=scale) diff --git a/tensorflow_probability/python/distributions/markov_chain_test.py b/tensorflow_probability/python/distributions/markov_chain_test.py index 21b0fd0441..4b8923a826 100644 --- a/tensorflow_probability/python/distributions/markov_chain_test.py +++ b/tensorflow_probability/python/distributions/markov_chain_test.py @@ -52,7 +52,7 @@ def test_error_when_transition_modifies_batch_shape(self): reinterpreted_batch_ndims=1), num_steps=5) x = self.evaluate(loses_batch_shape.sample([2], seed=test_util.test_seed())) - with self.assertRaisesRegexp(ValueError, 'batch shape is incorrect'): + with self.assertRaisesRegex(ValueError, 'batch shape is incorrect'): loses_batch_shape.log_prob(x) gains_batch_shape = markov_chain_lib.MarkovChain( @@ -61,7 +61,7 @@ def test_error_when_transition_modifies_batch_shape(self): transition_fn=lambda _, x: normal.Normal(loc=0., scale=tf.ones_like(x)), num_steps=5) x = self.evaluate(gains_batch_shape.sample([2], seed=test_util.test_seed())) - with self.assertRaisesRegexp(ValueError, 'batch shape is incorrect'): + with self.assertRaisesRegex(ValueError, 'batch shape is incorrect'): gains_batch_shape.log_prob(x) def test_log_prob_matches_linear_gaussian_ssm(self): diff --git a/tensorflow_probability/python/distributions/multinomial_test.py b/tensorflow_probability/python/distributions/multinomial_test.py index 8446476314..9f99510526 100644 --- a/tensorflow_probability/python/distributions/multinomial_test.py +++ b/tensorflow_probability/python/distributions/multinomial_test.py @@ -477,7 +477,7 @@ def testAssertionsProbs(self): def testAssertionsLogits(self): x = deferred_tensor.TransformedVariable(0., tfb.Identity(), shape=None) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'Argument `logits` must have rank at least 1.'): d = multinomial.Multinomial(total_count=2., logits=x, validate_args=True) self.evaluate([v.initializer for v in d.variables]) diff --git a/tensorflow_probability/python/distributions/multivariate_student_t_test.py b/tensorflow_probability/python/distributions/multivariate_student_t_test.py index 1c931a7b11..619b68a43a 100644 --- a/tensorflow_probability/python/distributions/multivariate_student_t_test.py +++ b/tensorflow_probability/python/distributions/multivariate_student_t_test.py @@ -114,8 +114,8 @@ def testNonPositiveDf(self): validate_args=True).sample(seed=test_util.test_seed())) def testBadScaleDType(self): - with self.assertRaisesRegexp(TypeError, - '`scale` must have floating-point dtype.'): + with self.assertRaisesRegex(TypeError, + '`scale` must have floating-point dtype.'): mvst.MultivariateStudentTLinearOperator( loc=[0.], df=1., @@ -123,8 +123,8 @@ def testBadScaleDType(self): num_rows=1, dtype=tf.int32, is_non_singular=True)) def testNotPositiveDefinite(self): - with self.assertRaisesRegexp(ValueError, - '`scale` must be non-singular.'): + with self.assertRaisesRegex(ValueError, + '`scale` must be non-singular.'): mvst.MultivariateStudentTLinearOperator( loc=self._input([0.]), df=self._input(1.), diff --git a/tensorflow_probability/python/distributions/mvn_diag_test.py b/tensorflow_probability/python/distributions/mvn_diag_test.py index d115a72abd..2f77ff8370 100644 --- a/tensorflow_probability/python/distributions/mvn_diag_test.py +++ b/tensorflow_probability/python/distributions/mvn_diag_test.py @@ -45,7 +45,7 @@ def setUp(self): def testScalarParams(self): mu = -1. diag = -5. - with self.assertRaisesRegexp(ValueError, 'at least 1 dimension'): + with self.assertRaisesRegex(ValueError, 'at least 1 dimension'): mvn_diag.MultivariateNormalDiag(mu, diag) def testVectorParams(self): diff --git a/tensorflow_probability/python/distributions/normal_test.py b/tensorflow_probability/python/distributions/normal_test.py index ca9a334eb8..1216a5634f 100644 --- a/tensorflow_probability/python/distributions/normal_test.py +++ b/tensorflow_probability/python/distributions/normal_test.py @@ -475,14 +475,14 @@ def testVariableScale(self): def testIncompatibleArgShapesGraph(self): if tf.executing_eagerly(): return scale = tf1.placeholder_with_default(tf.ones([4, 1]), shape=None) - with self.assertRaisesRegexp(tf.errors.OpError, r'Incompatible shapes'): + with self.assertRaisesRegex(tf.errors.OpError, r'Incompatible shapes'): d = normal.Normal(loc=tf.zeros([2, 3]), scale=scale, validate_args=True) self.evaluate(d.mean()) def testIncompatibleArgShapesEager(self): if not tf.executing_eagerly(): return scale = tf1.placeholder_with_default(tf.ones([4, 1]), shape=None) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, r'Arguments `loc` and `scale` must have compatible shapes.'): normal.Normal(loc=tf.zeros([2, 3]), scale=scale, validate_args=True) diff --git a/tensorflow_probability/python/distributions/onehot_categorical_test.py b/tensorflow_probability/python/distributions/onehot_categorical_test.py index d9d0b43b3c..a53929a6df 100644 --- a/tensorflow_probability/python/distributions/onehot_categorical_test.py +++ b/tensorflow_probability/python/distributions/onehot_categorical_test.py @@ -45,7 +45,7 @@ def setUp(self): def assertRaises(self, error_class, msg): if tf.executing_eagerly(): - return self.assertRaisesRegexp(error_class, msg) + return self.assertRaisesRegex(error_class, msg) return self.assertRaisesOpError(msg) def testP(self): @@ -342,7 +342,7 @@ def testAssertionsProbsAfterMutation(self): def testAssertionsLogits(self): x = deferred_tensor.TransformedVariable(0., tfb.Identity(), shape=None) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'Argument `logits` must have rank at least 1.'): d = oc.OneHotCategorical(logits=x, validate_args=True) self.evaluate([v.initializer for v in d.variables]) diff --git a/tensorflow_probability/python/distributions/ordered_logistic_test.py b/tensorflow_probability/python/distributions/ordered_logistic_test.py index 456431640a..5bdb90e878 100644 --- a/tensorflow_probability/python/distributions/ordered_logistic_test.py +++ b/tensorflow_probability/python/distributions/ordered_logistic_test.py @@ -202,7 +202,7 @@ def testLatentLogistic(self): self.assertAllClose(ordered_cdf, latent_cdf) def testUnorderedCutpointsFails(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'Argument `cutpoints` must be non-decreasing.'): dist = ol.OrderedLogistic( cutpoints=[1., 0.9], loc=0.0, validate_args=True) diff --git a/tensorflow_probability/python/distributions/plackett_luce_test.py b/tensorflow_probability/python/distributions/plackett_luce_test.py index ff8eb96053..5a38f3bf58 100644 --- a/tensorflow_probability/python/distributions/plackett_luce_test.py +++ b/tensorflow_probability/python/distributions/plackett_luce_test.py @@ -45,7 +45,7 @@ def setUp(self): def assertRaises(self, error_class, msg): if tf.executing_eagerly(): - return self.assertRaisesRegexp(error_class, msg) + return self.assertRaisesRegex(error_class, msg) return self.assertRaisesOpError(msg) def testScores(self): @@ -166,7 +166,7 @@ def testAssertionsProbsAfterMutation(self): def testAssertionsScores(self): x = deferred_tensor.TransformedVariable(0., tfb.Identity(), shape=None) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'Argument `scores` must have rank at least 1.'): d = plackett_luce.PlackettLuce(scores=x, validate_args=True) self.evaluate([v.initializer for v in d.variables]) diff --git a/tensorflow_probability/python/distributions/power_spherical_test.py b/tensorflow_probability/python/distributions/power_spherical_test.py index de9aae7f8c..3d8eea4774 100644 --- a/tensorflow_probability/python/distributions/power_spherical_test.py +++ b/tensorflow_probability/python/distributions/power_spherical_test.py @@ -427,7 +427,7 @@ def testAssertValidSample(self): self.evaluate(pspherical.prob([0.5, 0.5, 0.5])) msg = 'must have innermost dimension matching' - static_shape_assertion = self.assertRaisesRegexp(ValueError, msg) + static_shape_assertion = self.assertRaisesRegex(ValueError, msg) dynamic_shape_assertion = self.assertRaisesOpError(msg) x = [[1., 0., 0., 0.]] @@ -576,7 +576,7 @@ def testInvalidPowerSphericalvMFKl(self): mean_direction=mean_direction1, concentration=concentration) vmf = von_mises_fisher.VonMisesFisher( mean_direction=mean_direction2, concentration=concentration) - with self.assertRaisesRegexp(ValueError, 'Can not compute the KL'): + with self.assertRaisesRegex(ValueError, 'Can not compute the KL'): kullback_leibler.kl_divergence(ps, vmf) def VerifyPowerSphericalVonMisesFisherKL(self, dim): diff --git a/tensorflow_probability/python/distributions/relaxed_onehot_categorical_test.py b/tensorflow_probability/python/distributions/relaxed_onehot_categorical_test.py index 0b6605afee..6799e6dfbc 100644 --- a/tensorflow_probability/python/distributions/relaxed_onehot_categorical_test.py +++ b/tensorflow_probability/python/distributions/relaxed_onehot_categorical_test.py @@ -88,7 +88,7 @@ class RelaxedOneHotCategoricalTest(test_util.TestCase): def assertRaises(self, error_class, msg): if tf.executing_eagerly(): - return self.assertRaisesRegexp(error_class, msg) + return self.assertRaisesRegex(error_class, msg) return self.assertRaisesOpError(msg) def testProbs(self): @@ -330,7 +330,7 @@ def testAssertionsProbsAfterMutation(self): def testAssertionsLogits(self): logits = deferred_tensor.TransformedVariable(0., tfb.Identity(), shape=None) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'Argument `logits` must have rank at least 1.'): d = roc.ExpRelaxedOneHotCategorical( 0.7, logits=logits, validate_args=True) diff --git a/tensorflow_probability/python/distributions/sample_test.py b/tensorflow_probability/python/distributions/sample_test.py index 92c6923619..629fbc18a3 100644 --- a/tensorflow_probability/python/distributions/sample_test.py +++ b/tensorflow_probability/python/distributions/sample_test.py @@ -309,8 +309,8 @@ def test_broadcast_event(self): def test_misshapen_event(self): d = sample.Sample( normal.Normal(0, 1, validate_args=True), 4, validate_args=True) - with self.assertRaisesRegexp(ValueError, - r'Incompatible shapes for broadcasting'): + with self.assertRaisesRegex(ValueError, + r'Incompatible shapes for broadcasting'): self.evaluate(d.log_prob(tf.zeros([3]))) def test_bijector_shapes(self): diff --git a/tensorflow_probability/python/distributions/stopping_ratio_logistic_test.py b/tensorflow_probability/python/distributions/stopping_ratio_logistic_test.py index 0b51f4f0f6..f04bffa344 100644 --- a/tensorflow_probability/python/distributions/stopping_ratio_logistic_test.py +++ b/tensorflow_probability/python/distributions/stopping_ratio_logistic_test.py @@ -126,7 +126,7 @@ def testKLAgainstSampling(self): self.assertAllMeansClose(kl_samples, kl, axis=0, atol=2e-2) def testUnorderedCutpointsFails(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'Argument `cutpoints` must be non-decreasing.'): dist = srp.StoppingRatioLogistic( cutpoints=[1., 0.9], loc=0.0, validate_args=True) diff --git a/tensorflow_probability/python/distributions/von_mises_fisher_test.py b/tensorflow_probability/python/distributions/von_mises_fisher_test.py index fa8214481a..ff7b25eb96 100644 --- a/tensorflow_probability/python/distributions/von_mises_fisher_test.py +++ b/tensorflow_probability/python/distributions/von_mises_fisher_test.py @@ -432,7 +432,7 @@ def testAssertValidSample(self): self.evaluate(vmf.prob([0.5, 0.5, 0.5])) msg = 'must have innermost dimension matching' - static_shape_assertion = self.assertRaisesRegexp(ValueError, msg) + static_shape_assertion = self.assertRaisesRegex(ValueError, msg) dynamic_shape_assertion = self.assertRaisesOpError(msg) x = [[1., 0., 0., 0.]] diff --git a/tensorflow_probability/python/distributions/wishart_test.py b/tensorflow_probability/python/distributions/wishart_test.py index d32ed5700c..5f6dcde015 100644 --- a/tensorflow_probability/python/distributions/wishart_test.py +++ b/tensorflow_probability/python/distributions/wishart_test.py @@ -365,7 +365,7 @@ def testValidateArgs(self): error_type = ValueError # Check expensive, deferred assertions. - with self.assertRaisesRegexp(error_type, 'cannot be less than'): + with self.assertRaisesRegex(error_type, 'cannot be less than'): chol_w = wishart.WishartTriL( df=df_deferred, scale_tril=chol_scale_deferred, validate_args=True) self.evaluate(chol_w.log_prob(np.asarray(x, dtype=np.float32))) @@ -399,10 +399,10 @@ def testStaticAsserts(self): # Still has these assertions because they're resolveable at graph # construction: # df < rank - with self.assertRaisesRegexp(ValueError, 'cannot be less than'): + with self.assertRaisesRegex(ValueError, 'cannot be less than'): wishart.WishartTriL(df=2, scale_tril=chol_scale, validate_args=False) # non-float dtype - with self.assertRaisesRegexp(TypeError, '.'): + with self.assertRaisesRegex(TypeError, '.'): wishart.WishartTriL( df=4, scale_tril=np.asarray(chol_scale, dtype=np.int32), diff --git a/tensorflow_probability/python/experimental/distributions/joint_distribution_pinned_test.py b/tensorflow_probability/python/experimental/distributions/joint_distribution_pinned_test.py index 8769eec87a..c3c7101f77 100644 --- a/tensorflow_probability/python/experimental/distributions/joint_distribution_pinned_test.py +++ b/tensorflow_probability/python/experimental/distributions/joint_distribution_pinned_test.py @@ -143,9 +143,9 @@ def test_pinned_distribution_seq_args(self, jd_factory, sample_shape): if jd_factory is jd_named or jd_factory is jd_named_autobatched: # JDNamed does not support unnamed args unless model is ordered. for args in tuple_args: - with self.assertRaisesRegexp(ValueError, r'unordered'): + with self.assertRaisesRegex(ValueError, r'unordered'): jdp.JointDistributionPinned(underlying, args) - with self.assertRaisesRegexp(ValueError, r'unordered'): + with self.assertRaisesRegex(ValueError, r'unordered'): jdp.JointDistributionPinned(underlying, *args) tuple_args = () diff --git a/tensorflow_probability/python/experimental/distributions/multitask_gaussian_process_regression_model_test.py b/tensorflow_probability/python/experimental/distributions/multitask_gaussian_process_regression_model_test.py index 2680bf6038..2a7708afe8 100644 --- a/tensorflow_probability/python/experimental/distributions/multitask_gaussian_process_regression_model_test.py +++ b/tensorflow_probability/python/experimental/distributions/multitask_gaussian_process_regression_model_test.py @@ -118,7 +118,7 @@ def testValidateArgs(self): kernel = exponentiated_quadratic.ExponentiatedQuadratic() multi_task_kernel = multitask_kernel.Independent( num_tasks=3, base_kernel=kernel) - with self.assertRaisesRegexp(ValueError, 'match the number of tasks'): + with self.assertRaisesRegex(ValueError, 'match the number of tasks'): observations = np.linspace(-1., 1., 24).astype(np.float32) mtgprm_lib.MultiTaskGaussianProcessRegressionModel( multi_task_kernel, @@ -128,7 +128,7 @@ def testValidateArgs(self): observation_noise_variance=observation_noise_variance, validate_args=True) - with self.assertRaisesRegexp(ValueError, 'match the number of tasks'): + with self.assertRaisesRegex(ValueError, 'match the number of tasks'): observations = np.linspace(-1., 1., 32).reshape(8, 4).astype(np.float32) mtgprm_lib.MultiTaskGaussianProcessRegressionModel( multi_task_kernel, @@ -138,7 +138,7 @@ def testValidateArgs(self): observation_noise_variance=observation_noise_variance, validate_args=True) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'match the second to last dimension'): observations = np.linspace(-1., 1., 18).reshape(6, 3).astype(np.float32) mtgprm_lib.MultiTaskGaussianProcessRegressionModel( diff --git a/tensorflow_probability/python/experimental/distributions/multitask_gaussian_process_test.py b/tensorflow_probability/python/experimental/distributions/multitask_gaussian_process_test.py index 054aadfbc1..e5cf7f8585 100644 --- a/tensorflow_probability/python/experimental/distributions/multitask_gaussian_process_test.py +++ b/tensorflow_probability/python/experimental/distributions/multitask_gaussian_process_test.py @@ -402,15 +402,15 @@ def testLogProbValidateArgs(self): observation_noise_variance=observation_noise_variance, validate_args=True) - with self.assertRaisesRegexp(ValueError, 'match the number of tasks'): + with self.assertRaisesRegex(ValueError, 'match the number of tasks'): observations = np.linspace(-1., 1., 15).astype(np.float32) multitask_gp.log_prob(observations) - with self.assertRaisesRegexp(ValueError, 'match the number of tasks'): + with self.assertRaisesRegex(ValueError, 'match the number of tasks'): observations = np.linspace(-1., 1., 20).reshape(5, 4).astype(np.float32) multitask_gp.log_prob(observations) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'match the second to last dimension'): observations = np.linspace(-1., 1., 18).reshape(6, 3).astype(np.float32) multitask_gp.log_prob(observations) diff --git a/tensorflow_probability/python/experimental/nn/util/random_variable_test.py b/tensorflow_probability/python/experimental/nn/util/random_variable_test.py index 15a0e27099..e2a8ae11b9 100644 --- a/tensorflow_probability/python/experimental/nn/util/random_variable_test.py +++ b/tensorflow_probability/python/experimental/nn/util/random_variable_test.py @@ -72,7 +72,7 @@ def test_non_xla_graph_throws_exception(self): def run(): tf.convert_to_tensor(x) run() - with self.assertRaisesRegexp(ValueError, r'different graph context'): + with self.assertRaisesRegex(ValueError, r'different graph context'): tf.convert_to_tensor(x) def test_nested_graphs(self): @@ -88,7 +88,7 @@ def _inner(): y = _inner() z = tf.convert_to_tensor(x, name='outer') return y, z - with self.assertRaisesRegexp(ValueError, r'different graph context'): + with self.assertRaisesRegex(ValueError, r'different graph context'): run() diff --git a/tensorflow_probability/python/experimental/sequential/iterated_filter_test.py b/tensorflow_probability/python/experimental/sequential/iterated_filter_test.py index bd943abf06..4a035923bc 100644 --- a/tensorflow_probability/python/experimental/sequential/iterated_filter_test.py +++ b/tensorflow_probability/python/experimental/sequential/iterated_filter_test.py @@ -168,7 +168,7 @@ def parameterized_infection_observations(_, state, parameters): self.assertAllClose(parameter_estimates['recovery_rate'], 0.1, atol=0.05) def test_raises_error_on_inconsistent_prior_shapes(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'The specified prior does not generate consistent shapes'): iterated_filter_lib.IteratedFilter( parameter_prior=normal.Normal(0., 1.), diff --git a/tensorflow_probability/python/experimental/sts_gibbs/gibbs_sampler_test.py b/tensorflow_probability/python/experimental/sts_gibbs/gibbs_sampler_test.py index 18d5320eaf..bd414e7185 100644 --- a/tensorflow_probability/python/experimental/sts_gibbs/gibbs_sampler_test.py +++ b/tensorflow_probability/python/experimental/sts_gibbs/gibbs_sampler_test.py @@ -491,7 +491,7 @@ def do_sampling_again(observed_time_series, is_missing): def test_invalid_model_spec_raises_error(self): observed_time_series = tf.ones([2]) design_matrix = tf.eye(2) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'Weights prior must be a normal distribution'): gibbs_sampler.build_model_for_gibbs_fitting( observed_time_series, @@ -501,7 +501,7 @@ def test_invalid_model_spec_raises_error(self): observation_noise_variance_prior=inverse_gamma.InverseGamma( 0.01, 0.01)) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'Level variance prior must be an inverse gamma'): gibbs_sampler.build_model_for_gibbs_fitting( observed_time_series, @@ -511,7 +511,7 @@ def test_invalid_model_spec_raises_error(self): observation_noise_variance_prior=inverse_gamma.InverseGamma( 0.01, 0.01)) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'noise variance prior must be an inverse gamma'): gibbs_sampler.build_model_for_gibbs_fitting( observed_time_series, diff --git a/tensorflow_probability/python/experimental/vi/surrogate_posteriors_test.py b/tensorflow_probability/python/experimental/vi/surrogate_posteriors_test.py index bfe84b0bb2..59d2152a23 100644 --- a/tensorflow_probability/python/experimental/vi/surrogate_posteriors_test.py +++ b/tensorflow_probability/python/experimental/vi/surrogate_posteriors_test.py @@ -679,7 +679,7 @@ def test_mixed_dtypes_raises(self): 'b': logistic.Logistic(tf.zeros([], dtype=tf.float64), 1.) } operators = [tf.linalg.LinearOperatorDiag] * 2 - with self.assertRaisesRegexp(NotImplementedError, 'mixed dtype'): + with self.assertRaisesRegex(NotImplementedError, 'mixed dtype'): init_fn, apply_fn = ( surrogate_posteriors .build_affine_surrogate_posterior_from_base_distribution_stateless( diff --git a/tensorflow_probability/python/experimental/vi/util/trainable_linear_operators_test.py b/tensorflow_probability/python/experimental/vi/util/trainable_linear_operators_test.py index c90a37eaa2..92b831387c 100644 --- a/tensorflow_probability/python/experimental/vi/util/trainable_linear_operators_test.py +++ b/tensorflow_probability/python/experimental/vi/util/trainable_linear_operators_test.py @@ -200,7 +200,7 @@ def test_undefined_block_dims_raises(self): operators = (tf.linalg.LinearOperatorIdentity(2), tf.linalg.LinearOperatorDiag) - with self.assertRaisesRegexp(ValueError, '`block_dims` must be defined'): + with self.assertRaisesRegex(ValueError, '`block_dims` must be defined'): trainable_linear_operators.build_trainable_linear_operator_block( operators) diff --git a/tensorflow_probability/python/internal/backend/numpy/numpy_test.py b/tensorflow_probability/python/internal/backend/numpy/numpy_test.py index 13140fe36c..4aa17732d7 100644 --- a/tensorflow_probability/python/internal/backend/numpy/numpy_test.py +++ b/tensorflow_probability/python/internal/backend/numpy/numpy_test.py @@ -1808,7 +1808,7 @@ def test_foldl_struct_mismatched(self): np.arange(10).astype(np.int32).reshape(5, 2)) init = np.zeros_like(elems[1][0]) fn = lambda x, y_z: x + y_z[0] - y_z[1] - with self.assertRaisesRegexp(ValueError, r'.*size.*'): + with self.assertRaisesRegex(ValueError, r'.*size.*'): nptf.foldl(fn, elems, initializer=init) def test_foldl_struct_in_single_out(self): diff --git a/tensorflow_probability/python/internal/distribution_util_test.py b/tensorflow_probability/python/internal/distribution_util_test.py index 2c9fa25d50..a8bf3d196b 100644 --- a/tensorflow_probability/python/internal/distribution_util_test.py +++ b/tensorflow_probability/python/internal/distribution_util_test.py @@ -41,7 +41,7 @@ class ShapesFromLocAndScaleTest(test_util.TestCase): def test_static_loc_static_scale_non_matching_event_size_raises(self): loc = tf.zeros([2, 4]) diag = tf.ones([5, 1, 3]) - with self.assertRaisesRegexp(ValueError, 'could not be broadcast'): + with self.assertRaisesRegex(ValueError, 'could not be broadcast'): distribution_util.shapes_from_loc_and_scale( loc, tf.linalg.LinearOperatorDiag(diag)) @@ -735,7 +735,7 @@ def _np_rotate_transpose(self, x, shift): return np.transpose(x, np.roll(np.arange(len(x.shape)), shift)) def testRollStatic(self): - with self.assertRaisesRegexp(Exception, 'None'): + with self.assertRaisesRegex(Exception, 'None'): distribution_util.rotate_transpose(None, 1) for x in (np.ones(1), np.ones((2, 1)), np.ones((3, 2, 1))): for shift in np.arange(-5, 5): diff --git a/tensorflow_probability/python/internal/slicing_test.py b/tensorflow_probability/python/internal/slicing_test.py index 136a842641..0f9984fea1 100644 --- a/tensorflow_probability/python/internal/slicing_test.py +++ b/tensorflow_probability/python/internal/slicing_test.py @@ -183,7 +183,7 @@ def test_single_param_slice_broadcast_batch_leading_newaxis(self): self.assertAllEqual(expected, self.evaluate(sliced).shape) def test_single_param_multi_ellipsis(self): - with self.assertRaisesRegexp(ValueError, 'Found multiple `...`'): + with self.assertRaisesRegex(ValueError, 'Found multiple `...`'): slicing._slice_single_param( tf.zeros([7, 6, 5, 4, 3]), param_event_ndims=2, diff --git a/tensorflow_probability/python/internal/structural_tuple_test.py b/tensorflow_probability/python/internal/structural_tuple_test.py index bf8baa34c9..1fd536a106 100644 --- a/tensorflow_probability/python/internal/structural_tuple_test.py +++ b/tensorflow_probability/python/internal/structural_tuple_test.py @@ -117,58 +117,58 @@ def testMake(self): def testMakeTooManyValues(self): t = structural_tuple.structtuple(['a', 'b']) - with self.assertRaisesRegexp(TypeError, - 'Expected 2 arguments or fewer, got 3'): + with self.assertRaisesRegex(TypeError, + 'Expected 2 arguments or fewer, got 3'): t._make([1, 2, 3]) def testNonStrField(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( TypeError, 'Field names must be strings: 1 has type '): structural_tuple.structtuple([1]) def testInvalidIdentifierField(self): - with self.assertRaisesRegexp(ValueError, - 'Field names must be valid identifiers: 0'): + with self.assertRaisesRegex(ValueError, + 'Field names must be valid identifiers: 0'): structural_tuple.structtuple(['0']) def testKeywordField(self): - with self.assertRaisesRegexp(ValueError, - 'Field names cannot be a keyword: def'): + with self.assertRaisesRegex(ValueError, + 'Field names cannot be a keyword: def'): structural_tuple.structtuple(['def']) def testUnderscoreField(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'Field names cannot start with an underscore: _a'): structural_tuple.structtuple(['_a']) def testDuplicateField(self): - with self.assertRaisesRegexp(ValueError, - 'Encountered duplicate field name: a'): + with self.assertRaisesRegex(ValueError, + 'Encountered duplicate field name: a'): structural_tuple.structtuple(['a', 'a']) def testDuplicateConstructorArg(self): t = structural_tuple.structtuple(['a']) - with self.assertRaisesRegexp(TypeError, - 'Got multiple values for argument a'): + with self.assertRaisesRegex(TypeError, + 'Got multiple values for argument a'): t(1, a=2) def testUnexpectedConstructorArg(self): t = structural_tuple.structtuple(['a']) - with self.assertRaisesRegexp(TypeError, - 'Got an unexpected keyword argument b'): + with self.assertRaisesRegex(TypeError, + 'Got an unexpected keyword argument b'): t(b=2) def testMissingAttribute(self): t = structural_tuple.structtuple(['a']) a = t() - with self.assertRaisesRegexp(AttributeError, - 'StructTuple has no attribute b'): + with self.assertRaisesRegex(AttributeError, + 'StructTuple has no attribute b'): _ = a.b def testReplaceUnknownFields(self): t = structural_tuple.structtuple(['a']) a = t() - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, r'Got unexpected field names: \[\'b\', \'c\'\]'): a._replace(b=1, c=2) diff --git a/tensorflow_probability/python/internal/vectorization_util_test.py b/tensorflow_probability/python/internal/vectorization_util_test.py index 034700a05d..bf8784de5e 100644 --- a/tensorflow_probability/python/internal/vectorization_util_test.py +++ b/tensorflow_probability/python/internal/vectorization_util_test.py @@ -151,7 +151,7 @@ def test_passes_insufficient_rank_input_through_to_function(self): vectorized_matvec = vectorization_util.make_rank_polymorphic( tf.linalg.matvec, core_ndims=(2, 1)) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'Shape must be rank 2 but is rank 1'): vectorized_matvec(tf.zeros([5]), tf.zeros([2, 1, 5])) @@ -176,7 +176,7 @@ def test_unit_batch_dims_are_flattened(self): # Define `fn` to expect a vector input. fn = lambda x: tf.einsum('n->', x) # Verify that it won't accept a batch dimension. - with self.assertRaisesRegexp(Exception, 'rank'): + with self.assertRaisesRegex(Exception, 'rank'): fn(tf.zeros([1, 5])) polymorphic_fn = vectorization_util.make_rank_polymorphic(fn, diff --git a/tensorflow_probability/python/layers/internal/distribution_tensor_coercible_test.py b/tensorflow_probability/python/layers/internal/distribution_tensor_coercible_test.py index 85bf8380f7..feed13fb68 100644 --- a/tensorflow_probability/python/layers/internal/distribution_tensor_coercible_test.py +++ b/tensorflow_probability/python/layers/internal/distribution_tensor_coercible_test.py @@ -254,7 +254,7 @@ def _body(iter_, d): error_regex = r'Tensor.*must be from the same graph as Tensor.*' else: error_regex = 'Cannot use.*in a while loop' - with self.assertRaisesRegexp(ValueError, error_regex): + with self.assertRaisesRegex(ValueError, error_regex): _ = x + tf.constant(3.) return diff --git a/tensorflow_probability/python/math/integration_test.py b/tensorflow_probability/python/math/integration_test.py index 532d786331..416f0933a8 100644 --- a/tensorflow_probability/python/math/integration_test.py +++ b/tensorflow_probability/python/math/integration_test.py @@ -45,12 +45,12 @@ def test_simple_use_with_dx_arg(self): self.assertAllClose(integral, 5.0) def test_provide_multiple_axes_raises(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'Only permitted to specify one axis'): integration.trapz(y=tf.ones((2, 3)), axis=[0, 1]) def test_non_scalar_dx_raises(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'Expected dx to be a scalar'): integration.trapz(y=tf.ones((2, 3)), dx=[0.1, 0.2]) diff --git a/tensorflow_probability/python/math/interpolation_test.py b/tensorflow_probability/python/math/interpolation_test.py index 9255cc83e6..1290b10965 100644 --- a/tensorflow_probability/python/math/interpolation_test.py +++ b/tensorflow_probability/python/math/interpolation_test.py @@ -959,7 +959,7 @@ def batch_interp_regular_nd_grid_fn(self): return interpolation.batch_interp_regular_nd_grid def test_axis_set_too_large_raises(self): - with self.assertRaisesRegexp(ValueError, 'Since dims'): + with self.assertRaisesRegex(ValueError, 'Since dims'): interpolation.batch_interp_regular_nd_grid( x=[[1.]], x_ref_min=[0.], x_ref_max=[1.], y_ref=[0., 1.], axis=3) @@ -1002,12 +1002,12 @@ def regular_to_rectilinear_interp(x, return regular_to_rectilinear_interp def test_axis_set_too_large_raises(self): - with self.assertRaisesRegexp(ValueError, 'Since dims'): + with self.assertRaisesRegex(ValueError, 'Since dims'): interpolation.batch_interp_rectilinear_nd_grid( x=[[1.]], x_grid_points=([0, 1, 2.],), y_ref=[1., 2., 3.], axis=3) def test_x_grid_points_and_y_ref_must_have_same_n_points_or_raises(self): - with self.assertRaisesRegexp(ValueError, 'the number of points'): + with self.assertRaisesRegex(ValueError, 'the number of points'): interpolation.batch_interp_rectilinear_nd_grid( x=[[0.5]], x_grid_points=([0, 1, 2.],), y_ref=[1., 2.], axis=0) diff --git a/tensorflow_probability/python/math/ode/ode_test.py b/tensorflow_probability/python/math/ode/ode_test.py index 650c9ce034..cc4cccc020 100644 --- a/tensorflow_probability/python/math/ode/ode_test.py +++ b/tensorflow_probability/python/math/ode/ode_test.py @@ -664,7 +664,7 @@ def test_bad_initial_state_dtype(self, solver): ode_fn = lambda time, state: -state initial_time = 0. initial_state = np.int32(1) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( TypeError, ('`initial_state` must have a floating point or complex ' 'floating point dtype')): solver(validate_args=True).solve( diff --git a/tensorflow_probability/python/math/scan_associative_test.py b/tensorflow_probability/python/math/scan_associative_test.py index 6ff54b46b2..46fddca51a 100644 --- a/tensorflow_probability/python/math/scan_associative_test.py +++ b/tensorflow_probability/python/math/scan_associative_test.py @@ -174,7 +174,7 @@ def test_inconsistent_lengths_raise_error(self): def extended_add(a, b): return (a[0] + b[0], a[1] + b[1]) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( Exception, 'Inputs must have the same size along the given axis'): self.evaluate( scan_associative( @@ -202,7 +202,7 @@ def test_min_disallowed_size(self): elems = self.evaluate( uniform.Uniform(-1., 1.).sample([512], seed=test_util.test_seed())) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( Exception, 'Input `Tensor`s must have dimension less than'): self.evaluate( scan_associative( diff --git a/tensorflow_probability/python/mcmc/diagnostic_test.py b/tensorflow_probability/python/mcmc/diagnostic_test.py index 07497bb8cd..4fff448786 100644 --- a/tensorflow_probability/python/mcmc/diagnostic_test.py +++ b/tensorflow_probability/python/mcmc/diagnostic_test.py @@ -372,7 +372,7 @@ def testCrossChainEssNotEnoughChains(self): if not self.use_static_shape: cross_chain_dims = tf1.placeholder_with_default( cross_chain_dims, shape=[]) - with self.assertRaisesRegexp(Exception, 'there must be > 1 chain'): + with self.assertRaisesRegex(Exception, 'there must be > 1 chain'): self.evaluate( diagnostic.effective_sample_size( x, cross_chain_dims=cross_chain_dims, validate_args=True)) @@ -629,10 +629,10 @@ def use_static_shape(self): return True def assertRaisesError(self, msg): - return self.assertRaisesRegexp(Exception, msg) + return self.assertRaisesRegex(Exception, msg) def testIndependentNdimsLessThanOneRaises(self): - with self.assertRaisesRegexp(ValueError, 'independent_chain_ndims'): + with self.assertRaisesRegex(ValueError, 'independent_chain_ndims'): diagnostic.potential_scale_reduction( np.random.rand(2, 3, 4), independent_chain_ndims=0) @@ -647,7 +647,7 @@ def use_static_shape(self): def assertRaisesError(self, msg): if tf.executing_eagerly(): - return self.assertRaisesRegexp(Exception, msg) + return self.assertRaisesRegex(Exception, msg) return self.assertRaisesOpError(msg) diff --git a/tensorflow_probability/python/mcmc/internal/util_test.py b/tensorflow_probability/python/mcmc/internal/util_test.py index 380410e488..c93fb4e174 100644 --- a/tensorflow_probability/python/mcmc/internal/util_test.py +++ b/tensorflow_probability/python/mcmc/internal/util_test.py @@ -214,11 +214,11 @@ def fn(x, y): for i, arg in enumerate(fn_args) ] if tf.executing_eagerly(): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'Encountered `None`.*\n.*fn_arg_list.*\n.*None'): util.maybe_call_fn_and_grads(fn, fn_args) else: - with self.assertRaisesRegexp( + with self.assertRaisesRegex( ValueError, 'Encountered `None`.*\n.*fn_arg_list.*arg1.*\n.*None'): util.maybe_call_fn_and_grads(fn, fn_args) diff --git a/tensorflow_probability/python/mcmc/replica_exchange_mc_test.py b/tensorflow_probability/python/mcmc/replica_exchange_mc_test.py index 6a30eb8322..6d5769ef22 100644 --- a/tensorflow_probability/python/mcmc/replica_exchange_mc_test.py +++ b/tensorflow_probability/python/mcmc/replica_exchange_mc_test.py @@ -295,7 +295,7 @@ def setUp(self): def assertRaisesError(self, msg): if tf.executing_eagerly(): - return self.assertRaisesRegexp(Exception, msg) + return self.assertRaisesRegex(Exception, msg) return self.assertRaisesOpError(msg) @parameterized.named_parameters([ diff --git a/tensorflow_probability/python/monte_carlo/expectation_test.py b/tensorflow_probability/python/monte_carlo/expectation_test.py index fd911c7e81..3e6d2c6e0c 100644 --- a/tensorflow_probability/python/monte_carlo/expectation_test.py +++ b/tensorflow_probability/python/monte_carlo/expectation_test.py @@ -36,7 +36,7 @@ def test_raises_if_both_z_and_n_are_none(self): z = None n = None seed = test_util.test_seed() - with self.assertRaisesRegexp(ValueError, 'exactly one'): + with self.assertRaisesRegex(ValueError, 'exactly one'): _get_samples(dist, z, n, seed) def test_raises_if_both_z_and_n_are_not_none(self): @@ -44,7 +44,7 @@ def test_raises_if_both_z_and_n_are_not_none(self): z = dist.sample(seed=test_util.test_seed()) n = 1 seed = test_util.test_seed() - with self.assertRaisesRegexp(ValueError, 'exactly one'): + with self.assertRaisesRegex(ValueError, 'exactly one'): _get_samples(dist, z, n, seed) def test_returns_n_samples_if_n_provided(self): diff --git a/tensorflow_probability/python/optimizer/convergence_criteria/loss_not_decreasing_test.py b/tensorflow_probability/python/optimizer/convergence_criteria/loss_not_decreasing_test.py index 20486bfe5d..4d9a5446dc 100644 --- a/tensorflow_probability/python/optimizer/convergence_criteria/loss_not_decreasing_test.py +++ b/tensorflow_probability/python/optimizer/convergence_criteria/loss_not_decreasing_test.py @@ -37,7 +37,7 @@ def test_follows_tolerances(self, expected_num_steps, pass_inputs_as_tensors): - with self.assertRaisesRegexp(ValueError, 'Must specify at least one of'): + with self.assertRaisesRegex(ValueError, 'Must specify at least one of'): loss_not_decreasing.LossNotDecreasing() window_size = 2 diff --git a/tensorflow_probability/python/stats/sample_stats_test.py b/tensorflow_probability/python/stats/sample_stats_test.py index 235e32a014..b0e5797044 100644 --- a/tensorflow_probability/python/stats/sample_stats_test.py +++ b/tensorflow_probability/python/stats/sample_stats_test.py @@ -396,7 +396,7 @@ def test_non_contiguous_event_axis_raises(self): x = rng.randn(100, 3, 2) y = x + 0.1 * rng.randn(100, 3, 2) - with self.assertRaisesRegexp(ValueError, 'must be contiguous'): + with self.assertRaisesRegex(ValueError, 'must be contiguous'): sample_stats.covariance(x, y, sample_axis=1, event_axis=[0, 2]) def test_overlapping_axis_raises(self): @@ -405,7 +405,7 @@ def test_overlapping_axis_raises(self): x = rng.randn(100, 3, 2) y = x + 0.1 * rng.randn(100, 3, 2) - with self.assertRaisesRegexp(ValueError, 'overlapped'): + with self.assertRaisesRegex(ValueError, 'overlapped'): sample_stats.covariance(x, y, sample_axis=[0, 1], event_axis=[1, 2]) def test_batch_vector_shape_dtype_ok(self): @@ -701,7 +701,7 @@ def test_mathematical_correctness_categorical(self): def test_bad_axis_static(self): logits = tf.random.normal([10, 3, 4], seed=test_util.test_seed()) - with self.assertRaisesRegexp(ValueError, r'.*must be distinct.'): + with self.assertRaisesRegex(ValueError, r'.*must be distinct.'): sample_stats.log_average_probs( logits, sample_axis=[0, 1, 2], event_axis=-1, validate_args=True) diff --git a/tensorflow_probability/python/sts/components/sum_test.py b/tensorflow_probability/python/sts/components/sum_test.py index 4e03456e27..41d5f26ca6 100644 --- a/tensorflow_probability/python/sts/components/sum_test.py +++ b/tensorflow_probability/python/sts/components/sum_test.py @@ -320,7 +320,7 @@ def test_mismatched_dtype_error(self): ssm1 = self._dummy_model(dtype=self.dtype) ssm2 = self._dummy_model(dtype=np.float16) - with self.assertRaisesRegexp(Exception, 'dtype'): + with self.assertRaisesRegex(Exception, 'dtype'): _ = AdditiveStateSpaceModel(component_ssms=[ssm1, ssm2]) @parameterized.named_parameters(