sketchingpy.test.test_pillow_util

  1import os
  2import pathlib
  3import unittest
  4
  5import PIL.ImageFont
  6
  7import sketchingpy.pillow_util
  8import sketchingpy.shape_struct
  9
 10
 11class PillowUtilTests(unittest.TestCase):
 12
 13    def test_make_arc_image(self):
 14        result = sketchingpy.pillow_util.make_arc_image(
 15            10,
 16            20,
 17            3,
 18            4,
 19            1.5,
 20            1.6,
 21            True,
 22            True,
 23            (100, 100, 100),
 24            (200, 200, 200),
 25            7
 26        )
 27        self.assertEqual(result.get_x(), 10)
 28        self.assertEqual(result.get_y(), 20)
 29        self.assertEqual(result.get_width(), 10)
 30        self.assertEqual(result.get_height(), 11)
 31        self.assertIsNotNone(result.get_image())
 32
 33    def test_make_rect_image(self):
 34        result = sketchingpy.pillow_util.make_rect_image(
 35            10,
 36            20,
 37            3,
 38            4,
 39            True,
 40            True,
 41            (100, 100, 100),
 42            (200, 200, 200),
 43            7
 44        )
 45        self.assertEqual(result.get_x(), 6)
 46        self.assertEqual(result.get_y(), 16)
 47        self.assertEqual(result.get_width(), 9)
 48        self.assertEqual(result.get_height(), 10)
 49        self.assertIsNotNone(result.get_image())
 50
 51    def test_make_ellipse_image(self):
 52        result = sketchingpy.pillow_util.make_ellipse_image(
 53            10,
 54            20,
 55            3,
 56            4,
 57            True,
 58            True,
 59            (100, 100, 100),
 60            (200, 200, 200),
 61            7
 62        )
 63        self.assertEqual(result.get_x(), 6)
 64        self.assertEqual(result.get_y(), 16)
 65        self.assertEqual(result.get_width(), 9)
 66        self.assertEqual(result.get_height(), 10)
 67        self.assertIsNotNone(result.get_image())
 68    
 69    def test_make_shape_image_lines(self):
 70        shape = sketchingpy.shape_struct.Shape(50, 100)
 71        shape.add_line_to(150, 200)
 72        shape.end()
 73        result = sketchingpy.pillow_util.make_shape_image(
 74            shape,
 75            True,
 76            True,
 77            (100, 100, 100),
 78            (200, 200, 200),
 79            1
 80        )
 81        self.assertEqual(result.get_x(), 49)
 82        self.assertEqual(result.get_y(), 99)
 83        self.assertEqual(result.get_width(), 102)
 84        self.assertEqual(result.get_height(), 102)
 85        self.assertIsNotNone(result.get_image())
 86    
 87    def test_make_shape_image_bezier(self):
 88        shape = sketchingpy.shape_struct.Shape(50, 100)
 89        shape.add_bezier_to(60, 110, 140, 190, 150, 200)
 90        shape.end()
 91        result = sketchingpy.pillow_util.make_shape_image(
 92            shape,
 93            True,
 94            True,
 95            (100, 100, 100),
 96            (200, 200, 200),
 97            1
 98        )
 99        self.assertEqual(result.get_x(), 49)
