Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup of deprecated test methods #1171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -204,49 +204,49 @@ def test_unknown_shape_raises(self):
x = test_utils.get_tensor_with_random_shape()
stage = self.default_encoding_stage()
params, _ = stage.get_params()
with self.assertRaisesRegexp(ValueError, 'fully known'):
with self.assertRaisesRegex(ValueError, 'fully known'):
stage.encode(x, params)

@parameterized.parameters([((1, 1, 5),), ((1, 1, 1, 5),)])
def test_more_than_two_ndims_raises(self, dims):
x = tf.random.normal(dims)
stage = self.default_encoding_stage()
params, _ = stage.get_params()
with self.assertRaisesRegexp(ValueError, 'must be 1 or 2.'):
with self.assertRaisesRegex(ValueError, 'must be 1 or 2.'):
stage.encode(x, params)

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

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

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

def test_num_iters_tensor_raises(self):
with self.assertRaisesRegexp(ValueError, 'num_iters'):
with self.assertRaisesRegex(ValueError, 'num_iters'):
kashin.KashinHadamardEncodingStage(
num_iters=tf.constant(2, dtype=tf.int32))

def test_last_iter_clip_tensor_raises(self):
with self.assertRaisesRegexp(ValueError, 'last_iter_clip'):
with self.assertRaisesRegex(ValueError, 'last_iter_clip'):
kashin.KashinHadamardEncodingStage(
last_iter_clip=tf.constant(True, dtype=tf.bool))

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

def test_pad_extra_level_threshold_tensor_raises(self):
with self.assertRaisesRegexp(ValueError, 'pad_extra_level_threshold'):
with self.assertRaisesRegex(ValueError, 'pad_extra_level_threshold'):
kashin.KashinHadamardEncodingStage(
pad_extra_level_threshold=tf.constant(0.8, dtype=tf.float32))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ def test_empty_input_dynamic(self):
@parameterized.parameters([tf.bool, tf.float32])
def test_encode_unsupported_type_raises(self, dtype):
stage = self.default_encoding_stage()
with self.assertRaisesRegexp(TypeError, 'Unsupported input type'):
with self.assertRaisesRegex(TypeError, 'Unsupported input type'):
self.run_one_to_many_encode_decode(
stage, lambda: tf.cast(self.default_input(), dtype))

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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def test_all_zero_input_works(self):

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

def test_dynamic_input_shape(self):
Expand Down Expand Up @@ -226,11 +226,11 @@ def test_all_zero_input_works(self):

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

def test_stochastic_tensor_raises(self):
with self.assertRaisesRegexp(TypeError, 'stochastic'):
with self.assertRaisesRegex(TypeError, 'stochastic'):
quantization.PerChannelUniformQuantizationEncodingStage(
stochastic=tf.constant(True, dtype=tf.bool))

Expand Down Expand Up @@ -343,7 +343,7 @@ def test_all_zero_input_works(self):

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

