sketchingpy.test.test_state_struct
1import unittest 2 3import sketchingpy.const 4import sketchingpy.state_struct 5 6 7class SketchStateMachineTest(unittest.TestCase): 8 9 def setUp(self): 10 self._machine = sketchingpy.state_struct.SketchStateMachine() 11 12 def test_fill(self): 13 self._machine.clear_fill() 14 self.assertFalse(self._machine.get_fill_enabled()) 15 16 self._machine.set_fill('#A0B0C0') 17 self.assertEqual(self._machine.get_fill(), '#A0B0C0') 18 self.assertTrue(self._machine.get_fill_enabled()) 19 20 self._machine.set_fill('#A0B0C0D0') 21 self.assertEqual(self._machine.get_fill(), '#A0B0C0D0') 22 self.assertTrue(self._machine.get_fill_enabled()) 23 24 self._machine.clear_fill() 25 self.assertFalse(self._machine.get_fill_enabled()) 26 27 def test_stroke(self): 28 self._machine.clear_stroke() 29 self.assertFalse(self._machine.get_stroke_enabled()) 30 31 self._machine.set_stroke('#A0B0C0') 32 self.assertEqual(self._machine.get_stroke(), '#A0B0C0') 33 self.assertTrue(self._machine.get_stroke_enabled()) 34 35 self._machine.set_stroke_weight(0) 36 self.assertFalse(self._machine.get_stroke_enabled()) 37 38 self._machine.set_stroke_weight(1) 39 self.assertTrue(self._machine.get_stroke_enabled()) 40 41 self._machine.set_stroke('#A0B0C0D0') 42 self.assertEqual(self._machine.get_stroke(), '#A0B0C0D0') 43 self.assertTrue(self._machine.get_stroke_enabled()) 44 45 self._machine.clear_stroke() 46 self.assertFalse(self._machine.get_stroke_enabled()) 47 self.assertEqual(self._machine.get_stroke_weight(), 0) 48 49 self._machine.set_stroke('#A0B0C0') 50 self.assertTrue(self._machine.get_stroke_enabled()) 51 self.assertEqual(self._machine.get_stroke_weight(), 1) 52 53 def test_arc_mode(self): 54 self._machine.set_arc_mode('center') 55 self.assertEqual(self._machine.get_arc_mode(), 'center') 56 57 self._machine.set_arc_mode('radius') 58 self.assertEqual(self._machine.get_arc_mode(), 'radius') 59 60 def test_ellipse_mode(self): 61 self._machine.set_ellipse_mode('center') 62 self.assertEqual(self._machine.get_ellipse_mode(), 'center') 63 64 self._machine.set_ellipse_mode('radius') 65 self.assertEqual(self._machine.get_ellipse_mode(), 'radius') 66 67 def test_rect_mode(self): 68 self._machine.set_rect_mode('center') 69 self.assertEqual(self._machine.get_rect_mode(), 'center') 70 71 self._machine.set_rect_mode('radius') 72 self.assertEqual(self._machine.get_rect_mode(), 'radius') 73 74 def test_stroke_weight(self): 75 self._machine.set_stroke_weight(1) 76 self.assertEqual(self._machine.get_stroke_weight(), 1) 77 self.assertTrue(self._machine.get_stroke_enabled()) 78 79 self._machine.clear_stroke() 80 self.assertEqual(self._machine.get_stroke_weight(), 0) 81 self.assertFalse(self._machine.get_stroke_enabled()) 82 83 self._machine.set_stroke_weight(2) 84 self.assertEqual(self._machine.get_stroke_weight(), 0) 85 self.assertFalse(self._machine.get_stroke_enabled()) 86 87 self._machine.set_stroke('#A0B0C0') 88 self.assertEqual(self._machine.get_stroke_weight(), 2) 89 self.assertTrue(self._machine.get_stroke_enabled()) 90 91 self._machine.set_stroke_weight(0) 92 self.assertEqual(self._machine.get_stroke_weight(), 0) 93 self.assertFalse(self._machine.get_stroke_enabled()) 94 95 def test_stroke_maintained(self): 96 self._machine.set_stroke_weight(1) 97 self._machine.set_stroke('#A0B0C0') 98 99 self.assertEqual(self._machine.get_stroke_weight(), 1) 100 self.assertTrue(self._machine.get_stroke_enabled()) 101 self.assertEqual(self._machine.get_stroke(), '#A0B0C0') 102 103 self._machine.set_stroke_weight(0) 104 self.assertEqual(self._machine.get_stroke_weight(), 0) 105 self.assertFalse(self._machine.get_stroke_enabled()) 106 self.assertEqual(self._machine.get_stroke(), '#A0B0C0') 107 108 self._machine.set_stroke_weight(2) 109 self.assertEqual(self._machine.get_stroke_weight(), 2) 110 self.assertTrue(self._machine.get_stroke_enabled()) 111 self.assertEqual(self._machine.get_stroke(), '#A0B0C0') 112 113 def test_text_font(self): 114 self._machine.set_text_font('a') 115 self.assertEqual(self._machine.get_text_font(), 'a') 116 117 self._machine.set_text_font('b') 118 self.assertEqual(self._machine.get_text_font(), 'b') 119 120 def test_text_align(self): 121 self._machine.set_text_align(sketchingpy.state_struct.TextAlign( 122 'right', 123 'baseline' 124 )) 125 self.assertEqual( 126 self._machine.get_text_align().get_horizontal_align(), 127 'right' 128 ) 129 self.assertEqual( 130 self._machine.get_text_align().get_vertical_align(), 131 'baseline' 132 ) 133 134 self._machine.set_text_align(sketchingpy.state_struct.TextAlign( 135 'center', 136 'top' 137 )) 138 self.assertEqual( 139 self._machine.get_text_align().get_horizontal_align(), 140 'center' 141 ) 142 self.assertEqual( 143 self._machine.get_text_align().get_vertical_align(), 144 'top' 145 ) 146 147 def test_image_mode(self): 148 self._machine.set_image_mode('center') 149 self.assertEqual(self._machine.get_image_mode(), 'center') 150 151 self._machine.set_image_mode('corner') 152 self.assertEqual(self._machine.get_image_mode(), 'corner') 153 154 def test_angle_mode(self): 155 self._machine.set_angle_mode('radians') 156 self.assertEqual(self._machine.get_angle_mode(), 'radians') 157 158 self._machine.set_angle_mode('degrees') 159 self.assertEqual(self._machine.get_angle_mode(), 'degrees')
8class SketchStateMachineTest(unittest.TestCase): 9 10 def setUp(self): 11 self._machine = sketchingpy.state_struct.SketchStateMachine() 12 13 def test_fill(self): 14 self._machine.clear_fill() 15 self.assertFalse(self._machine.get_fill_enabled()) 16 17 self._machine.set_fill('#A0B0C0') 18 self.assertEqual(self._machine.get_fill(), '#A0B0C0') 19 self.assertTrue(self._machine.get_fill_enabled()) 20 21 self._machine.set_fill('#A0B0C0D0') 22 self.assertEqual(self._machine.get_fill(), '#A0B0C0D0') 23 self.assertTrue(self._machine.get_fill_enabled()) 24 25 self._machine.clear_fill() 26 self.assertFalse(self._machine.get_fill_enabled()) 27 28 def test_stroke(self): 29 self._machine.clear_stroke() 30 self.assertFalse(self._machine.get_stroke_enabled()) 31 32 self._machine.set_stroke('#A0B0C0') 33 self.assertEqual(self._machine.get_stroke(), '#A0B0C0') 34 self.assertTrue(self._machine.get_stroke_enabled()) 35 36 self._machine.set_stroke_weight(0) 37 self.assertFalse(self._machine.get_stroke_enabled()) 38 39 self._machine.set_stroke_weight(1) 40 self.assertTrue(self._machine.get_stroke_enabled()) 41 42 self._machine.set_stroke('#A0B0C0D0') 43 self.assertEqual(self._machine.get_stroke(), '#A0B0C0D0') 44 self.assertTrue(self._machine.get_stroke_enabled()) 45 46 self._machine.clear_stroke() 47 self.assertFalse(self._machine.get_stroke_enabled()) 48 self.assertEqual(self._machine.get_stroke_weight(), 0) 49 50 self._machine.set_stroke('#A0B0C0') 51 self.assertTrue(self._machine.get_stroke_enabled()) 52 self.assertEqual(self._machine.get_stroke_weight(), 1) 53 54 def test_arc_mode(self): 55 self._machine.set_arc_mode('center') 56 self.assertEqual(self._machine.get_arc_mode(), 'center') 57 58 self._machine.set_arc_mode('radius') 59 self.assertEqual(self._machine.get_arc_mode(), 'radius') 60 61 def test_ellipse_mode(self): 62 self._machine.set_ellipse_mode('center') 63 self.assertEqual(self._machine.get_ellipse_mode(), 'center') 64 65 self._machine.set_ellipse_mode('radius') 66 self.assertEqual(self._machine.get_ellipse_mode(), 'radius') 67 68 def test_rect_mode(self): 69 self._machine.set_rect_mode('center') 70 self.assertEqual(self._machine.get_rect_mode(), 'center') 71 72 self._machine.set_rect_mode('radius') 73 self.assertEqual(self._machine.get_rect_mode(), 'radius') 74 75 def test_stroke_weight(self): 76 self._machine.set_stroke_weight(1) 77 self.assertEqual(self._machine.get_stroke_weight(), 1) 78 self.assertTrue(self._machine.get_stroke_enabled()) 79 80 self._machine.clear_stroke() 81 self.assertEqual(self._machine.get_stroke_weight(), 0) 82 self.assertFalse(self._machine.get_stroke_enabled()) 83 84 self._machine.set_stroke_weight(2) 85 self.assertEqual(self._machine.get_stroke_weight(), 0) 86 self.assertFalse(self._machine.get_stroke_enabled()) 87 88 self._machine.set_stroke('#A0B0C0') 89 self.assertEqual(self._machine.get_stroke_weight(), 2) 90 self.assertTrue(self._machine.get_stroke_enabled()) 91 92 self._machine.set_stroke_weight(0) 93 self.assertEqual(self._machine.get_stroke_weight(), 0) 94 self.assertFalse(self._machine.get_stroke_enabled()) 95 96 def test_stroke_maintained(self): 97 self._machine.set_stroke_weight(1) 98 self._machine.set_stroke('#A0B0C0') 99 100 self.assertEqual(self._machine.get_stroke_weight(), 1) 101 self.assertTrue(self._machine.get_stroke_enabled()) 102 self.assertEqual(self._machine.get_stroke(), '#A0B0C0') 103 104 self._machine.set_stroke_weight(0) 105 self.assertEqual(self._machine.get_stroke_weight(), 0) 106 self.assertFalse(self._machine.get_stroke_enabled()) 107 self.assertEqual(self._machine.get_stroke(), '#A0B0C0') 108 109 self._machine.set_stroke_weight(2) 110 self.assertEqual(self._machine.get_stroke_weight(), 2) 111 self.assertTrue(self._machine.get_stroke_enabled()) 112 self.assertEqual(self._machine.get_stroke(), '#A0B0C0') 113 114 def test_text_font(self): 115 self._machine.set_text_font('a') 116 self.assertEqual(self._machine.get_text_font(), 'a') 117 118 self._machine.set_text_font('b') 119 self.assertEqual(self._machine.get_text_font(), 'b') 120 121 def test_text_align(self): 122 self._machine.set_text_align(sketchingpy.state_struct.TextAlign( 123 'right', 124 'baseline' 125 )) 126 self.assertEqual( 127 self._machine.get_text_align().get_horizontal_align(), 128 'right' 129 ) 130 self.assertEqual( 131 self._machine.get_text_align().get_vertical_align(), 132 'baseline' 133 ) 134 135 self._machine.set_text_align(sketchingpy.state_struct.TextAlign( 136 'center', 137 'top' 138 )) 139 self.assertEqual( 140 self._machine.get_text_align().get_horizontal_align(), 141 'center' 142 ) 143 self.assertEqual( 144 self._machine.get_text_align().get_vertical_align(), 145 'top' 146 ) 147 148 def test_image_mode(self): 149 self._machine.set_image_mode('center') 150 self.assertEqual(self._machine.get_image_mode(), 'center') 151 152 self._machine.set_image_mode('corner') 153 self.assertEqual(self._machine.get_image_mode(), 'corner') 154 155 def test_angle_mode(self): 156 self._machine.set_angle_mode('radians') 157 self.assertEqual(self._machine.get_angle_mode(), 'radians') 158 159 self._machine.set_angle_mode('degrees') 160 self.assertEqual(self._machine.get_angle_mode(), 'degrees')
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.
13 def test_fill(self): 14 self._machine.clear_fill() 15 self.assertFalse(self._machine.get_fill_enabled()) 16 17 self._machine.set_fill('#A0B0C0') 18 self.assertEqual(self._machine.get_fill(), '#A0B0C0') 19 self.assertTrue(self._machine.get_fill_enabled()) 20 21 self._machine.set_fill('#A0B0C0D0') 22 self.assertEqual(self._machine.get_fill(), '#A0B0C0D0') 23 self.assertTrue(self._machine.get_fill_enabled()) 24 25 self._machine.clear_fill() 26 self.assertFalse(self._machine.get_fill_enabled())
28 def test_stroke(self): 29 self._machine.clear_stroke() 30 self.assertFalse(self._machine.get_stroke_enabled()) 31 32 self._machine.set_stroke('#A0B0C0') 33 self.assertEqual(self._machine.get_stroke(), '#A0B0C0') 34 self.assertTrue(self._machine.get_stroke_enabled()) 35 36 self._machine.set_stroke_weight(0) 37 self.assertFalse(self._machine.get_stroke_enabled()) 38 39 self._machine.set_stroke_weight(1) 40 self.assertTrue(self._machine.get_stroke_enabled()) 41 42 self._machine.set_stroke('#A0B0C0D0') 43 self.assertEqual(self._machine.get_stroke(), '#A0B0C0D0') 44 self.assertTrue(self._machine.get_stroke_enabled()) 45 46 self._machine.clear_stroke() 47 self.assertFalse(self._machine.get_stroke_enabled()) 48 self.assertEqual(self._machine.get_stroke_weight(), 0) 49 50 self._machine.set_stroke('#A0B0C0') 51 self.assertTrue(self._machine.get_stroke_enabled()) 52 self.assertEqual(self._machine.get_stroke_weight(), 1)
75 def test_stroke_weight(self): 76 self._machine.set_stroke_weight(1) 77 self.assertEqual(self._machine.get_stroke_weight(), 1) 78 self.assertTrue(self._machine.get_stroke_enabled()) 79 80 self._machine.clear_stroke() 81 self.assertEqual(self._machine.get_stroke_weight(), 0) 82 self.assertFalse(self._machine.get_stroke_enabled()) 83 84 self._machine.set_stroke_weight(2) 85 self.assertEqual(self._machine.get_stroke_weight(), 0) 86 self.assertFalse(self._machine.get_stroke_enabled()) 87 88 self._machine.set_stroke('#A0B0C0') 89 self.assertEqual(self._machine.get_stroke_weight(), 2) 90 self.assertTrue(self._machine.get_stroke_enabled()) 91 92 self._machine.set_stroke_weight(0) 93 self.assertEqual(self._machine.get_stroke_weight(), 0) 94 self.assertFalse(self._machine.get_stroke_enabled())
96 def test_stroke_maintained(self): 97 self._machine.set_stroke_weight(1) 98 self._machine.set_stroke('#A0B0C0') 99 100 self.assertEqual(self._machine.get_stroke_weight(), 1) 101 self.assertTrue(self._machine.get_stroke_enabled()) 102 self.assertEqual(self._machine.get_stroke(), '#A0B0C0') 103 104 self._machine.set_stroke_weight(0) 105 self.assertEqual(self._machine.get_stroke_weight(), 0) 106 self.assertFalse(self._machine.get_stroke_enabled()) 107 self.assertEqual(self._machine.get_stroke(), '#A0B0C0') 108 109 self._machine.set_stroke_weight(2) 110 self.assertEqual(self._machine.get_stroke_weight(), 2) 111 self.assertTrue(self._machine.get_stroke_enabled()) 112 self.assertEqual(self._machine.get_stroke(), '#A0B0C0')
121 def test_text_align(self): 122 self._machine.set_text_align(sketchingpy.state_struct.TextAlign( 123 'right', 124 'baseline' 125 )) 126 self.assertEqual( 127 self._machine.get_text_align().get_horizontal_align(), 128 'right' 129 ) 130 self.assertEqual( 131 self._machine.get_text_align().get_vertical_align(), 132 'baseline' 133 ) 134 135 self._machine.set_text_align(sketchingpy.state_struct.TextAlign( 136 'center', 137 'top' 138 )) 139 self.assertEqual( 140 self._machine.get_text_align().get_horizontal_align(), 141 'center' 142 ) 143 self.assertEqual( 144 self._machine.get_text_align().get_vertical_align(), 145 'top' 146 )
Inherited Members
- unittest.case.TestCase
- TestCase
- failureException
- longMessage
- maxDiff
- addTypeEqualityFunc
- addCleanup
- addClassCleanup
- 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_