/usr/lib/python3/dist-packages/defcon/test/objects/test_anchor.py is in python3-defcon 0.3.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | import unittest
from defcon.objects.anchor import Anchor
from defcon.objects.font import Font
from defcon.test.testTools import NotificationTestObserver
class AnchorTest(unittest.TestCase):
def __init__(self, methodName):
unittest.TestCase.__init__(self, methodName)
def setUp(self):
self.font = Font()
self.glyph = self.font.newGlyph("A")
self.anchor = Anchor()
def tearDown(self):
del self.anchor
del self.glyph
del self.font
def test_dirty(self):
self.assertFalse(self.anchor.dirty)
notdirty = not self.anchor.dirty
self.anchor.dirty = notdirty
self.assertEqual(self.anchor.dirty, notdirty)
self.anchor.dirty = not notdirty
self.assertNotEqual(self.anchor.dirty, notdirty)
def test_getParent(self):
self.assertIsNone(self.anchor.getParent())
self.anchor = Anchor(self.glyph)
self.assertEqual(self.anchor.getParent(), self.glyph)
def test_font(self):
self.assertIsNone(self.anchor.font)
self.anchor = Anchor(self.glyph)
self.assertEqual(self.anchor.font, self.font)
with self.assertRaises(AttributeError):
self.anchor.font = "foo"
def test_layerSet(self):
self.assertIsNone(self.anchor.layerSet)
self.anchor = Anchor(self.glyph)
self.assertEqual(self.anchor.layerSet, self.glyph.layerSet)
self.assertIsNotNone(self.anchor.layerSet)
with self.assertRaises(AttributeError):
self.anchor.layerSet = "foo"
def test_layer(self):
self.assertIsNone(self.anchor.layer)
self.anchor = Anchor(self.glyph)
self.assertEqual(self.anchor.layer, self.glyph.layer)
self.assertIsNotNone(self.anchor.layer)
with self.assertRaises(AttributeError):
self.anchor.layer = "foo"
def test_x(self):
self.anchor.x = 100
self.assertEqual(self.anchor.x, 100)
self.assertTrue(self.anchor.dirty)
def test_y(self):
self.anchor.y = 100
self.assertEqual(self.anchor.y, 100)
self.assertTrue(self.anchor.dirty)
def test_name(self):
self.anchor.name = "foo"
self.assertEqual(self.anchor.name, "foo")
self.assertTrue(self.anchor.dirty)
self.anchor.name = None
self.assertIsNone(self.anchor.name)
self.assertTrue(self.anchor.dirty)
def test_color(self):
self.anchor.color = "1,1,1,1"
self.assertEqual(self.anchor.color, "1,1,1,1")
self.assertTrue(self.anchor.dirty)
def test_identifiers(self):
anchor = Anchor(self.glyph)
self.assertEqual(anchor.identifiers, self.glyph.identifiers)
def test_identifier(self):
self.assertIsNone(self.anchor.identifier)
identifier = self.anchor.generateIdentifier()
self.assertEqual(identifier, self.anchor.identifier)
self.assertIsNotNone(self.anchor.identifier)
def test_identifier_set(self):
self.assertIsNone(self.anchor.identifier)
self.anchor.identifier = "foo"
self.assertEqual(self.anchor.identifier, "foo")
self.anchor.identifier = "bar"
self.assertEqual(self.anchor.identifier, "foo")
self.anchor.identifier = None
self.assertEqual(self.anchor.identifier, "foo")
def test_instance(self):
a = Anchor(anchorDict=dict(x=1, y=2, name="3", identifier="4",
color="1,1,1,1"))
self.assertEqual((a.x, a.y, a.name, a.identifier, a.color),
(1, 2, "3", "4", "1,1,1,1"))
def test_move(self):
a = Anchor(anchorDict=dict(x=1, y=2, name="3"))
a.dirty = False
self.assertEqual((a.x, a.y), (1, 2))
a.move((10, 0))
self.assertTrue(a.dirty)
a.dirty = False
self.assertEqual((a.x, a.y), (11, 2))
a.move((0, -123))
self.assertTrue(a.dirty)
a.dirty = False
self.assertEqual((a.x, a.y), (11, -121))
a.move((-11, 121))
self.assertEqual((a.x, a.y), (0, 0))
self.assertTrue(a.dirty)
class AnchorNotificationTest(unittest.TestCase):
def __init__(self, methodName):
unittest.TestCase.__init__(self, methodName)
def setUp(self):
self.font = Font()
self.glyph = self.font.newGlyph("A")
self.anchor = Anchor(
self.glyph,
{"name": "anchor1", "x": 300, "y": 700}
)
self.notificationObject = NotificationTestObserver()
def tearDown(self):
del self.anchor
del self.glyph
del self.font
del self.notificationObject
def test_x_changed_notification(self):
self.anchor.dispatcher.addObserver(
observer=self.notificationObject,
methodName="notificationCallback",
notification="Anchor.XChanged",
observable=self.anchor
)
self.assertEqual(self.notificationObject.stack, [])
self.anchor.x += 10
self.assertEqual(
self.notificationObject.stack[-1],
("Anchor.XChanged", "anchor1")
)
def test_y_changed_notification(self):
self.anchor.dispatcher.addObserver(
observer=self.notificationObject,
methodName="notificationCallback",
notification="Anchor.YChanged",
observable=self.anchor
)
self.assertEqual(self.notificationObject.stack, [])
self.anchor.y += 10
self.assertEqual(
self.notificationObject.stack[-1],
("Anchor.YChanged", "anchor1")
)
def test_name_notification(self):
self.anchor.dispatcher.addObserver(
observer=self.notificationObject,
methodName="notificationCallback",
notification="Anchor.NameChanged",
observable=self.anchor
)
self.assertEqual(self.notificationObject.stack, [])
self.anchor.name += "_suffix"
self.assertEqual(
self.notificationObject.stack[-1],
("Anchor.NameChanged", "anchor1_suffix")
)
def test_color_notification(self):
self.anchor.dispatcher.addObserver(
observer=self.notificationObject,
methodName="notificationCallback",
notification="Anchor.ColorChanged",
observable=self.anchor
)
self.assertEqual(self.notificationObject.stack, [])
self.anchor.color = "1,1,1,1"
self.assertEqual(
self.notificationObject.stack[-1],
("Anchor.ColorChanged", "anchor1")
)
def test_identifier_notification(self):
self.anchor.dispatcher.addObserver(
observer=self.notificationObject,
methodName="notificationCallback",
notification="Anchor.IdentifierChanged",
observable=self.anchor
)
self.assertEqual(self.notificationObject.stack, [])
self.anchor.identifier = "anchor1_identifier"
self.assertEqual(
self.notificationObject.stack[-1],
("Anchor.IdentifierChanged", "anchor1")
)
def test_endSelfNotificationObservation(self):
self.assertIsNotNone(self.anchor.dispatcher)
self.assertIsNotNone(self.anchor.font)
self.assertIsNotNone(self.anchor.layerSet)
self.assertIsNotNone(self.anchor.layer)
self.assertIsNotNone(self.anchor.glyph)
self.anchor.endSelfNotificationObservation()
self.assertIsNone(self.anchor.dispatcher)
self.assertIsNone(self.anchor.font)
self.assertIsNone(self.anchor.layerSet)
self.assertIsNone(self.anchor.layer)
self.assertIsNone(self.anchor.glyph)
if __name__ == "__main__":
unittest.main()
|