codingutf8 2022 huggingface inc licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache orglicenseslicense2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license test a dict with the wrong keys raises an error test a dict with the correct keys is returned as is test a single int value which represents size size test a single int value which represents the shortest edge test a tuple of ints which represents height width test a tuple of ints which represents width height test an int representing the shortest edge and maxsize which represents the longest edge test int with defaulttosquaretrue and maxsize fails coding utf 8 2022 huggingface inc licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache org licenses license 2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license test a dict with the wrong keys raises an error test a dict with the correct keys is returned as is test a single int value which represents size size test a single int value which represents the shortest edge test a tuple of ints which represents height width test a tuple of ints which represents width height test an int representing the shortest edge and max_size which represents the longest edge test int with default_to_square true and max_size fails
import unittest

from transformers.image_processing_utils import get_size_dict


class ImageProcessingUtilsTester(unittest.TestCase):
    def test_get_size_dict(self):
        
        inputs = {"wrong_key": 224}
        with self.assertRaises(ValueError):
            get_size_dict(inputs)

        inputs = {"height": 224}
        with self.assertRaises(ValueError):
            get_size_dict(inputs)

        inputs = {"width": 224, "shortest_edge": 224}
        with self.assertRaises(ValueError):
            get_size_dict(inputs)

        
        inputs = {"height": 224, "width": 224}
        outputs = get_size_dict(inputs)
        self.assertEqual(outputs, inputs)

        inputs = {"shortest_edge": 224}
        outputs = get_size_dict(inputs)
        self.assertEqual(outputs, {"shortest_edge": 224})

        inputs = {"longest_edge": 224, "shortest_edge": 224}
        outputs = get_size_dict(inputs)
        self.assertEqual(outputs, {"longest_edge": 224, "shortest_edge": 224})

        
        outputs = get_size_dict(224)
        self.assertEqual(outputs, {"height": 224, "width": 224})

        
        outputs = get_size_dict(224, default_to_square=False)
        self.assertEqual(outputs, {"shortest_edge": 224})

        
        outputs = get_size_dict((150, 200))
        self.assertEqual(outputs, {"height": 150, "width": 200})

        
        outputs = get_size_dict((150, 200), height_width_order=False)
        self.assertEqual(outputs, {"height": 200, "width": 150})

        
        outputs = get_size_dict(224, max_size=256, default_to_square=False)
        self.assertEqual(outputs, {"shortest_edge": 224, "longest_edge": 256})

        
        with self.assertRaises(ValueError):
            get_size_dict(224, max_size=256, default_to_square=True)