100        self.assertEqual(result.get_y(), 99)
101        self.assertEqual(result.get_width(), 102)
102        self.assertEqual(result.get_height(), 102)
103        self.assertIsNotNone(result.get_image())
104    
105    def test_make_text_image(self):
106        font_path = os.path.join(
107            pathlib.Path(__file__).parent.absolute(),
108            'IBMPlexMono-Regular.ttf'
109        )
110        result = sketchingpy.pillow_util.make_text_image(
111            20,
112            20,
113            'test',
114            PIL.ImageFont.truetype(font_path, 10),
115            True,
116            True,
117            (100, 100, 100),
118            (200, 200, 200),
119            7,
120            'ms'
121        )
122        self.assertEqual(result.get_x(), 1)
123        self.assertEqual(result.get_y(), 6)
124        self.assertEqual(result.get_width(), 52)
125        self.assertEqual(result.get_height(), 35)
126        self.assertIsNotNone(result.get_image())
class PillowUtilTests(unittest.case.TestCase):
 12class PillowUtilTests(unittest.TestCase):
 13
 14    def test_make_arc_image(self):
 15        result = sketchingpy.pillow_util.make_arc_image(
 16            10,
 17            20,
 18            3,
 19            4,
 20            1.5,
 21            1.6,
 22            True,
 23            True,
 24            (100, 100, 100),
 25            (200, 200, 200),
 26            7
 27        )
 28        self.assertEqual(result.get_x(), 10)
 29        self.assertEqual(result.get_y(), 20)
 30        self.assertEqual(result.get_width(), 10)
 31        self.assertEqual(result.get_height(), 11)
 32        self.assertIsNotNone(result.get_image())
 33
 34    def test_make_rect_image(self):
 35        result = sketchingpy.pillow_util.make_rect_image(
 36            10,
 37            20,
 38            3,
 39            4,
 40            True,
 41            True,
 42            (100, 100, 100),
 43            (200, 200, 200),
 44            7
 45        )
 46        self.assertEqual(result.get_x(), 6)
 47        self.assertEqual(result.get_y(), 16)
 48        self.assertEqual(result.get_width(), 9)
 49        self.assertEqual(result.get_height(), 10)
 50        self.assertIsNotNone(result.get_image())
 51
 52    def test_make_ellipse_image(self):
 53        result = sketchingpy.pillow_util.make_ellipse_image(
 54            10,
 55            20,
 56            3,
 57            4,
 58            True,
 59            True,
 60            (100, 100, 100),
 61            (200, 200, 200),
 62            7
 63        )
 64        self.assertEqual(result.get_x(), 6)
 65        self.assertEqual(result.get_y(), 16)
 66        self.assertEqual(result.get_width(), 9)
 67        self.assertEqual(result.get_height(), 10)
 68        self.assertIsNotNone(result.get_image())
 69    
 70    def test_make_shape_image_lines(self):
 71        shape = sketchingpy.shape_struct.Shape(50, 100)
 72        shape.add_line_to(150, 200)
 73        shape.end()
 74        result = sketchingpy.pillow_util.make_shape_image(
 75            shape,
 76            True,
 77            True,
 78            (100, 100, 100),
 79            (200, 200, 200),
 80            1
 81        )
 82        self.assertEqual(result.get_x(), 49)
 83        self.assertEqual(result.get_y(), 99)
 84        self.assertEqual(result.get_width(), 102)
 85        self.assertEqual(result.get_height(), 102)
 86        self.assertIsNotNone(result.get_image())
 87    
 88    def test_make_shape_image_bezier(self):
 89        shape = sketchingpy.shape_struct.Shape(50, 100)
 90        shape.add_bezier_to(60, 110, 140, 190, 150, 200)
 91        shape.end()
 92        result = sketchingpy.pillow_util.make_shape_image(
 93            shape,
 94            True,
 95            True,
 96            (100, 100, 100),
 97            (200, 200, 200),
 98            1
 99        )
100        self.assertEqual(result.get_x(), 49)
101        self.assertEqual(result.get_y(), 99)
102        self.assertEqual(result.get_width(), 102)
103        self.assertEqual(result.get_height(), 102)
104        self.assertIsNotNone(result.get_image())
105    
106    def test_make_text_image(self):
107        font_path = os.path.join(
108            pathlib.Path(__file__).parent.absolute(),
109            'IBMPlexMono-Regular.ttf'
110        )
111        result = sketchingpy.pillow_util.make_text_image(
112            20,
113            20,
114            'test',
115            PIL.ImageFont.truetype(font_path, 10),
116            True,
117            True,
118            (100, 100, 100),
119            (200, 200, 200),
120            7,
121            'ms'
122        )
123        self.assertEqual(result.get_x(), 1)
124        self.assertEqual(result.get_y(), 6)
125        self.assertEqual(result.get_width(), 52)
126        self.assertEqual(result.get_height(), 35)
127        self.assertIsNotNone(result.get_image())

A class whose instances are single test cases.

By default, the test code itself should be placed in a method named 'runTest'.

If the fixture may be used for many test cases, create as many test methods as are needed. When instantiating such a TestCase subclass, specify in the constructor arguments the name of the test method that the instance is to execute.

Test authors should subclass TestCase for their own tests. Construction and deconstruction of the test's environment ('fixture') can be implemented by overriding the 'setUp' and 'tearDown' methods respectively.

If it is necessary to override the __init__ method, the base class __init__ method must always be called. It is important that subclasses should not change the signature of their __init__ method, since instances of the classes are instantiated automatically by parts of the framework in order to be run.

When subclassing TestCase, you can set these attributes:

  • failureException: determines which exception will be raised when the instance's assertion methods fail; test methods raising this exception will be deemed to have 'failed' rather than 'errored'.
  • longMessage: determines whether long messages (including repr of objects used in assert methods) will be printed on failure in addition to any explicit message passed.
  • maxDiff: sets the maximum length of a diff in failure messages by assert methods using difflib. It is looked up as an instance attribute so can be configured by individual tests if required.
