Raise TypeError instead of ValueError for invalid types (#38660)
* Raise TypeError instead of ValueError for invalid types. * Removed un-necessary changes. * Resolved conflicts * Code quality * Fix failing tests. * Fix failing tests.
This commit is contained in:
@@ -174,7 +174,7 @@ class CLIPTokenizationTest(TokenizerTesterMixin, unittest.TestCase):
|
||||
def test_log_warning(self):
|
||||
# Test related to the breaking change introduced in transformers v4.17.0
|
||||
# We need to check that an error in raised when the user try to load a previous version of the tokenizer.
|
||||
with self.assertRaises(ValueError) as context:
|
||||
with self.assertRaises(TypeError) as context:
|
||||
self.get_rust_tokenizer("robot-test/old-clip-tokenizer")
|
||||
|
||||
self.assertTrue(
|
||||
|
||||
@@ -61,7 +61,7 @@ def generate_fake_bounding_boxes(n_boxes):
|
||||
"""Generate bounding boxes in the format (center_x, center_y, width, height)"""
|
||||
# Validate the input
|
||||
if not isinstance(n_boxes, int):
|
||||
raise ValueError("n_boxes must be an integer")
|
||||
raise TypeError("n_boxes must be an integer")
|
||||
if n_boxes <= 0:
|
||||
raise ValueError("n_boxes must be a positive integer")
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ class SamProcessorTest(ProcessorTesterMixin, unittest.TestCase):
|
||||
self.assertEqual(masks[0].shape, (1, 3, 1764, 2646))
|
||||
|
||||
dummy_masks = [[1, 0], [0, 1]]
|
||||
with self.assertRaises(ValueError):
|
||||
with self.assertRaises(TypeError):
|
||||
masks = processor.post_process_masks(dummy_masks, np.array(original_sizes), np.array(reshaped_input_size))
|
||||
|
||||
def test_rle_encoding(self):
|
||||
|
||||
@@ -163,5 +163,5 @@ class SamHQProcessorTest(ProcessorTesterMixin, unittest.TestCase):
|
||||
self.assertEqual(masks[0].shape, (1, 3, 1764, 2646))
|
||||
|
||||
dummy_masks = [[1, 0], [0, 1]]
|
||||
with self.assertRaises(ValueError):
|
||||
with self.assertRaises(TypeError):
|
||||
masks = processor.post_process_masks(dummy_masks, np.array(original_sizes), np.array(reshaped_input_size))
|
||||
|
||||
Reference in New Issue
Block a user