forked from vkurup/python-tcxparser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_tcxparser.py
124 lines (94 loc) · 3.85 KB
/
test_tcxparser.py
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
from StringIO import StringIO
import unittest
from tcxparser import TCXParser
class TestParseTCX(unittest.TestCase):
def setUp(self):
tcx_file = 'test.tcx'
self.tcx = TCXParser(tcx_file)
def test_hr_values_are_correct(self):
self.assertEquals(self.tcx.hr_values()[0], 62)
self.assertEquals(self.tcx.hr_values()[-1], 180)
def test_altitude_points_are_correct(self):
self.assertEquals(self.tcx.altitude_points()[0], 178.942626953)
self.assertEquals(self.tcx.altitude_points()[-1], 166.4453125)
def test_time_values_are_correct(self):
self.assertEquals(self.tcx.time_values()[0], '2012-12-26T21:29:53Z')
self.assertEquals(self.tcx.time_values()[-1], '2012-12-26T22:03:05Z')
def test_latitude_is_correct(self):
self.assertEquals(self.tcx.latitude, 35.951880198)
def test_longitude_is_correct(self):
self.assertEquals(self.tcx.longitude, -79.0931872185)
def test_activity_type_is_correct(self):
self.assertEquals(self.tcx.activity_type, 'running')
def test_completion_time_is_correct(self):
self.assertEquals(self.tcx.completed_at, '2012-12-26T22:03:05Z')
def test_distance_is_correct(self):
self.assertEquals(self.tcx.distance, 4686.31103516)
def test_distance_units_is_correct(self):
self.assertEquals(self.tcx.distance_units, 'meters')
def test_duration_is_correct(self):
self.assertEquals(self.tcx.duration, 1992.78)
def test_calories_is_correct(self):
self.assertEquals(self.tcx.calories, 379)
def test_hr_max(self):
self.assertEquals(self.tcx.hr_max, 189)
def test_hr_min(self):
self.assertEquals(self.tcx.hr_min, 60)
def test_hr_avg(self):
self.assertEquals(self.tcx.hr_avg, 156)
def test_pace(self):
self.assertEquals(self.tcx.pace, '07:05')
def test_altitude_avg_is_correct(self):
self.assertAlmostEqual(self.tcx.altitude_avg, 172.020056184)
def test_altitude_max_is_correct(self):
self.assertAlmostEqual(self.tcx.altitude_max, 215.95324707)
def test_altitude_min_is_correct(self):
self.assertAlmostEqual(self.tcx.altitude_min, 157.793579102)
def test_ascent_is_correct(self):
self.assertAlmostEqual(self.tcx.ascent, 153.80981445)
def test_descent_is_correct(self):
self.assertAlmostEqual(self.tcx.descent, 166.307128903)
class BugTest(unittest.TestCase):
def test_single_trackpoint_in_track_is_ok(self):
"https://github.com/vkurup/python-tcxparser/issues/9"
xml = """
<TrainingCenterDatabase xmlns="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2">
<Activities>
<Activity>
<Lap>
<Track>
<Trackpoint>
<DistanceMeters>5</DistanceMeters>
</Trackpoint>
</Track>
</Lap>
</Activity>
</Activities>
</TrainingCenterDatabase>
"""
tcx_file = StringIO(xml)
tcx = TCXParser(tcx_file)
self.assertEqual(tcx.distance, 5)
def test_no_error_if_no_position(self):
"https://github.com/vkurup/python-tcxparser/issues/11"
xml = """
<TrainingCenterDatabase xmlns="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2">
<Activities>
<Activity>
<Lap>
<Track>
<Trackpoint>
<DistanceMeters>5</DistanceMeters>
</Trackpoint>
</Track>
</Lap>
</Activity>
</Activities>
</TrainingCenterDatabase>
"""
tcx_file = StringIO(xml)
tcx = TCXParser(tcx_file)
self.assertEqual(tcx.latitude, None)
self.assertEqual(tcx.longitude, None)
if __name__ == '__main__':
unittest.main()