Skip to content

Commit

Permalink
Incorporate changes from #16
Browse files Browse the repository at this point in the history
  • Loading branch information
vkurup committed Apr 25, 2018
1 parent b15053b commit dde51b2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
4 changes: 1 addition & 3 deletions tcxparser/tcxparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ def cadence_avg(self):
@property
def distance(self):
distance_values = self.root.findall('.//ns:DistanceMeters', namespaces={'ns': namespace})
if distance_values:
return distance_values[-1]
return 0
return distance_values[-1] if distance_values else 0

@property
def distance_units(self):
Expand Down
18 changes: 18 additions & 0 deletions tests/test_cycling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os
from unittest import TestCase

from tcxparser import TCXParser


class TestParseCyclingTCX(TestCase):

def setUp(self):
tcx_file = 'test2.tcx'
path = os.path.join(os.path.dirname(__file__), 'files', tcx_file)
self.tcx = TCXParser(path)

def test_cadence_max_is_correct(self):
self.assertEqual(self.tcx.cadence_max, 115)

def test_cadence_avg_is_correct(self):
self.assertEqual(self.tcx.cadence_avg, 82)
10 changes: 3 additions & 7 deletions tests/test_tcxparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from StringIO import StringIO
except ImportError:
from io import StringIO
import unittest
from unittest import TestCase

from tcxparser import TCXParser


class TestParseTCX(unittest.TestCase):
class TestParseTCX(TestCase):

def setUp(self):
tcx_file = 'test.tcx'
Expand Down Expand Up @@ -79,7 +79,7 @@ def test_descent_is_correct(self):
self.assertAlmostEqual(self.tcx.descent, 166.307128903)


class BugTest(unittest.TestCase):
class BugTest(TestCase):

def test_single_trackpoint_in_track_is_ok(self):
"https://github.com/vkurup/python-tcxparser/issues/9"
Expand Down Expand Up @@ -123,7 +123,3 @@ def test_no_error_if_no_position(self):
tcx = TCXParser(tcx_file)
self.assertEqual(tcx.latitude, None)
self.assertEqual(tcx.longitude, None)


if __name__ == '__main__':
unittest.main()

0 comments on commit dde51b2

Please sign in to comment.