Skip to content

Commit

Permalink
Minor bugfix when applying 'prettystr' to a voevent packet-root.
Browse files Browse the repository at this point in the history
The prettystr command applies the deannotate / cleanup_namespaces routines,
this conflicts with the namespace mangling we temporarily apply to
make objectify work nicely with VOEvents.

The fix is simple - we simply take a copy of the passed datastructure,
then deannotate and prettyprint that.
  • Loading branch information
timstaley committed May 3, 2016
1 parent fefbccc commit 77861da
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -4,7 +4,7 @@

setup(
name="voevent-parse",
version="0.9.3",
version="0.9.4",
packages=['voeventparse', 'voeventparse.tests', 'voeventparse.tests.resources'],
package_data={'voeventparse':['tests/resources/*.xml']},
description="Convenience routines for parsing and manipulation of "
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Expand Up @@ -15,5 +15,6 @@ deps =
deps=
sphinx
commands=
pip install -r documentation/requirements.txt
pip install -e .
sphinx-build -W -b html -d {envtmpdir}/doctrees documentation/source {envtmpdir}/html
2 changes: 2 additions & 0 deletions voeventparse/convenience.py
Expand Up @@ -6,6 +6,7 @@
from collections import OrderedDict
from voeventparse.misc import (Param, Group, Reference, Inference, Position2D,
Citation)
from copy import deepcopy



Expand Down Expand Up @@ -139,6 +140,7 @@ def prettystr(subtree):
Returns:
string: Prettyprinted string representation of the raw XML.
"""
subtree = deepcopy(subtree)
lxml.objectify.deannotate(subtree)
lxml.etree.cleanup_namespaces(subtree)
return lxml.etree.tostring(subtree, pretty_print=True)
Expand Down
15 changes: 15 additions & 0 deletions voeventparse/tests/test_voeventparse.py
Expand Up @@ -360,3 +360,18 @@ def test_pull_isotime(self):

null_result = vp.pull_isotime(self.blank)
self.assertIsNone(null_result)

class TestPrettyStr(TestCase):
def setUp(self):
with open(datapaths.swift_bat_grb_pos_v2, 'rb') as f:
self.swift_grb_v2_packet = vp.load(f)
def test_for_packet_mangling(self):
"""
Check that applying prettystr to a packet does not change it.
"""
self.assertTrue(vp.valid_as_v2_0(self.swift_grb_v2_packet))
before = vp.dumps(self.swift_grb_v2_packet)
vp.prettystr(self.swift_grb_v2_packet)
self.assertTrue(vp.valid_as_v2_0(self.swift_grb_v2_packet))
after = vp.dumps(self.swift_grb_v2_packet)
self.assertEqual(before,after)

0 comments on commit 77861da

Please sign in to comment.