Skip to content

Commit

Permalink
Use OrderedDict to represent Params instead of plain dict.
Browse files Browse the repository at this point in the history
Preserves ordering from the XML which may be desirable.
  • Loading branch information
timstaley committed Jan 21, 2016
1 parent 4b74662 commit 88e3ce9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name="voevent-parse",
version="0.9.1",
version="0.9.2",
packages=['voeventparse', 'voeventparse.tests', 'voeventparse.tests.resources'],
package_data={'voeventparse':['tests/resources/*.xml']},
description="Convenience routines for parsing and manipulation of "
Expand Down
5 changes: 3 additions & 2 deletions voeventparse/convenience.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import absolute_import
import iso8601
import lxml
from collections import OrderedDict
from voeventparse.misc import (Param, Group, Reference, Inference, Position2D,
Citation)

Expand Down Expand Up @@ -105,11 +106,11 @@ def pull_params(voevent):
what_dict[None]['ParamName']['value']
"""
result = {}
result = OrderedDict()
w = voevent.What
if w.countchildren() == 0:
return result
toplevel_params = {}
toplevel_params = OrderedDict()
result[None] = toplevel_params
if hasattr(voevent.What, 'Param'):
for p in voevent.What.Param:
Expand Down
10 changes: 7 additions & 3 deletions voeventparse/tests/test_voeventparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,17 @@ def test_pull_astro_coords(self):
self.assertIsInstance(p.ra, float)

def test_pull_params(self):
params = vp.pull_params(self.swift_grb_v2_packet)
swift_params = vp.pull_params(self.swift_grb_v2_packet)

#General example, check basic functionality
self.assertEqual(params[None]['Packet_Type']['value'], '61')
self.assertEqual(params['Misc_Flags']['Values_Out_of_Range']['value'],
self.assertEqual(swift_params[None]['Packet_Type']['value'], '61')
self.assertEqual(swift_params['Misc_Flags']['Values_Out_of_Range']['value'],
'false')

#Check ordering is preserved
self.assertEqual(list(swift_params[None].keys())[:3],
['Packet_Type', 'Pkt_Ser_Num', 'TrigID'])

#Test empty What section
params = vp.pull_params(self.blank)
self.assertEqual(params, {})
Expand Down

0 comments on commit 88e3ce9

Please sign in to comment.