My favorites | Sign in
Project Home Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Repository:
Checkout   Browse   Changes  
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
'''
Created on Sep 28, 2010

@author: morgan
'''
from string import Template
import unittest
import kml

print kml

class UnitTests(unittest.TestCase):
#--------------------------------------------------------------------------
# Setup and utilities
#--------------------------------------------------------------------------

def setUp(self):
self.kml = kml.kml()
self.verbose = False

def tearDown(self):
del self.kml

@property
def verbose(self):
return self._verbose

@verbose.setter
def verbose(self, value):
if type(value) == bool:
self._verbose = value
else:
raise TypeError("verbose must be a boolean")

def assertAssignRaises(self, exception, KMLObject, attribute, value):
"""
This is roughly equivalent to:
self.assertRaises(exception, KMLObject.attribute = value)
except, of course, you can't do that. ;)
"""
classname = KMLObject.__class__.__name__
exceptname = exception.__name__
try:
KMLObject.__setattr__(attribute, value)
except exception:
pass
except Exception as inst:
realexception = inst.__class__.__name__
msg=Template("Exception $r, not $e occurred for illegal $c.$a value")
msg=msg.substitute(r=realexception, e=exceptname, c=classname, a=attribute)
self.fail(msg)
else:
msg=Template("Exception $e did not occur for illegal $c.$a value")
msg=msg.substitute(e=exceptname, c=classname, a=attribute)
self.fail(msg)

def assertAssignSuccessful(self, KMLObject, attribute, value):
KMLObject.__setattr__(attribute, value)
self.assertEqual(KMLObject.__getattribute__(attribute), value)


def cloneTest(self, KMLObject, debug=False):
"""
tests the ability of a KMLObject create an XML node and to then
parse it back. Each object is then converted to a string (XML) and
compared. The two strings should be equal, otherwise an exception is
raised.

This test is a sort-of acid test. For a fully-filled out object, this
test will hit every single line of code in the KMLObject-derived class.
The only exception to this rule is if, somehow, you've got data leaking
in from another instance of this class or a predecessor. I'm not sure
under which conditions this occurs and believe that it may be a Python
bug; however, since I can't (yet) reproduce the scenario in a simple
isolated test case, I'm not officially calling it a Python bug. I
consider it more likely that it is a gap in my understanding of how
Python handles some aspects of inheritance in new-style classes
"""
source = KMLObject
target = KMLObject.__class__()
target.parseKMLNode(source.toXmlNode(self.kml))
if debug:
print("\n")
print("*** source:")
print(source.toStr(self.kml, True).replace("\t", " "))
print("*** target:")
print(target.toStr(self.kml, True).replace("\t", " "))
self.assertEqual(source.toStr(self.kml, True),
target.toStr(self.kml, True))

def modeTest(self, mode, testvalue):
""" test a mode. testvalue needs to be a non-default value """
self.assertEqual(mode.value, mode.__class__.default)
self.assertNotEqual(mode.validModes, [])
for value in mode.validModes:
self.assertEqual(mode.__getattribute__(value), value)
mode.actualMode = testvalue
self.assertRaises(ValueError, mode.__class__, "bogus")
self.assertEqual(mode.actualMode, mode.__getattribute__(testvalue))
self.assertNotEqual(mode.defaultMode, mode.__getattribute__(testvalue))
self.cloneTest(mode, self.verbose)

#--------------------------------------------------------------------------
# Base classes
#--------------------------------------------------------------------------

def testColor(self):
color = kml.Color(255, 127, 63, 1) # nice darkish blue!
self.assertEqual(color.alpha, 0xFF)
self.assertEqual(color.blue, 0x7F)
self.assertEqual(color.green, 0x3F)
self.assertEqual(color.red, 0x01)
self.assertEqual(color.value, 0xff7f3f01)
color2 = kml.Color()
color2.value = 0xff7f3f01
self.assertEqual(color.value, color2.value)

