Skip to content

Commit c50d92f

Browse files
cleanup of deprecated test methods
PiperOrigin-RevId: 721043234
1 parent 695c340 commit c50d92f

File tree

5 files changed

+42
-40
lines changed

5 files changed

+42
-40
lines changed

tensorflow_model_optimization/python/core/internal/tensor_encoding/stages/research/kashin_test.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,49 +204,49 @@ def test_unknown_shape_raises(self):
204204
x = test_utils.get_tensor_with_random_shape()
205205
stage = self.default_encoding_stage()
206206
params, _ = stage.get_params()
207-
with self.assertRaisesRegexp(ValueError, 'fully known'):
207+
with self.assertRaisesRegex(ValueError, 'fully known'):
208208
stage.encode(x, params)
209209

210210
@parameterized.parameters([((1, 1, 5),), ((1, 1, 1, 5),)])
211211
def test_more_than_two_ndims_raises(self, dims):
212212
x = tf.random.normal(dims)
213213
stage = self.default_encoding_stage()
214214
params, _ = stage.get_params()
215-
with self.assertRaisesRegexp(ValueError, 'must be 1 or 2.'):
215+
with self.assertRaisesRegex(ValueError, 'must be 1 or 2.'):
216216
stage.encode(x, params)
217217

218218
@parameterized.parameters([0.0, 1.0, -1.0, 2.5])
219219
def test_eta_out_of_bounds_raises(self, eta):
220-
with self.assertRaisesRegexp(ValueError, 'between 0 and 1'):
220+
with self.assertRaisesRegex(ValueError, 'between 0 and 1'):
221221
kashin.KashinHadamardEncodingStage(eta=eta)
222222

223223
@parameterized.parameters([0.0, -1.0])
224224
def test_delta_small_raises(self, delta):
225-
with self.assertRaisesRegexp(ValueError, 'greater than 0'):
225+
with self.assertRaisesRegex(ValueError, 'greater than 0'):
226226
kashin.KashinHadamardEncodingStage(delta=delta)
227227

228228
@parameterized.parameters([0, -1, -10])
229229
def test_num_iters_small_raises(self, num_iters):
230-
with self.assertRaisesRegexp(ValueError, 'positive'):
230+
with self.assertRaisesRegex(ValueError, 'positive'):
231231
kashin.KashinHadamardEncodingStage(num_iters=num_iters)
232232

233233
def test_num_iters_tensor_raises(self):
234-
with self.assertRaisesRegexp(ValueError, 'num_iters'):
234+
with self.assertRaisesRegex(ValueError, 'num_iters'):
235235
kashin.KashinHadamardEncodingStage(
236236
num_iters=tf.constant(2, dtype=tf.int32))
237237

238238
def test_last_iter_clip_tensor_raises(self):
239-
with self.assertRaisesRegexp(ValueError, 'last_iter_clip'):
239+
with self.assertRaisesRegex(ValueError, 'last_iter_clip'):
240240
kashin.KashinHadamardEncodingStage(
241241
last_iter_clip=tf.constant(True, dtype=tf.bool))
242242

243243
@parameterized.parameters([0, 1, 0.0, 1.0])
244244
def test_last_iter_clip_not_bool_raises(self, last_iter_clip):
245-
with self.assertRaisesRegexp(ValueError, 'last_iter_clip must be a bool'):
245+
with self.assertRaisesRegex(ValueError, 'last_iter_clip must be a bool'):
246246
kashin.KashinHadamardEncodingStage(last_iter_clip=last_iter_clip)
247247

248248
def test_pad_extra_level_threshold_tensor_raises(self):
249-
with self.assertRaisesRegexp(ValueError, 'pad_extra_level_threshold'):
249+
with self.assertRaisesRegex(ValueError, 'pad_extra_level_threshold'):
250250
kashin.KashinHadamardEncodingStage(
251251
pad_extra_level_threshold=tf.constant(0.8, dtype=tf.float32))
252252

