Created
May 28, 2018 14:51
-
-
Save desh2608/afe4472b428b9c761c9ef24cfebf53e3 to your computer and use it in GitHub Desktop.
Example of a unit test script for testing utilities using Python unittest module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
class ImageUtilsTest(unittest.TestCase): | |
"""Testing image utilities: visualization and compression | |
""" | |
def setUp(self): | |
"""This method sets up objects for all the test cases. | |
""" | |
<code for loading data> | |
def test_visualize_object(self): | |
"""Given a dictionary object as follows | |
x['img']: numpy array of shape (height,width,colors) | |
x['mask']: numpy array of shape (height,width), with every element categorizing it into one of the object ids | |
The method generates an image overlaying a translucent mask on the image. | |
""" | |
visualize_mask(self.test_object) | |
def test_compress_object(self): | |
"""Given a dictionary object x, the method compresses the object and prints the original and compressed sizes. | |
It also asserts that the original size should be greater than the compressed size. | |
""" | |
y = compress_image_with_mask(self.test_object,self.c) | |
x_mem = sys.getsizeof(self.test_object) | |
y_mem = sys.getsizeof(y) | |
self.assertTrue(y_mem <= x_mem) | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment