1 |
bh |
330 |
# Copyright (c) 2002 by Intevation GmbH |
2 |
|
|
# Authors: |
3 |
|
|
# Bernhard Herzog <[email protected]> |
4 |
|
|
# |
5 |
|
|
# This program is free software under the GPL (>=v2) |
6 |
|
|
# Read the file COPYING coming with Thuban for details. |
7 |
|
|
|
8 |
|
|
""" |
9 |
|
|
Test the Label and LabelLayer classes |
10 |
|
|
""" |
11 |
|
|
|
12 |
|
|
__version__ = "$Revision$" |
13 |
|
|
# $Source$ |
14 |
|
|
# $Id$ |
15 |
|
|
|
16 |
|
|
import unittest |
17 |
|
|
|
18 |
|
|
import support |
19 |
|
|
support.initthuban() |
20 |
|
|
|
21 |
|
|
from Thuban.Model.messages import CHANGED |
22 |
|
|
from Thuban.Model.label import Label, LabelLayer, \ |
23 |
|
|
ALIGN_CENTER, ALIGN_BASELINE, ALIGN_LEFT, ALIGN_TOP |
24 |
|
|
|
25 |
|
|
|
26 |
|
|
class TestLabel(unittest.TestCase): |
27 |
|
|
|
28 |
|
|
"""Test cases for the Label class""" |
29 |
|
|
|
30 |
|
|
def test(self): |
31 |
|
|
"""Test Label""" |
32 |
|
|
# The label objects are very simple. We just have to test |
33 |
|
|
# whether instantiating one assigns the correct values to the |
34 |
|
|
# instance variables |
35 |
|
|
label = Label(10.5, 234567.0, "Label Text", |
36 |
|
|
ALIGN_CENTER, ALIGN_BASELINE) |
37 |
|
|
self.assertEquals(label.x, 10.5) |
38 |
|
|
self.assertEquals(label.y, 234567.0) |
39 |
|
|
self.assertEquals(label.text, "Label Text") |
40 |
|
|
self.assertEquals(label.halign, ALIGN_CENTER) |
41 |
|
|
self.assertEquals(label.valign, ALIGN_BASELINE) |
42 |
|
|
|
43 |
|
|
|
44 |
|
|
class TestLabelLayer(unittest.TestCase, support.SubscriberMixin): |
45 |
|
|
|
46 |
|
|
"""Test cases for LabelLayer""" |
47 |
|
|
|
48 |
|
|
def setUp(self): |
49 |
|
|
"""Clear the messages list and create a LabelLayer as self.layer |
50 |
|
|
""" |
51 |
|
|
self.clear_messages() |
52 |
|
|
self.layer = LabelLayer("A Label Layer") |
53 |
|
|
self.layer.Subscribe(CHANGED, self.subscribe_with_params, CHANGED) |
54 |
|
|
|
55 |
|
|
def tearDown(self): |
56 |
|
|
"""Clear the messages list and explictly destroy self.layer""" |
57 |
|
|
self.layer.Destroy() |
58 |
|
|
self.clear_messages() |
59 |
|
|
|
60 |
|
|
def test_initial_state(self): |
61 |
|
|
"""Test LabelLayer's initial state""" |
62 |
|
|
self.failIf(self.layer.WasModified()) |
63 |
|
|
self.assertEquals(self.layer.Title(), "A Label Layer") |
64 |
|
|
self.assertEquals(self.layer.Labels(), []) |
65 |
|
|
self.check_messages([]) |
66 |
|
|
|
67 |
|
|
def test_methods(self): |
68 |
|
|
"""Test LabelLayer methods""" |
69 |
|
|
# first add a label |
70 |
|
|
self.layer.AddLabel(10.5, 234567.0, "Label Text") |
71 |
|
|
self.check_messages([(CHANGED,)]) |
72 |
|
|
self.assertEquals(self.layer.Labels()[0].text, "Label Text") |
73 |
|
|
self.assert_(self.layer.WasModified()) |
74 |
|
|
|
75 |
|
|
# add another one |
76 |
|
|
self.layer.AddLabel(-1000.125, 987654.0, "Another Label", |
77 |
|
|
ALIGN_LEFT, ALIGN_TOP) |
78 |
|
|
self.check_messages([(CHANGED,), |
79 |
|
|
(CHANGED,)]) |
80 |
|
|
self.assertEquals(self.layer.Labels()[0].text, "Label Text") |
81 |
|
|
self.assertEquals(self.layer.Labels()[1].text, "Another Label") |
82 |
|
|
|
83 |
|
|
# remove one |
84 |
|
|
self.layer.RemoveLabel(0) |
85 |
|
|
self.check_messages([(CHANGED,), |
86 |
|
|
(CHANGED,), |
87 |
|
|
(CHANGED,)]) |
88 |
|
|
self.assertEquals(self.layer.Labels()[0].text, "Another Label") |
89 |
|
|
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
if __name__ == "__main__": |
93 |
|
|
unittest.main() |