예제 #1
0
 def test_noreplace(self):
     with capture_output() as out:
         dip.convert_tif_to_jpg(self.folder,
                                self.size3,
                                self.size3,
                                replace=False)
     output = out.getvalue().strip()
     out.close()
     lines = output.split('\n')
     self.assertTrue(output.startswith('Processing folder: "'))
     self.assertTrue(output.endswith('Batch processing complete.'))
     for this_line in lines:
         if this_line.startswith(
                 ' Skipping due to pre-existing jpg file: "'):
             break
     else:
         self.assertTrue(
             False, 'No images were skipped due to pre-existing ones.')
     for this_line in lines:
         if this_line.startswith(' Skipping file   : "{}"'.format(
                 self.name6)):
             break
     else:
         self.assertTrue(False,
                         'File "{}" was not skipped.'.format(self.name6))
예제 #2
0
 def test_upscale(self):
     with capture_output() as out:
         dip.convert_tif_to_jpg(self.folder,
                                max_width=self.size4,
                                max_height=self.size4,
                                enlarge=True,
                                replace=True)
     output = out.getvalue().strip()
     out.close()
     lines = output.split('\n')
     self.assertTrue(output.startswith('Processing folder: "'))
     self.assertTrue(output.endswith('Batch processing complete.'))
     for this_line in lines:
         if this_line.startswith(' Saving image    : "'):
             break
     else:
         self.assertTrue(False, 'No images were saved.')
     for this_line in lines:
         if this_line.startswith(' Skipping file   : "{}"'.format(
                 self.name6)):
             break
     else:
         self.assertTrue(False,
                         'File "{}" was not skipped.'.format(self.name6))
     with open(
             os.path.join(self.folder, self.name1.replace('.tif', '.jpg')),
             'rb') as file:
         img = Image.open(file)
         img.load()
     np.testing.assert_array_equal(img.size, [self.size4, self.size4])
     fact = self.size2 / self.size1
     with open(
             os.path.join(self.folder, self.name2.replace('.tif', '.jpg')),
             'rb') as file:
         img = Image.open(file)
         img.load()
     np.testing.assert_array_equal(img.size,
                                   [int(self.size4 * fact), self.size4])
     with open(
             os.path.join(self.folder, self.name3.replace('.tif', '.jpg')),
             'rb') as file:
         img = Image.open(file)
         img.load()
     np.testing.assert_array_equal(
         img.size, [self.size4, int(self.size4 * fact)])
     with open(
             os.path.join(self.folder, self.name4.replace('.tif', '.jpg')),
             'rb') as file:
         img = Image.open(file)
         img.load()
     np.testing.assert_array_equal(img.size, [self.size4, self.size6 * 2])
     with open(
             os.path.join(self.folder, self.name5.replace('.tif', '.jpg')),
             'rb') as file:
         img = Image.open(file)
         img.load()
     np.testing.assert_array_equal(img.size, [self.size6 * 2, self.size4])
     img.close()
예제 #3
0
 def test_no_images(self):
     with capture_output() as out:
         dip.convert_tif_to_jpg(get_data_dir())
     output = out.getvalue().strip()
     out.close()
     lines = output.split('\n')
     self.assertTrue(output.startswith('Processing folder: "'))
     self.assertTrue(output.endswith('Batch processing complete.'))
     for this_line in lines:
         self.assertFalse(this_line.startswith(' Resizing image'))