tensorflow_model_optimization/python/core/internal/tensor_encoding/stages/research/misc_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,15 @@ def test_empty_input_dynamic(self):
176176
@parameterized.parameters([tf.bool, tf.float32])
177177
def test_encode_unsupported_type_raises(self, dtype):
178178
stage = self.default_encoding_stage()
179-
with self.assertRaisesRegexp(TypeError, 'Unsupported input type'):
179+
with self.assertRaisesRegex(TypeError, 'Unsupported input type'):
180180
self.run_one_to_many_encode_decode(
181181
stage, lambda: tf.cast(self.default_input(), dtype))
182182

183183
def test_encode_unsupported_input_shape_raises(self):
184184
x = tf.random.uniform((3, 4), maxval=10, dtype=tf.int32)
185185
stage = self.default_encoding_stage()
186186
params, _ = stage.get_params()
187-
with self.assertRaisesRegexp(ValueError, 'Number of dimensions must be 1'):
187+
with self.assertRaisesRegex(ValueError, 'Number of dimensions must be 1'):
188188
stage.encode(x, params)
189189

190190

tensorflow_model_optimization/python/core/internal/tensor_encoding/stages/research/quantization_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def test_all_zero_input_works(self):
112112

113113
@parameterized.parameters([0, 17, -1, 1.5])
114114
def test_bits_out_of_range_raises(self, bits):
115-
with self.assertRaisesRegexp(ValueError, 'integer between 1 and 16'):
115+
with self.assertRaisesRegex(ValueError, 'integer between 1 and 16'):
116116
quantization.PRNGUniformQuantizationEncodingStage(bits=bits)
117117

118118
def test_dynamic_input_shape(self):
@@ -226,11 +226,11 @@ def test_all_zero_input_works(self):
226226

227227
@parameterized.parameters([0, 17, -1, 1.5])
228228
def test_bits_out_of_range_raises(self, bits):
229-
with self.assertRaisesRegexp(ValueError, 'integer between 1 and 16'):
229+
with self.assertRaisesRegex(ValueError, 'integer between 1 and 16'):
230230
quantization.PerChannelUniformQuantizationEncodingStage(bits=bits)
231231

232232
def test_stochastic_tensor_raises(self):
233-
with self.assertRaisesRegexp(TypeError, 'stochastic'):
233+
with self.assertRaisesRegex(TypeError, 'stochastic'):
234234
quantization.PerChannelUniformQuantizationEncodingStage(
235235
stochastic=tf.constant(True, dtype=tf.bool))
236236

@@ -343,7 +343,7 @@ def test_all_zero_input_works(self):
343343

344344
@parameterized.parameters([0, 17, -1, 1.5])
345345
def test_bits_out_of_range_raises(self, bits):
346-
with self.assertRaisesRegexp(ValueError, 'integer between 1 and 16'):
346+
with self.assertRaisesRegex(ValueError, 'integer between 1 and 16'):
347347
quantization.PerChannelPRNGUniformQuantizationEncodingStage(bits=bits)
348348

349349
def test_dynamic_input_shape(self):

tensorflow_model_optimization/python/core/internal/tensor_encoding/stages/stages_impl_test.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,15 @@ def test_unknown_shape_raises(self):
192192
x = test_utils.get_tensor_with_random_shape()
193193
stage = self.default_encoding_stage()
194194
params, _ = stage.get_params()
195-
with self.assertRaisesRegexp(ValueError, 'fully known'):
195+
with self.assertRaisesRegex(ValueError, 'fully known'):
196196
stage.encode(x, params)
197197

198198
@parameterized.parameters([((1, 1, 5),), ((1, 1, 1, 5),)])
199199
def test_more_than_two_ndims_raises(self, dims):
200200
x = tf.random.normal(dims)
201201
stage = self.default_encoding_stage()
202202
params, _ = stage.get_params()
203-
with self.assertRaisesRegexp(ValueError, 'must be 1 or 2.'):
203+
with self.assertRaisesRegex(ValueError, 'must be 1 or 2.'):
204204
stage.encode(x, params)
205205

