1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import os
25 import tempfile
26 import unittest
27
28 import xml.etree.ElementTree as et
29
30 from utils import *
31
33
35 self.lax_lat = 33.0 + (57.0 / 60.0)
36 self.lax_lon = -(118.0 + (24.0 / 60.0))
37
38 self.jfk_lat = 40.0 + (38.0 / 60.0)
39 self.jfk_lon = -(73.0 + (47.0 / 60.0))
40
46
48 new_pt = pt_dist_from_pt(self.lax_lat, self.lax_lon,
49 100.0 * nm_to_statute, 65.8921517923)
50 self.assertAlmostEqual(new_pt[0], 34.0 + (37.0 / 60.0), 3)
51 self.assertAlmostEqual(new_pt[1], -(116.0 + (33.0 / 60.0)), 2)
52
54 new_pt = pt_dist_from_pt(29.738246, -98.103823, 1.0, 0.0)
55 self.assertAlmostEqual(new_pt[0], 29.752728937365013)
56 self.assertAlmostEqual(new_pt[1], -98.103822999999977)
57
59 new_pt = pt_dist_from_pt(29.738246, -98.103823, 1.0, 90.0)
60 self.assertAlmostEqual(new_pt[0], 29.738244954303006)
61 self.assertAlmostEqual(new_pt[1], -98.087143364652249)
62
64 new_pt = pt_dist_from_pt(29.738246, -98.103823, 1.0, 180.0)
65 self.assertAlmostEqual(new_pt[0], 29.72376306263499)
66 self.assertAlmostEqual(new_pt[1], -98.103822999999977)
67
69 new_pt = pt_dist_from_pt(29.738246, -98.103823, 1.0, 270.0)
70 self.assertAlmostEqual(new_pt[0], 29.738244954303006)
71 self.assertAlmostEqual(new_pt[1], -98.120502635347805)
72
74
76 sabx_valid = """<?xml version='1.0' encoding='utf-8'?>
77 <rideset xmlns="http://www.sabikerides.com/SABX/1/0/"
78 version="1.0">
79
80 <uuid>147dbb84-d109-44f7-9ac2-09b2a736993f</uuid>
81 <version>1</version>
82 <zip_prefix>781</zip_prefix>
83
84 <ride_type>road</ride_type>
85 <title>Tour de Gruene 2009 Tour</title>
86 <description><p>This is the tour route for the 2009 Tour de Gruene.
87 The time trial courses will have their own map.
88 Please note that the stops listed on this map are not the official
89 rest areas for the ride. Those will come later. For now I have
90 included the stops you would use if you did the ride on your own.</p>
91 <p>Check out the <a href="http://www.tourdegruene.com/">Tour de Gruene
92 web site</a> for more information.</p>
93 </description>
94 <terrain>Flat</terrain>
95
96 <segment id='2'>
97 <road>Gruene Rd.</road>
98 <fromto>parking to Hunter Rd.</fromto>
99 <comments>Gruene Hall is on your left.</comments>
100 <lanes>2</lanes>
101 <shoulder>0</shoulder>
102 <traffic>Moderate</traffic>
103 <speed>20</speed>
104 <waypoint id='6'>
105 <lat>29.738246</lat>
106 <lon>-98.103823</lon>
107 <ele>213.6</ele>
108 <usgs>206.44480896</usgs>
109 </waypoint>
110 <waypoint id='7'>
111 <lat>29.738285</lat>
112 <lon>-98.103958</lon>
113 <ele>213.1</ele>
114 <usgs>206.279098511</usgs>
115 </waypoint>
116 <waypoint id='8'>
117 <lat>29.738286</lat>
118 <lon>-98.103996</lon>
119 <ele>212.6</ele>
120 <usgs>206.126815796</usgs>
121 </waypoint>
122 <waypoint id='9' stop='0a'>
123 <lat>29.738416</lat>
124 <lon>-98.10415</lon>
125 <ele>212.6</ele>
126 <usgs>205.945068359</usgs>
127 </waypoint>
128 </segment>
129 </rideset>"""
130
131 sabx_invalid_version = """<?xml version='1.0' encoding='utf-8'?>
132 <rideset xmlns="http://www.sabikerides.com/SABX/1/0/"
133 version="2.0">
134 <uuid>147dbb84-d109-44f7-9ac2-09b2a736993f</uuid>
135 </rideset>"""
136
137 self.file_valid = tempfile.TemporaryFile(mode='w+')
138 self.file_valid.write(sabx_valid)
139 self.file_valid.seek(0, os.SEEK_SET)
140
141 self.file_invalid_version = tempfile.TemporaryFile(mode='w+')
142 self.file_invalid_version.write(sabx_invalid_version)
143 self.file_invalid_version.seek(0, os.SEEK_SET)
144
148
152
157
162
164 full_tree = et.parse(self.file_valid)
165 self.file_valid.seek(0, os.SEEK_SET)
166 no_namespace_tree = parse_no_def_namespaces(self.file_valid)
167
168 self.assert_(
169 full_tree.findtext(
170 '{http://www.sabikerides.com/SABX/1/0/}title'))
171 self.assertFalse(
172 no_namespace_tree.findtext(
173 '{http://www.sabikerides.com/SABX/1/0/}title'))
174
176 full_tree = et.parse(self.file_valid)
177 self.file_valid.seek(0, os.SEEK_SET)
178 no_namespace_tree = parse_no_def_namespaces(self.file_valid)
179
180 self.assertFalse(full_tree.findtext('title'))
181 self.assert_(no_namespace_tree.findtext('title'))
182
183 if __name__ == "__main__":
184 unittest.main()
185