I have created a function that filters an image based on the filter_type, and creates a file. For example, if the filtered image is greyscale, a new file is generated in the same folder with a name greyscale.png.
I am not sure how to test that by executing the code a temporary file is created with that name in the same folder. Here's my code:
def test_image_greyscale(self):
test_image = '/path/to/source/file.png/'
# the image processing takes place in the main function of the class;
result = self.filter_instance.main(
source=test_image,
filter='greyscale'
)
dirname, basename = os.path.split('greyscale.png')
file = tempfile.NamedTemporaryFile(prefix=basename, dir=dirname)
self.assertTrue(os.path.isfile(file.name))