def test_dynamic_input_shape(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,15 @@ def test_unknown_shape_raises(self):
x = test_utils.get_tensor_with_random_shape()
stage = self.default_encoding_stage()
params, _ = stage.get_params()
with self.assertRaisesRegexp(ValueError, 'fully known'):
with self.assertRaisesRegex(ValueError, 'fully known'):
stage.encode(x, params)

@parameterized.parameters([((1, 1, 5),), ((1, 1, 1, 5),)])
def test_more_than_two_ndims_raises(self, dims):
x = tf.random.normal(dims)
stage = self.default_encoding_stage()
params, _ = stage.get_params()
with self.assertRaisesRegexp(ValueError, 'must be 1 or 2.'):
with self.assertRaisesRegex(ValueError, 'must be 1 or 2.'):
stage.encode(x, params)


Expand Down Expand Up @@ -336,27 +336,27 @@ def test_commutes_with_sum_given_min_max(self):

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

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

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

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

def test_stochastic_tensor_raises(self):
with self.assertRaisesRegexp(TypeError, 'stochastic'):
with self.assertRaisesRegex(TypeError, 'stochastic'):
stages_impl.UniformQuantizationEncodingStage(
stochastic=tf.constant(True, dtype=tf.bool))

Expand Down Expand Up @@ -441,16 +441,16 @@ def test_bad_input_executes(self):
@parameterized.parameters([tf.bool, tf.int32])
def test_encode_unsupported_type_raises(self, dtype):
stage = self.default_encoding_stage()
with self.assertRaisesRegexp(TypeError, 'Unsupported packing type'):
with self.assertRaisesRegex(TypeError, 'Unsupported packing type'):
self.run_one_to_many_encode_decode(
stage, lambda: tf.cast(self.default_input(), dtype))

def test_bad_input_bits_raises(self):
with self.assertRaisesRegexp(TypeError, 'cannot be a TensorFlow value'):
with self.assertRaisesRegex(TypeError, 'cannot be a TensorFlow value'):
stages_impl.BitpackingEncodingStage(tf.constant(1, dtype=tf.int32))
with self.assertRaisesRegexp(ValueError, 'between 1 and 16'):
with self.assertRaisesRegex(ValueError, 'between 1 and 16'):
stages_impl.BitpackingEncodingStage(0)
with self.assertRaisesRegexp(ValueError, 'between 1 and 16'):
with self.assertRaisesRegex(ValueError, 'between 1 and 16'):
stages_impl.BitpackingEncodingStage(17)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ def test_apply_twice_equals_identity(self, first_dim):
def test_illegal_inputs_shape(self, *dims):
"""Tests incorrect rank of the input."""
x = tf.random.normal(dims)
with self.assertRaisesRegexp(ValueError,
with self.assertRaisesRegex(ValueError,
'Number of dimensions of x must be 2.'):
tf_utils.fast_walsh_hadamard_transform(x)

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

Expand Down Expand Up @@ -170,20 +170,20 @@ def test_approximately_uniform_distribution(self):
self.assertAllLessEqual(bucket_counts, 10250)

def test_tensor_num_elements_raises(self):
with self.assertRaisesRegexp(TypeError, 'must be a Python integer'):
with self.assertRaisesRegex(TypeError, 'must be a Python integer'):
tf_utils._cmwc_random_sequence(
tf.constant(10), tf.constant(123, tf.int64))

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

def test_python_seed_raises(self):
with self.assertRaisesRegexp(TypeError, 'tf.int64 Tensor'):
with self.assertRaisesRegex(TypeError, 'tf.int64 Tensor'):
tf_utils._cmwc_random_sequence(10, 123)

def test_tf_int32_seed_raises(self):
with self.assertRaisesRegexp(TypeError, 'tf.int64 Tensor'):
with self.assertRaisesRegex(TypeError, 'tf.int64 Tensor'):
tf_utils._cmwc_random_sequence(10, tf.constant(123, tf.int32))


Expand Down Expand Up @@ -232,7 +232,7 @@ def test_expected_dtype(self, dtype):

@parameterized.parameters([tf.int32, tf.int64])
def test_type_error_raises(self, dtype):
with self.assertRaisesRegexp(
with self.assertRaisesRegex(
TypeError, 'Supported types are tf.float32 and '
'tf.float64 values'):
tf_utils.random_floats_cmwc(10, tf.constant(456, tf.int64), dtype)
Expand Down Expand Up @@ -291,7 +291,7 @@ def test_expected_dtype(self, dtype):

@parameterized.parameters([tf.int32, tf.int64])
def test_type_error_raises(self, dtype):
with self.assertRaisesRegexp(TypeError,
with self.assertRaisesRegex(TypeError,
'Supported types are tf.float32 and '
'tf.float64 values'):
tf_utils.random_floats(10, tf.constant([456, 123], tf.int64), dtype)
Expand Down
Loading