コード例 #1
0
    def test_fitness(self):
        s = Sketch.read(self._data("sketch01.txt"))
        im2 = Image.open(self._data("test.png"))
        self.assertAlmostEqual(s.get_fitness(im2), 200)

        s = Sketch(Point(65, 65), RGB)
        self.assertEqual(s.get_fitness(im2), 130382)
コード例 #2
0
 def test_read(self):
     file_contents = open(self._data("sketch01.txt")).read().strip()
     s = Sketch.read(self._data("sketch01.txt"))
     self.assertEqual(s.size.x, 65)
     self.assertEqual(s.size.y, 65)
     self.assertEqual(len(s.triangles), 2)
     content = BytesIO()
     s.save_file_obj(content)
     saved_file = content.getvalue().strip()
     self.assertEqual(saved_file, file_contents)
コード例 #3
0
    def test_save_image(self):
        s = Sketch.read(self._data("sketch01.txt"))
        s.save_image(self._out("test.png"))
        im1 = Image.open(self._out("test.png"))
        im2 = Image.open(self._data("test.png"))
        self.assertEqual(list(im1.getdata()), list(im2.getdata()))

        # also works with file-like object
        content = BytesIO()
        s.save_image(content)
        im1 = Image.open(content)
        self.assertEqual(list(im1.getdata()), list(im2.getdata()))
コード例 #4
0
 def test_clone(self):
     s = Sketch.read(self._data("sketch01.txt"))
     s2 = s.clone()
     s.triangles[0].coordinates = [18, 18, 10, 0, 10, 10]
     self.assertEqual(s2.triangles[0].coordinates, [0, 0, 10, 0, 10, 10])