206206

@@ -336,27 +336,27 @@ def test_commutes_with_sum_given_min_max(self):
336336

337337
@parameterized.parameters([0, 17, -1, 1.5])
338338
def test_bits_out_of_range_raises(self, bits):
339-
with self.assertRaisesRegexp(ValueError, 'integer between 1 and 16'):
339+
with self.assertRaisesRegex(ValueError, 'integer between 1 and 16'):
340340
stages_impl.UniformQuantizationEncodingStage(bits=bits)
341341

342342
@parameterized.parameters([1.0, ([1.0, 2.0, 3.0],)])
343343
def test_bad_min_max_tensor_raises(self, bad_min_max):
344-
with self.assertRaisesRegexp(ValueError, r'shape \(2\)'):
344+
with self.assertRaisesRegex(ValueError, r'shape \(2\)'):
345345
stages_impl.UniformQuantizationEncodingStage(
346346
min_max=tf.constant(bad_min_max))
347347

348348
@parameterized.parameters([([1.0],), ([1.0, 2.0, 3.0],)])
349349
def test_bad_min_max_python_shape_raises(self, bad_min_max):
350-
with self.assertRaisesRegexp(ValueError, 'list with two elements'):
350+
with self.assertRaisesRegex(ValueError, 'list with two elements'):
351351
stages_impl.UniformQuantizationEncodingStage(min_max=bad_min_max)
352352

353353
@parameterized.parameters([([1.0, 1.0],), ([2.0, 1.0],)])
354354
def test_bad_min_max_python_values_raises(self, bad_min_max):
355-
with self.assertRaisesRegexp(ValueError, 'smaller than the second'):
355+
with self.assertRaisesRegex(ValueError, 'smaller than the second'):
356356
stages_impl.UniformQuantizationEncodingStage(min_max=bad_min_max)
357357

358358
def test_stochastic_tensor_raises(self):
359-
with self.assertRaisesRegexp(TypeError, 'stochastic'):
359+
with self.assertRaisesRegex(TypeError, 'stochastic'):
360360
stages_impl.UniformQuantizationEncodingStage(
361361
stochastic=tf.constant(True, dtype=tf.bool))
362362

@@ -441,16 +441,16 @@ def test_bad_input_executes(self):
441441
@parameterized.parameters([tf.bool, tf.int32])
442442
def test_encode_unsupported_type_raises(self, dtype):
443443
stage = self.default_encoding_stage()
444-
with self.assertRaisesRegexp(TypeError, 'Unsupported packing type'):
444+
with self.assertRaisesRegex(TypeError, 'Unsupported packing type'):
445445
self.run_one_to_many_encode_decode(
446446
stage, lambda: tf.cast(self.default_input(), dtype))
447447

448448
def test_bad_input_bits_raises(self):
449-
with self.assertRaisesRegexp(TypeError, 'cannot be a TensorFlow value'):
449+
with self.assertRaisesRegex(TypeError, 'cannot be a TensorFlow value'):
450450
stages_impl.BitpackingEncodingStage(tf.constant(1, dtype=tf.int32))
451-
with self.assertRaisesRegexp(ValueError, 'between 1 and 16'):
451+
with self.assertRaisesRegex(ValueError, 'between 1 and 16'):
452452
stages_impl.BitpackingEncodingStage(0)
453-
with self.assertRaisesRegexp(ValueError, 'between 1 and 16'):
453+
with self.assertRaisesRegex(ValueError, 'between 1 and 16'):
454454
stages_impl.BitpackingEncodingStage(17)
455455

456456

