Package sabx10 :: Package oxm :: Module parse_test
[hide private]
[frames] | no frames]

Source Code for Module sabx10.oxm.parse_test

  1  #! /usr/bin/python 
  2  ############################################################################### 
  3  # 
  4  # sabx10.oxm - an SABX file manipulation library 
  5  # Copyright (C) 2009, 2010 Jay Farrimond (jay@sabikerides.com) 
  6  # 
  7  # This file is part of sabx10.oxm. 
  8  # 
  9  # sabx10.oxm is free software: you can redistribute it and/or modify it under 
 10  # the terms of the GNU Lesser General Public License as published by the Free 
 11  # Software Foundation, either version 3 of the License, or (at your option) any 
 12  # later version. 
 13  # 
 14  # sabx10.oxm is distributed in the hope that it will be useful, but WITHOUT ANY 
 15  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 
 16  # A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more 
 17  # details. 
 18  # 
 19  # You should have received a copy of the GNU Lesser General Public License 
 20  # along with sabx10.oxm.  If not, see <http://www.gnu.org/licenses/>. 
 21  # 
 22  ############################################################################### 
 23   
 24  import os 
 25  import tempfile 
 26  import unittest 
 27   
 28  from utils import parse_no_def_namespaces 
 29   
 30  from parse_test_data import test_data 
 31  from parse import * 
 32   
33 -class TestParse(unittest.TestCase):
34
35 - def setUp(self):
36 file_valid = tempfile.TemporaryFile(mode='w+') 37 file_valid.write(test_data) 38 file_valid.seek(0, os.SEEK_SET) 39 self.tree = parse_no_def_namespaces(file_valid)
40
41 - def test_parse_tree(self):
42 sabx = parse_tree(self.tree) 43 44 # top level 45 self.assertEquals(sabx['uuid'], "147dbb84-d109-44f7-9ac2-09b2a736993f") 46 self.assertEquals(sabx['version'], "1") 47 self.assertEquals(sabx['zip_prefix'], "781") 48 self.assertEquals(sabx['ride_type'], "road") 49 self.assertEquals(sabx['title'], "Tour de Gruene 2009 Tour") 50 self.assertEquals(sabx['description'][:20], "<p>This is the tour ") 51 self.assertEquals(sabx['terrain'], "Flat") 52 53 # history 54 self.assertEquals(len(sabx['history']), 3) 55 self.assertEquals(sabx['history'][0].version, '1') 56 self.assertEquals(sabx['history'][0].date, '2009-06-03') 57 self.assertEquals(sabx['history'][0].description, 58 'Created short loop east of town.') 59 60 # photos 61 self.assertEquals(sabx['photos'].title, 'Returning via River Rd.') 62 self.assertEquals( 63 sabx['photos'].src, 64 'http://farm4.static.flickr.com/3352/3639773356_2435f78398_m.jpg') 65 self.assertEquals(len(sabx['photos'].photo_list), 1) 66 self.assertEquals(sabx['photos'].photo_list[0].desc, 67 '2009-06-07 Gruene') 68 self.assertEquals( 69 sabx['photos'].photo_list[0].href, 70 'http://www.flickr.com/photos/sabikerides/sets/72157619945875214/') 71 72 # parking 73 self.assertEquals(len(sabx['park_list']), 1) 74 self.assertEquals(sabx['park_list'][0].id, '1') 75 self.assertEquals(sabx['park_list'][0].description[:20], 76 'Gruene has plenty of') 77 self.assertEquals(sabx['park_list'][0].lat, 29.737931) 78 self.assertEquals(sabx['park_list'][0].lon, -98.103585) 79 80 # turns 81 self.assertEquals(len(sabx['turn_list']), 53) 82 self.assertEquals(sabx['turn_list'][0].id, '1') 83 self.assertEquals(sabx['turn_list'][0].fromto, 'parking to Hunter Rd.') 84 self.assertEquals(sabx['turn_list'][0].cue, 'RIGHT onto Gruene Rd.') 85 self.assertEquals( 86 sabx['turn_list'][0].comments, 87 'From the parking lot, turn right onto Gruene Rd.') 88 89 # segments 90 self.assertEquals(len(sabx['seg_list']), 53) 91 self.assertEquals(sabx['seg_list'][0].id, '2') 92 self.assertEquals(sabx['seg_list'][0].road, 'Gruene Rd.') 93 self.assertEquals(sabx['seg_list'][0].fromto, 'parking to Hunter Rd.') 94 self.assertEquals( 95 sabx['seg_list'][0].comments, 96 'Gruene Hall is on your left.') 97 self.assertEquals(sabx['seg_list'][0].lanes, '2') 98 self.assertEquals(sabx['seg_list'][0].shoulder, '0') 99 self.assertEquals(sabx['seg_list'][0].traffic, 'Moderate') 100 self.assertEquals(sabx['seg_list'][0].speed, '20') 101 102 # waypoints 103 self.assertEquals(len(sabx['seg_list'][0].waypoints), 4) 104 self.assertEquals(sabx['seg_list'][0].waypoints[0].id, '6') 105 self.assertEquals(sabx['seg_list'][0].waypoints[0].lat, 29.738246) 106 self.assertEquals(sabx['seg_list'][0].waypoints[0].lon, -98.103823) 107 self.assertEquals(sabx['seg_list'][0].waypoints[0].ele, 213.6) 108 self.assertEquals(sabx['seg_list'][0].waypoints[0].usgs, 206.44480896) 109 110 # stops 111 self.assertEquals(len(sabx['stop_list']), 13) 112 self.assertEquals(sabx['stop_list'][0].id, '0a') 113 self.assertEquals(sabx['stop_list'][0].type, 'conv. store') 114 self.assertEquals(sabx['stop_list'][0].description[:20], 115 'There are many bars ') 116 self.assertEquals(sabx['stop_list'][0].lat, 29.738416) 117 self.assertEquals(sabx['stop_list'][0].lon, -98.10415) 118 119 # pois 120 self.assertEquals(len(sabx['poi_list']), 7) 121 self.assertEquals(sabx['poi_list'][0].id, '1') 122 self.assertEquals(sabx['poi_list'][0].description[:20], 123 'The local land-fill ') 124 self.assertEquals(sabx['poi_list'][0].lat, 29.742733333) 125 self.assertEquals(sabx['poi_list'][0].lon, -98.0301) 126 127 # rides 128 self.assertEquals(len(sabx['ride_list']), 4) 129 self.assertEquals(sabx['ride_list'][0].id, '1') 130 self.assertEquals(sabx['ride_list'][0].description[:20], 131 'The short loop takes') 132 self.assertEquals(sabx['ride_list'][0].parking, '1') 133 self.assertEquals(len(sabx['ride_list'][0].turns), 18) 134 self.assertEquals(sabx['ride_list'][0].turns[0], '1') 135 self.assertEquals(len(sabx['ride_list'][0].segs), 18) 136 self.assertEquals(sabx['ride_list'][0].segs[0], '2')
137
138 - def test_process_ride(self):
139 pass
140 141 if __name__ == "__main__": 142 unittest.main() 143