From 26c94f67716f457efaa70c63b4d1b561a08be9f1 Mon Sep 17 00:00:00 2001 From: TensorFlow Hub Authors Date: Fri, 17 Jan 2025 04:09:05 -0800 Subject: [PATCH] cleanup of deprecated test methods PiperOrigin-RevId: 716610454 --- examples/half_plus_two/half_plus_two_test.py | 2 +- tensorflow_hub/compressed_module_resolver_test.py | 2 +- tensorflow_hub/feature_column_v2_test.py | 2 +- tensorflow_hub/keras_layer_test.py | 2 +- tensorflow_hub/resolver_test.py | 10 +++++----- tensorflow_hub/tensor_info_test.py | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/half_plus_two/half_plus_two_test.py b/examples/half_plus_two/half_plus_two_test.py index f63b02855..1b0fabd3d 100644 --- a/examples/half_plus_two/half_plus_two_test.py +++ b/examples/half_plus_two/half_plus_two_test.py @@ -34,7 +34,7 @@ def testExportTool(self): module_path = os.path.join(self.get_temp_dir(), "half-plus-two-module") export_tool_path = os.path.join(test_utils.test_srcdir(), EXPORT_TOOL_PATH) - self.assertEquals(0, subprocess.call([export_tool_path, module_path])) + self.assertEqual(0, subprocess.call([export_tool_path, module_path])) # Test the Module computes (0.5*input + 2). with tf.Graph().as_default(): diff --git a/tensorflow_hub/compressed_module_resolver_test.py b/tensorflow_hub/compressed_module_resolver_test.py index d90db2bae..044a5a826 100644 --- a/tensorflow_hub/compressed_module_resolver_test.py +++ b/tensorflow_hub/compressed_module_resolver_test.py @@ -106,7 +106,7 @@ def testModuleDescriptor(self): http_resolver = compressed_module_resolver.HttpCompressedFileResolver() path = http_resolver(self.module_handle) desc = tf_utils.read_file_to_string(resolver._module_descriptor_file(path)) - self.assertRegexpMatches( + self.assertRegex( desc, "Module: %s\n" "Download Time: .*\n" "Downloader Hostname: %s .PID:%d." % (re.escape( diff --git a/tensorflow_hub/feature_column_v2_test.py b/tensorflow_hub/feature_column_v2_test.py index cda239d39..f5d7ec978 100644 --- a/tensorflow_hub/feature_column_v2_test.py +++ b/tensorflow_hub/feature_column_v2_test.py @@ -175,7 +175,7 @@ def testLoadingDifferentFeatureColumnsFails(self): # Loading of checkpoints from the first model into the second model should # fail. - with self.assertRaisesRegexp(AssertionError, + with self.assertRaisesRegex(AssertionError, ".*not bound to checkpointed values.*"): model_2.load_weights(checkpoint_path).assert_consumed() diff --git a/tensorflow_hub/keras_layer_test.py b/tensorflow_hub/keras_layer_test.py index a784315a0..1e8b7830e 100644 --- a/tensorflow_hub/keras_layer_test.py +++ b/tensorflow_hub/keras_layer_test.py @@ -803,7 +803,7 @@ def test_keras_layer_logs_if_training_zero_variables(self): layer([[10.]]) layer([[10.]]) self.assertLen(logs.records, 1) # Duplicate logging is avoided. - self.assertRegexpMatches(logs.records[0].msg, "zero trainable weights") + self.assertRegex(logs.records[0].msg, "zero trainable weights") else: # Just test that it runs at all. layer([[10.]]) diff --git a/tensorflow_hub/resolver_test.py b/tensorflow_hub/resolver_test.py index 980c16d2d..7a7a3693c 100644 --- a/tensorflow_hub/resolver_test.py +++ b/tensorflow_hub/resolver_test.py @@ -89,7 +89,7 @@ def testCacheDir(self): self.assertEqual(cache_dir, None) # Use temp dir. cache_dir = resolver.tfhub_cache_dir(use_temp=True) - self.assertEquals(cache_dir, + self.assertEqual(cache_dir, os.path.join(tempfile.gettempdir(), "tfhub_modules")) # Use override cache_dir = resolver.tfhub_cache_dir(default_cache_dir="/d", use_temp=True) @@ -138,10 +138,10 @@ def testDirSize(self): self.assertEqual(0, resolver._locked_tmp_dir_size(fake_lock_filename)) def testLockFileName(self): - self.assertEquals("/a/b/c.lock", resolver._lock_filename("/a/b/c/")) + self.assertEqual("/a/b/c.lock", resolver._lock_filename("/a/b/c/")) def testTempDownloadDir(self): - self.assertEquals("/a/b.t.tmp", resolver._temp_download_dir("/a/b/", "t")) + self.assertEqual("/a/b.t.tmp", resolver._temp_download_dir("/a/b/", "t")) def testReadTaskUidFromLockFile(self): module_dir = os.path.join(self.get_temp_dir(), "module") @@ -250,7 +250,7 @@ def fake_download_fn_with_rogue_behavior(handle, tmp_dir): self.assertEqual( sorted(tf.compat.v1.gfile.ListDirectory(parent_dir)), ["module", "module.descriptor.txt"]) - self.assertRegexpMatches( + self.assertRegex( tf_utils.read_file_to_string( resolver._module_descriptor_file(module_dir)), "Module: module\n" "Download Time: .*\n" @@ -300,7 +300,7 @@ def fake_download_fn(handle, tmp_dir): self.assertEqual( sorted(tf.compat.v1.gfile.ListDirectory(parent_dir)), ["module", "module.descriptor.txt"]) - self.assertRegexpMatches( + self.assertRegex( tf_utils.read_file_to_string( resolver._module_descriptor_file(module_dir)), "Module: module\n" "Download Time: .*\n" diff --git a/tensorflow_hub/tensor_info_test.py b/tensorflow_hub/tensor_info_test.py index 3f36986a6..ab65db05d 100644 --- a/tensorflow_hub/tensor_info_test.py +++ b/tensorflow_hub/tensor_info_test.py @@ -182,7 +182,7 @@ def testConvertTensors(self): # check sparsity in1 = tf.compat.v1.sparse_placeholder(tf.int32, []) - with self.assertRaisesRegexp(TypeError, + with self.assertRaisesRegex(TypeError, "Got SparseTensor. Expected Tensor."): tensor_info.convert_dict_to_compatible_tensor({"a": in1}, targets)