#--------------------------------------------------------------------------
# Enumerated classes
#--------------------------------------------------------------------------
def testAltitudeMode(self):
self.modeTest(kml.altitudeMode(), "clampToGround")

def testDisplayMode(self):
self.modeTest(kml.displayMode(), "hide")

def testExtrude(self):
extrude = kml.extrude()
self.assertFalse(extrude.value)
extrude.value = True
self.assertTrue(extrude.value)
newExtrude = kml.extrude()
newExtrude.parseKMLNode(extrude.toXmlNode(self.kml))
self.assertNotEqual(extrude.toStr(self.kml, True),"")
self.assertEqual(extrude.toStr(self.kml, True),
newExtrude.toStr(self.kml, True))

def testColorMode(self):
self.modeTest(kml.colorMode(), "random")

def testRefreshMode(self):
self.modeTest(kml.refreshMode(), "onExpire")

def testViewRefreshMode(self):
self.modeTest(kml.viewRefreshMode(), "onStop")

#--------------------------------------------------------------------------
# Data classes
#--------------------------------------------------------------------------

def testCoordinates(self):
coords1 = kml.coordinates()
self.assertRaises(TypeError, kml.Coordinate, 'foo', 2, 3)
self.assertRaises(TypeError, kml.Coordinate, 1, 'bar', 3)
self.assertRaises(TypeError, kml.Coordinate, 1, 2, 'baz')
self.assertRaises(Exception, kml.Coordinate, coords="Foo")
self.assertRaises(ValueError, kml.Coordinate, 190, 2, 3)
self.assertRaises(ValueError, kml.Coordinate, 1, -290, 3)
# this should not fail
kml.Coordinate(1, 2, 390)
coord1 = kml.Coordinate(1,2,3)
coord2 = kml.Coordinate()
coord2.latitude = 2
coord2.longitude = 1
coord2.altitude = 3
self.assertEqual(str(coord1), str(coord2))
coord2.longitude = 4
coord2.latitude = 5
coord2.altitude = 6
coords1.append(coord1)
coords1.append(coord2)
self.cloneTest(coords1, self.verbose)

def testLocation(self):
loc = kml.Location(1,2,3)
coord = kml.Coordinate(1,2,3)
loc2 = kml.Location(coords=coord)
self.assertEqual(str(loc), str(loc2))
self.cloneTest(loc2, self.verbose)

def testOrientation(self):
orient = kml.Orientation(0, 60, 90)
self.cloneTest(orient, self.verbose)

def testLink(self):
time=10
refresh="onInterval"
viewRefresh="onRequest"
scale=0.75
pretty=True
link = kml.Link(id="foo", href="http://example.com/kml",
refreshMode=refresh,
refreshInterval=time,
viewRefreshMode=viewRefresh,
viewRefreshInterval=time,
viewBoundScale=scale)
self.assertEqual(link.refreshMode, refresh)
self.assertEqual(link.viewRefreshMode, viewRefresh)
self.assertEqual(link.viewBoundScale, scale)
self.assertRaises(TypeError, kml.Link, refreshMode=1)
self.assertRaises(ValueError, kml.Link, refreshMode="foo")
self.assertRaises(ValueError, kml.Link, refreshInterval=-1)
self.assertRaises(TypeError, kml.Link, refreshInterval="foo")
self.assertRaises(TypeError, kml.Link, viewRefreshMode=1)
self.assertRaises(ValueError, kml.Link, viewRefreshMode="foo")
self.assertRaises(ValueError, kml.Link, viewRefreshInterval=-1)
self.assertRaises(TypeError, kml.Link, viewRefreshInterval="foo")
self.cloneTest(link, self.verbose)

