Skip to content

Commit

Permalink
cleanup of deprecated test methods
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 722605970
  • Loading branch information
tfx-copybara committed Feb 3, 2025
1 parent 7ce9d47 commit 5fae480
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
13 changes: 8 additions & 5 deletions struct2tensor/calculate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,22 @@ def test_calculate_mock(self):
self.assertIs(my_input._calculate_output, result)

def test_calculate_broken_mock_is_repeated(self):
with self.assertRaisesRegexp(
with self.assertRaisesRegex(
ValueError,
"Expression Node0 returned the wrong type: expected: repeated <dtype: "
"'int64'> actual: optional <dtype: 'int64'>."):
"'int64'> actual: optional <dtype: 'int64'>.",
):
single_node = expression_test_util.get_mock_broken_leaf(
True, tf.int64, False, tf.int64, name="Node0")
calculate.calculate_values([single_node])

def test_calculate_broken_mock_dtype(self):
with self.assertRaisesRegexp(
ValueError, "Expression Node0 returned the "
with self.assertRaisesRegex(
ValueError,
"Expression Node0 returned the "
"wrong type: expected: repeated <dtype: "
"'int64'> actual: repeated <dtype: 'int32'>."):
"'int64'> actual: repeated <dtype: 'int32'>.",
):
single_node = expression_test_util.get_mock_broken_leaf(
True, tf.int64, True, tf.int32, name="Node0")
calculate.calculate_values([single_node])
Expand Down
15 changes: 9 additions & 6 deletions struct2tensor/ops/struct2tensor_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,15 +592,17 @@ def test_unsigned_integer_key_types(self, key_type):
self.assertAllEqual(indices_0, [])

def test_invalid_uint32_key(self):
with self.assertRaisesRegexp(tf.errors.InvalidArgumentError,
"Failed to parse .*string"):
with self.assertRaisesRegex(
tf.errors.InvalidArgumentError, "Failed to parse .*string"
):
self.evaluate(
self._parse_map_entry([test_map_pb2.MessageWithMap()],
"uint32_string_map", ["-42"]))

def test_invalid_int32_key(self):
with self.assertRaisesRegexp(tf.errors.InvalidArgumentError,
"Failed to parse .*string"):
with self.assertRaisesRegex(
tf.errors.InvalidArgumentError, "Failed to parse .*string"
):
self.evaluate(
self._parse_map_entry([test_map_pb2.MessageWithMap()],
"int32_string_map", ["foo"]))
Expand All @@ -617,8 +619,9 @@ def test_bool_key_type(self):

def test_invalid_bool_key(self):
message_with_map = test_map_pb2.MessageWithMap()
with self.assertRaisesRegexp(tf.errors.InvalidArgumentError,
"Failed to parse .*string"):
with self.assertRaisesRegex(
tf.errors.InvalidArgumentError, "Failed to parse .*string"
):
self.evaluate(
self._parse_map_entry([message_with_map], "bool_string_map", ["2"]))

Expand Down
2 changes: 1 addition & 1 deletion struct2tensor/prensor_to_structured_tensor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_deep_prensor(self):
def test_non_root_prensor(self):
child_prensor = prensor.create_prensor_from_root_and_children(
prensor_test_util.create_child_node([0, 0, 1, 3, 7], True), {})
with self.assertRaisesRegexp(ValueError, "Must be a root prensor"):
with self.assertRaisesRegex(ValueError, "Must be a root prensor"):
prensor_to_structured_tensor.prensor_to_structured_tensor(child_prensor)

def test_e2e_proto(self):
Expand Down

0 comments on commit 5fae480

Please sign in to comment.