def test_make_arc_image(self):
14    def test_make_arc_image(self):
15        result = sketchingpy.pillow_util.make_arc_image(
16            10,
17            20,
18            3,
19            4,
20            1.5,
21            1.6,
22            True,
23            True,
24            (100, 100, 100),
25            (200, 200, 200),
26            7
27        )
28        self.assertEqual(result.get_x(), 10)
29        self.assertEqual(result.get_y(), 20)
30        self.assertEqual(result.get_width(), 10)
31        self.assertEqual(result.get_height(), 11)
32        self.assertIsNotNone(result.get_image())
def test_make_rect_image(self):
34    def test_make_rect_image(self):
35        result = sketchingpy.pillow_util.make_rect_image(
36            10,
37            20,
38            3,
39            4,
40            True,
41            True,
42            (100, 100, 100),
43            (200, 200, 200),
44            7
45        )
46        self.assertEqual(result.get_x(), 6)
47        self.assertEqual(result.get_y(), 16)
48        self.assertEqual(result.get_width(), 9)
49        self.assertEqual(result.get_height(), 10)
50        self.assertIsNotNone(result.get_image())
def test_make_ellipse_image(self):
52    def test_make_ellipse_image(self):
53        result = sketchingpy.pillow_util.make_ellipse_image(
54            10,
55            20,
56            3,
57            4,
58            True,
59            True,
60            (100, 100, 100),
61            (200, 200, 200),
62            7
63        )
64        self.assertEqual(result.get_x(), 6)
65        self.assertEqual(result.get_y(), 16)
66        self.assertEqual(result.get_width(), 9)
67        self.assertEqual(result.get_height(), 10)
68        self.assertIsNotNone(result.get_image())
def test_make_shape_image_lines(self):
70    def test_make_shape_image_lines(self):
71        shape = sketchingpy.shape_struct.Shape(50, 100)
72        shape.add_line_to(150, 200)
73        shape.end()
74        result = sketchingpy.pillow_util.make_shape_image(
75            shape,
76            True,
77            True,
78            (100, 100, 100),
79            (200, 200, 200),
80            1
81        )
82        self.assertEqual(result.get_x(), 49)
83        self.assertEqual(result.get_y(), 99)
84        self.assertEqual(result.get_width(), 102)
85        self.assertEqual(result.get_height(), 102)
86        self.assertIsNotNone(result.get_image())
def test_make_shape_image_bezier(self):
 88    def test_make_shape_image_bezier(self):
 89        shape = sketchingpy.shape_struct.Shape(50, 100)
 90        shape.add_bezier_to(60, 110, 140, 190, 150, 200)
 91        shape.end()
 92        result = sketchingpy.pillow_util.make_shape_image(
 93            shape,
 94            True,
 95            True,
 96            (100, 100, 100),
 97            (200, 200, 200),
 98            1
 99        )
100        self.assertEqual(result.get_x(), 49)
101        self.assertEqual(result.get_y(), 99)
102        self.assertEqual(result.get_width(), 102)
103        self.assertEqual(result.get_height(), 102)
104        self.assertIsNotNone(result.get_image())
def test_make_text_image(self):
106    def test_make_text_image(self):
107        font_path = os.path.join(
108            pathlib.Path(__file__).parent.absolute(),
109            'IBMPlexMono-Regular.ttf'
110        )
111        result = sketchingpy.pillow_util.make_text_image(
112            20,
113            20,
114            'test',
115            PIL.ImageFont.truetype(font_path, 10),
116            True,
117            True,
118            (100, 100, 100),
119            (200, 200, 200),
120            7,
121            'ms'
122        )
123        self.assertEqual(result.get_x(), 1)
124        self.assertEqual(result.get_y(), 6)
125        self.assertEqual(result.get_width(), 52)
126        self.assertEqual(result.get_height(), 35)
127        self.assertIsNotNone(result.get_image())
Inherited Members
unittest.case.TestCase
TestCase
failureException
longMessage
maxDiff
addTypeEqualityFunc
addCleanup
addClassCleanup
setUp
tearDown
setUpClass
tearDownClass
countTestCases
defaultTestResult
shortDescription
id
subTest
run
doCleanups
doClassCleanups
debug
skipTest
fail
assertFalse
assertTrue
assertRaises
assertWarns
assertLogs
assertNoLogs
assertEqual
assertNotEqual
assertAlmostEqual
assertNotAlmostEqual
assertSequenceEqual
assertListEqual
assertTupleEqual
assertSetEqual
assertIn
assertNotIn
assertIs
assertIsNot
assertDictEqual
assertDictContainsSubset
assertCountEqual
assertMultiLineEqual
assertLess
assertLessEqual
assertGreater
assertGreaterEqual
assertIsNone
assertIsNotNone
assertIsInstance
assertNotIsInstance
assertRaisesRegex
assertWarnsRegex
assertRegex
assertNotRegex
failUnlessRaises
failIf
assertRaisesRegexp
assertRegexpMatches
assertNotRegexpMatches
failUnlessEqual
assertEquals
failIfEqual
assertNotEquals
failUnlessAlmostEqual
assertAlmostEquals
failIfAlmostEqual
assertNotAlmostEquals
failUnless
assert_