def testIcon(self):
href="root:///icons/palette-3.png"
x=96
y=128
h=32
w=32
icon = kml.Icon(href="root:///icons/palette-3.png", x=x, y=y,
height=h, width=w)
self.assertEqual(icon.x, x)
self.assertEqual(icon.y, y)
self.assertEqual(icon.width, w)
self.assertEqual(icon.height, h)
icon=kml.Icon()
icon.href=href
icon.x=x
icon.y=y
icon.height=h
icon.width=w
self.assertEqual(icon.x, x)
self.assertEqual(icon.y, y)
self.assertEqual(icon.width, w)
self.assertEqual(icon.height, h)
self.cloneTest(icon, self.verbose)

def testScale(self):
f1 = 0.5
f2 = 0.6
f3 = 0.7
scale = kml.Scale(x=f1, y=f2, z=f3)
self.assertEqual(scale.x, f1)
self.assertEqual(scale.y, f2)
self.assertEqual(scale.z, f3)
self.assertRaises(TypeError, kml.Scale, x="foo")
self.assertRaises(TypeError, kml.Scale, y="foo")
self.assertRaises(TypeError, kml.Scale, z="foo")
self.assertRaises(ValueError, kml.Scale, x=-1)
self.assertRaises(ValueError, kml.Scale, y=-1)
self.assertRaises(ValueError, kml.Scale, z=-1)
scale=kml.Scale()
self.assertEqual(scale.x,0)
scale.x = f1
scale.y = f2
scale.z = f3
self.assertEqual(scale.x, f1)
self.assertEqual(scale.y, f2)
self.assertEqual(scale.z, f3)
self.cloneTest(scale, self.verbose)

def testAlias(self):
s="foo"
t="bar"
alias = kml.Alias(s, t)
self.assertEqual(alias.sourceHref, s)
self.assertEqual(alias.targetHref, t)
alias=kml.Alias()
alias.sourceHref = s
alias.targetHref = t
self.assertEqual(alias.sourceHref, s)
self.assertEqual(alias.targetHref, t)
#alias2=kml.Alias()
#self.cloneTest(alias, alias2)
self.cloneTest(alias, self.verbose)

def testResourceMap(self):
d=dict(foo="bar", baz="banf", fubar="foobar")
aliases=[]
for key in d.keys():
aliases.append(kml.Alias(key, d[key]))
map=kml.ResourceMap()
for alias in aliases:
map.addAlias(alias)
self.assertEqual(aliases, map.Aliases)

map.removeAlias(aliases[1])
self.assertFalse(aliases[1] in map.Aliases)

map.clearAliases()
self.assertFalse(map.Aliases)
self.cloneTest(map, self.verbose)

def testHotSpot(self):
x = 0.25
y = 0.35
hotspot = kml.hotSpot(x, y)
self.assertEqual(hotspot.xfraction, True)
self.assertEqual(hotspot.yfraction, True)
self.assertEqual(hotspot.x, x)
self.assertEqual(hotspot.y, y)
x = 5
y = 3
hotspot.xfraction = False
hotspot.x = x
hotspot.yfraction = False
hotspot.y = x
self.assertEqual(hotspot.xunits, "insetPixels")
self.assertEqual(hotspot.yunits, "insetPixels")
self.assertRaises(ValueError, kml.hotSpot, 2)
self.assertRaises(ValueError, kml.hotSpot, 1,2)
self.assertRaises(TypeError, kml.hotSpot, 0.25,0.25,xunits="insetPixels",
yunits="insetPixels")
self.assertRaises(TypeError, kml.hotSpot, xunits="insetPixels")
self.assertRaises(ValueError, kml.hotSpot, xunits="foo")
self.cloneTest(hotspot, self.verbose)

#--------------------------------------------------------------------------
# Styles
#--------------------------------------------------------------------------

def testBalloonStyle(self):
id = "foo"
bgColor = 0xff7f3f01
textColor = kml.Color(255, 255, 255, 255)
text = "Hello, World."
DisplayMode = kml.displayMode("default")
style = kml.BalloonStyle(id, bgColor, textColor, text, DisplayMode)
self.assertEqual(style.id, id)
self.assertEqual(style.bgColor, bgColor)
self.assertEqual(style.textColor, int(str(textColor),16))
self.assertEqual(style.text, text)
self.assertEqual(style.displayMode, DisplayMode.value)
self.cloneTest(style, self.verbose)

