Skip to content

Commit

Permalink
Default version, 1.0 extension test, small bug
Browse files Browse the repository at this point in the history
Changed default output version to 1.1, added a unittest to verify no extensions are written in 1.0, found a small bug in the Email handling.
  • Loading branch information
nawagers committed Dec 14, 2017
1 parent 1776646 commit 6c0dfa2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gpxpy/gpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2564,7 +2564,7 @@ def to_xml(self, version=None, prettyprint=True):
if self.version:
version = self.version
else:
version = '1.0'
version = '1.1'

if version != '1.0' and version != '1.1':
raise GPXException('Invalid version %s' % version)
Expand Down
3 changes: 2 additions & 1 deletion gpxpy/gpxfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,11 @@ def from_xml(self, node, version):
A string containing the email address.
"""
email_node = node.find(self.tag)
if email_node is None:
return ''

email_id = email_node.get('id')
email_domain = email_node.get('domain')

return '{0}@{1}'.format(email_id, email_domain)

def to_xml(self, value, version, nsmap=None, prettyprint=True, indent=''):
Expand Down
42 changes: 42 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2917,6 +2917,48 @@ def test_write_read_extensions(self):
print("Reading Track Point Extension")
self.assertTrue(elements_equal(gpx.tracks[0].segments[0].points[0].extensions[0], root))

def test_no_10_extensions(self):
namespace = '{gpx.py}'
nsmap = {'ext' : namespace[1:-1]}
root = mod_etree.Element(namespace + 'tag')
root.text = 'text'
root.tail = 'tail'

gpx = mod_gpx.GPX()
gpx.nsmap = nsmap

print("Inserting Waypoint Extension")
gpx.waypoints.append(mod_gpx.GPXWaypoint())
gpx.waypoints[0].latitude = 5
gpx.waypoints[0].longitude = 10
gpx.waypoints[0].extensions.append(root)

print("Inserting Metadata Extension")
gpx.metadata_extensions.append(root)

print("Inserting GPX Extension")
gpx.extensions.append(root)

print("Inserting Route Extension")
gpx.routes.append(mod_gpx.GPXRoute())
gpx.routes[0].extensions.append(root)

print("Inserting Track Extension")
gpx.tracks.append(mod_gpx.GPXTrack())
gpx.tracks[0].extensions.append(root)

print("Inserting Track Segment Extension")
gpx.tracks[0].segments.append(mod_gpx.GPXTrackSegment())
gpx.tracks[0].segments[0].extensions.append(root)


print("Inserting Track Point Extension")
gpx.tracks[0].segments[0].points.append(mod_gpx.GPXTrackPoint(latitude=12, longitude=13))
gpx.tracks[0].segments[0].points[0].extensions.append(root)

xml = gpx.to_xml('1.0')
self.assertFalse('extension' in xml)


class LxmlTest(mod_unittest.TestCase):
@mod_unittest.skipIf(mod_os.environ.get('XMLPARSER')!="LXML", "LXML not installed")
Expand Down

0 comments on commit 6c0dfa2

Please sign in to comment.