tensorflow_model_optimization/python/core/internal/tensor_encoding/utils/tf_utils_test.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,18 @@ def test_apply_twice_equals_identity(self, first_dim):
5757
def test_illegal_inputs_shape(self, *dims):
5858
"""Tests incorrect rank of the input."""
5959
x = tf.random.normal(dims)
60-
with self.assertRaisesRegexp(ValueError,
61-
'Number of dimensions of x must be 2.'):
60+
with self.assertRaisesRegex(
61+
ValueError, 'Number of dimensions of x must be 2.'
62+
):
6263
tf_utils.fast_walsh_hadamard_transform(x)
6364

6465
@parameterized.parameters([[1, 3], [1, 7], [1, 9], [4, 3]])
6566
def test_illegal_inputs_static_power_of_two(self, *dims):
6667
"""Tests incorrect static shape of the rank 2 input."""
6768
x = tf.random.normal(dims)
68-
with self.assertRaisesRegexp(ValueError,
69-
'The dimension of x must be a power of two.'):
69+
with self.assertRaisesRegex(
70+
ValueError, 'The dimension of x must be a power of two.'
71+
):
7072
tf_utils.fast_walsh_hadamard_transform(x)
7173

7274
def test_illegal_inputs_dynamic_power_of_two(self):
@@ -170,20 +172,20 @@ def test_approximately_uniform_distribution(self):
170172
self.assertAllLessEqual(bucket_counts, 10250)
171173

172174
def test_tensor_num_elements_raises(self):
173-
with self.assertRaisesRegexp(TypeError, 'must be a Python integer'):
175+
with self.assertRaisesRegex(TypeError, 'must be a Python integer'):
174176
tf_utils._cmwc_random_sequence(
175177
tf.constant(10), tf.constant(123, tf.int64))
176178

177179
def test_negative_num_elements_raises(self):
178-
with self.assertRaisesRegexp(ValueError, 'must be positive'):
180+
with self.assertRaisesRegex(ValueError, 'must be positive'):
179181
tf_utils._cmwc_random_sequence(-10, tf.constant(123, tf.int64))
180182

181183
def test_python_seed_raises(self):
182-
with self.assertRaisesRegexp(TypeError, 'tf.int64 Tensor'):
184+
with self.assertRaisesRegex(TypeError, 'tf.int64 Tensor'):
183185
tf_utils._cmwc_random_sequence(10, 123)
184186

185187
def test_tf_int32_seed_raises(self):
186-
with self.assertRaisesRegexp(TypeError, 'tf.int64 Tensor'):
188+
with self.assertRaisesRegex(TypeError, 'tf.int64 Tensor'):
187189
tf_utils._cmwc_random_sequence(10, tf.constant(123, tf.int32))
188190

189191

@@ -232,9 +234,9 @@ def test_expected_dtype(self, dtype):
232234

233235
@parameterized.parameters([tf.int32, tf.int64])
234236
def test_type_error_raises(self, dtype):
235-
with self.assertRaisesRegexp(
236-
TypeError, 'Supported types are tf.float32 and '
237-
'tf.float64 values'):
237+
with self.assertRaisesRegex(
238+
TypeError, 'Supported types are tf.float32 and tf.float64 values'
239+
):
238240
tf_utils.random_floats_cmwc(10, tf.constant(456, tf.int64), dtype)
239241

240242
def test_differs_given_different_seed(self):
@@ -291,9 +293,9 @@ def test_expected_dtype(self, dtype):
291293

292294
@parameterized.parameters([tf.int32, tf.int64])
293295
def test_type_error_raises(self, dtype):
294-
with self.assertRaisesRegexp(TypeError,
295-
'Supported types are tf.float32 and '
296-
'tf.float64 values'):
296+
with self.assertRaisesRegex(
297+
TypeError, 'Supported types are tf.float32 and tf.float64 values'
298+
):
297299
tf_utils.random_floats(10, tf.constant([456, 123], tf.int64), dtype)
298300

299301
def test_differs_given_different_seed(self):

0 commit comments

Comments
 (0)