def testLineStyle(self):
id = "foo"
width=4
darkBlue = kml.Color(255, 127, 63, 1)
colorMode = kml.colorMode("normal")
style = kml.LineStyle(id, width, color=darkBlue, colorMode=colorMode)
self.assertEqual(style.id, id)
self.assertEqual(style.color, darkBlue.value)
self.assertEqual(style.colorMode, colorMode.value)
self.assertEqual(style.width, width)
self.cloneTest(style, self.verbose)

def testIconStyle(self):
id = "foo"
icon = kml.Icon(href="1.png")
scale=0.75
heading=0
hotSpot = kml.hotSpot(0.25, 0.25)
style = kml.IconStyle(id, scale, heading, icon)
style.hotSpot=hotSpot
self.assertEqual(style.Icon, icon)
self.assertEqual(style.scale, scale)
self.assertEqual(style.heading, heading)
self.assertEqual(style.hotSpot, hotSpot)
self.cloneTest(style, self.verbose)

#--------------------------------------------------------------------------
# Geometry
#--------------------------------------------------------------------------

def testLineString(self):
id = "foo"
coords = kml.coordinates()
for n in range(0,10):
coords.append(kml.Coordinate(n, n+1 ,n+2))
linestring = kml.LineString(id=id)
linestring.extrude = True
linestring.tessellate = True
linestring.coordinates = coords
self.assertEqual(linestring.extrude, True)
self.assertEqual(linestring.tessellate, True)
self.assertEqual(linestring.coordinates, coords.value)
self.cloneTest(linestring, self.verbose)
del linestring, coords

def testLinearRing(self):
id = "foo"
openCoords = kml.coordinates()
for n in range(0,4):
openCoords.append(kml.Coordinate(n, n+1, n+2))
closedCoords = kml.coordinates()
for n in range(0,4):
closedCoords.append(kml.Coordinate(n, n*2, n*3))
closedCoords.append(closedCoords.value[0])
linearRing = kml.LinearRing(coordinates=openCoords)
self.assertRaises(Exception,linearRing.toXmlNode, self.kml)
linearRing.coordinates = closedCoords
self.assertEqual(linearRing.coordinates, closedCoords.value)
self.assertEqual(linearRing.extrude, False)
self.assertEqual(linearRing.tessellate, False)
self.assertEqual(linearRing.altitudeMode, kml.altitudeMode.default)
linearRing.extrude = kml.extrude(True)
linearRing.tessellate = kml.tessellate(True)
self.assertEqual(linearRing.tessellate, True)
self.assertEqual(linearRing.extrude, True)
linearRing.extrude = False
linearRing.tessellate = False
self.assertEqual(linearRing.extrude, False)
self.assertEqual(linearRing.tessellate, False)
self.assertRaises(TypeError, kml.LinearRing, extrude=1)
self.assertRaises(TypeError, kml.LinearRing, tessellate=1)
linearRing.extrude = True
linearRing.tessellate = True
self.cloneTest(linearRing, self.verbose)

def testPoint(self):
pt1 = kml.Point("", 1,2,3)
self.assertEqual(pt1.longitude, 1)
self.assertEqual(pt1.latitude, 2)
self.assertEqual(pt1.altitude, 3)
pt2 = kml.Point(coordinates=kml.Coordinate(1,2,3))
self.assertEqual(pt2.longitude, 1)
self.assertEqual(pt2.latitude, 2)
self.assertEqual(pt2.altitude, 3)
pt3 = kml.Point()
pt3.longitude = 1
pt3.latitude = 2
pt3.altitude = 3
self.assertEqual(pt3.longitude, 1)
self.assertEqual(pt3.latitude, 2)
self.assertEqual(pt3.altitude, 3)
self.assertRaises(TypeError, kml.Point, "", "10 W", 2, 3)
self.assertRaises(TypeError, kml.Point, "", 1, "10 N", 3)
self.assertRaises(TypeError, kml.Point, "", 1, 2, None)
self.cloneTest(pt1, self.verbose)

