def test_that_pixelate_returns_pixelated_photo(self):
     pixelated_wolf = self.creator.pixelate(nr_pixels_in_x=50,
                                            nr_pixels_in_y=35)
     output_file = Path.to_testphoto('wolf_pixelated_50_35.bmp')
     if self.RESET_EXPECTED_OUTPUT:
         pixelated_wolf.save(output_file)
     # Expected image is a bitmap, to prevent jpeg artefacts in comparison
     expected_pixelated_wolf = Photo.open(output_file)
     self.assertEqual(expected_pixelated_wolf, pixelated_wolf)
    def test_that_ensure_empty_dir_empties_dir(self):
        # Place a file in the directory to be emptied
        os.mkdir(self.photos_dir)
        src_full_path = Path.to_testphoto('wolf_low_res.jpg')
        dst_full_path = os.path.join(self.photos_dir, 'wolf.jpg')
        shutil.copyfile(src_full_path, dst_full_path)
        present_files = [entry.name for entry in os.scandir(self.photos_dir)]
        self.assertListEqual(['wolf.jpg'], present_files)

        ensure_empty_dir(self.photos_dir)
        present_files = [entry.name for entry in os.scandir(self.photos_dir)]
        self.assertListEqual([], present_files)
 def test_that_photo_pixelate_returns_photo_pixelated_photo(self):
     random.seed(1)
     pixelated_wolf = self.creator.photo_pixelate(src_dir=os.path.join(
         Path.testdata, 'cats'),
                                                  nr_pixels_in_x=30,
                                                  nr_pixels_in_y=30)
     output_file = Path.to_testphoto('wolf_photo_pixelated_30_30.bmp')
     if self.RESET_EXPECTED_OUTPUT:
         pixelated_wolf.save(output_file)
     # Expected image is a bitmap, to prevent jpeg artefacts in comparison
     expected_pixelated_wolf = Photo.open(output_file)
     self.assertEqual(expected_pixelated_wolf, pixelated_wolf)
예제 #4
0
 def test_that_real_photo_returns_correct_color(self):
     photo = Photo.open(Path.to_testphoto('wolf_low_res'))
     expected_avg_color = (127, 111, 102)
     self.assertTupleEqual(expected_avg_color, photo.avg_color)
 def setUpClass(cls) -> None:
     super().setUpClass()
     cls.creator = MosaicCreator(Path.to_testphoto('wolf_high_res'),
                                 max_output_size=500)