def testModel(self):
model = kml.Model(id="foo")
model.altitudeMode = kml.altitudeMode.clampToGround
model.Location = kml.Location(1, 2, 3)
model.Orientation = kml.Orientation(0, 45, 90)
model.Scale = kml.Scale(1, 1, 1)
model.Link = "models/model.dae"
model.ResourceMap = kml.ResourceMap()
model.ResourceMap.addAlias(kml.Alias("models/model.dae",
"/nas/Models/test/model.dae"))
self.assertEqual(model.altitudeMode, kml.altitudeMode.clampToGround)
self.assertEqual(model.Location.longitude, 1)
self.assertEqual(model.Location.latitude, 2)
self.assertEqual(model.Location.altitude, 3)
self.assertEqual(model.Orientation.heading, 0)
self.assertEqual(model.Orientation.tilt, 45)
self.assertEqual(model.Orientation.roll, 90)
self.assertEqual(model.Scale.x, 1)
self.assertEqual(model.Scale.y, 1)
self.assertEqual(model.Scale.z, 1)
self.assertEqual(model.Link.href, "models/model.dae")
self.assertEqual(model.ResourceMap.Aliases[0].sourceHref,
"models/model.dae")
self.assertEqual(model.ResourceMap.Aliases[0].targetHref,
"/nas/Models/test/model.dae")
self.cloneTest(model, self.verbose)






#--------------------------------------------------------------------------
# Time
#--------------------------------------------------------------------------

def testTimeStamp(self):
timestr = "2010-10"
timestamp = kml.TimeStamp("", 2010, 10)
self.assertEqual(str(timestamp), timestr)
del timestamp
timestamp = kml.TimeStamp()
timestamp.parseDate(timestr)
self.assertEqual(str(timestamp), timestr)
self.assertEqual(timestamp.hour, None)
self.assertEqual(timestamp.minute, None)
self.assertEqual(timestamp.second, None)
self.assertEqual(timestamp.month, 10)
timestamp.day = 3
timestr = "-".join([timestr, str(timestamp.day).zfill(2)])
self.assertEqual(str(timestamp), timestr)
timestamp.hour=0
self.assertEqual(timestamp.hour, 0)
self.assertEqual(timestamp.minute, 0)
self.assertEqual(timestamp.second, 0)
timestamp.minute = 30
timestamp.second = 15
self.assertEqual(timestamp.minute, 30)
self.assertEqual(timestamp.second, 15)
self.assertAssignRaises(ValueError, timestamp, "year", -1)
self.assertAssignRaises(ValueError, timestamp, "month", 13)
self.assertAssignRaises(ValueError, timestamp, "month", 0)
self.assertAssignRaises(ValueError, timestamp, "day", 32)
timestamp.month = 2
self.assertAssignRaises(ValueError, timestamp, "day", 29)
timestamp.month = 6
self.assertAssignRaises(ValueError, timestamp, "day", 31)
timestamp.month += 1
timestamp.day = 31
tzinfo = kml.UTCOffset(-5)
timestamp.tzinfo = tzinfo
timestamp.value = str(timestamp)
self.cloneTest(timestamp, self.verbose)

def testTimeSpan(self):
begin = kml.TimeStamp("", 2010, 1, 1)
end = kml.TimeStamp("", 2010, 12, 31)
timespan = kml.TimeSpan("", begin, end)
self.assertEqual(timespan.begin, begin)
self.assertEqual(timespan.end, end)
self.assertAssignSuccessful(timespan, "end", None)
self.assertAssignSuccessful(timespan, "end", end)
self.cloneTest(timespan, self.verbose)

#--------------------------------------------------------------------------
# Views
#--------------------------------------------------------------------------

def testLookAt(self):
view = kml.LookAt("foo", longitude=1, latitude=2, altitude=3,
tilt=45, heading=90, range=100000)
self.assertEqual(view.longitude, 1)
self.assertEqual(view.latitude, 2)
self.assertEqual(view.altitude, 3)
self.assertEqual(view.tilt, 45)
self.assertEqual(view.heading, 90)
self.assertEqual(view.range, 100000)
view.altitude=3
view.longitude=2
view.latitude=1
self.assertAssignRaises(ValueError, view, "latitude", 91)
self.assertAssignRaises(ValueError, view, "longitude", -181)
self.assertAssignRaises(TypeError, view, "latitude", "90 S")
self.assertAssignRaises(TypeError, view, "longitude", "90 W")
self.assertAssignRaises(TypeError, view, "altitude", "foo")
self.assertAssignRaises(ValueError, view, "tilt", 181)
self.assertAssignRaises(ValueError, view, "tilt", -1)
self.assertAssignRaises(TypeError, view, "tilt", "foo")
self.assertAssignRaises(ValueError, view, "heading", 361)
self.assertAssignRaises(ValueError, view, "heading", -1)
self.assertAssignRaises(TypeError, view, "heading", "foo")
self.assertAssignRaises(TypeError, view, "range", "foo")
self.cloneTest(view, self.verbose)

def testCamera(self):
view = kml.Camera("foo", coordinates=kml.Coordinate(1,2,3))
self.assertEqual(view.longitude, 1)
self.assertEqual(view.latitude, 2)
self.assertEqual(view.altitude, 3)
view = kml.Camera("foo", longitude=1, latitude=2, altitude=3,
tilt=45, heading=90, roll=10)
self.assertEqual(view.longitude, 1)
self.assertEqual(view.latitude, 2)
self.assertEqual(view.altitude, 3)
view.altitude=3
view.longitude=2
view.latitude=1
self.assertAssignRaises(ValueError, view, "latitude", 91)
self.assertAssignRaises(ValueError, view, "longitude", -181)
self.assertAssignRaises(TypeError, view, "latitude", "90 S")
self.assertAssignRaises(TypeError, view, "longitude", "90 W")
self.assertAssignRaises(TypeError, view, "altitude", "foo")
self.assertAssignRaises(ValueError, view, "tilt", 181)
self.assertAssignRaises(ValueError, view, "tilt", -1)
self.assertAssignRaises(TypeError, view, "tilt", "foo")
self.assertAssignRaises(ValueError, view, "heading", 361)
self.assertAssignRaises(ValueError, view, "heading", -1)
self.assertAssignRaises(TypeError, view, "heading", "foo")
self.assertAssignRaises(ValueError, view, "roll", -181)
self.assertAssignRaises(ValueError, view, "roll", 181)
self.cloneTest(view, self.verbose)

#--------------------------------------------------------------------------
# Features
#--------------------------------------------------------------------------

def testPlacemark(self):
point = kml.Point("foo", 1,2,3)
view = kml.LookAt("foo", coordinates=kml.Coordinate(1,2,3), range=100000)
placemark = kml.Placemark(id="foo",
geometry=point,
name = "foobar",
description = "Not very descriptive :-).",
visibility = False,
open = True,
view = view)
self.assertEqual(placemark.Geometry, point)
self.assertEqual(placemark.View, view)
self.assertEqual(placemark.visibility, False)
self.assertEqual(placemark.open, True)
self.assertEqual(placemark.address, "")
self.assertEqual(placemark.name, "foobar")
self.assertEqual(placemark.Snippet, None)
snippet=kml.Snippet(value="Some snippet of information.")
view = kml.LookAt("foo2", coordinates=kml.Coordinate(3,2,1), range=200000)
self.assertAssignSuccessful(placemark, "Snippet", snippet)
self.assertAssignSuccessful(placemark, "name", "newname")
self.assertAssignSuccessful(placemark, "description", "Still not very descriptive.")
self.assertAssignSuccessful(placemark, "visibility", True)
self.assertAssignSuccessful(placemark, "open", False)
self.assertAssignSuccessful(placemark, "view", view)
self.cloneTest(placemark, self.verbose)

def testDocument(self):
document = kml.Document()
document.name = "My Document"
document.description = "Some description"
#comments currently break cloneTest
#document.comments = ["Foo"]
view = kml.LookAt("foo", longitude=1, latitude=2, altitude=3,
tilt=45, heading=90, range=100000)
placemark = kml.Placemark(id="foo",
geometry=kml.Point("", 1, 2, 3),
name = "foobar",
description = "Not very descriptive.",
visibility = False,
open = True,
view = kml.LookAt("bar", longitude=4, latitude=5,
altitude=6))
iconStyle = kml.IconStyle()
iconStyle.scale = 0.75
iconStyle.heading = 0
iconStyle.Icon = kml.Icon(href="1.png")
iconStyle.color = 0xffffffff
style = kml.Style()
style.IconStyle = iconStyle
document.addStyle(style)
document.addChildFeature(placemark)
self.assertEqual(placemark, document.children[0])
document.View = view
self.cloneTest(document, self.verbose)

def testFolder(self):
folder = kml.Folder()
folder.name = "My Folder"
folder.description = "Some description"
#comments currently break cloneTest
#folder.comments = ["Foo"]
view = kml.LookAt("foo2", longitude=1, latitude=2, altitude=3,
tilt=45, heading=90, range=100000)
placem = kml.Placemark(id="foo",
geometry=kml.Point("", 1, 2, 3),
name = "foobar",
description = "Not very descriptive.",
visibility = False,
open = True,
view = kml.LookAt("bar", longitude=4, latitude=5,
altitude=6))
iconStyle = kml.IconStyle()
iconStyle.scale = 0.75
iconStyle.heading = 0
iconStyle.Icon = kml.Icon(href="1.png")
iconStyle.color = 0xffffffff
style = kml.Style()
style.IconStyle = iconStyle
folder.addStyle(style)
folder.addChildFeature(placem)
self.assertEqual(placem, folder.children[0])
folder.View = view
self.cloneTest(folder, self.verbose)

def testNetworkLink(self):
networkLink = kml.NetworkLink()
networkLink.flyToView = True
networkLink.refreshVisibility = True
networkLink.Link = "http://example.com/foo"
self.assertEqual(networkLink.flyToView, True)
self.assertEqual(networkLink.refreshVisibility, True)
self.assertEqual(networkLink.Link.href, "http://example.com/foo")
self.cloneTest(networkLink, self.verbose)



if __name__ == "__main__":
#import sys;sys.argv = ['', 'Test.testName']
unittest.main()

Change log

faa2c5f08073 by Rob Shinn <rob.shinn> on Oct 6, 2010   Diff
update docstring of
testsuite.unittests.cloneTest to reflect
recently surfaced bugs in lists containing
object instances.
Go to: 
Project members, sign in to write a code review

Older revisions

649963d981e2 by Rob Shinn <rob.shinn> on Oct 6, 2010   Diff
- fixed major bugs in Feature relating
to child tags leaking into the parent.
- finally added parsing in
Feature.parseKMLNode for all support
elements of Feature
d2e44bcdccea by Rob Shinn <rob.shinn> on Oct 5, 2010   Diff
fix bug found in kml.Container
relating to self.children where new
instances of subclasses would get data
leaked through from previous
instances.
98930df82db4 by Rob Shinn <rob.shinn> on Oct 5, 2010   Diff
clean up Container
All revisions of this file

File info

Size: 28123 bytes, 673 lines
Powered by Google Project Hosting