From 77861da5cad9580b08624274b488ce0356477d9b Mon Sep 17 00:00:00 2001 From: Tim Staley Date: Tue, 3 May 2016 15:38:58 +0100 Subject: [PATCH] Minor bugfix when applying 'prettystr' to a voevent packet-root. 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. --- setup.py | 2 +- tox.ini | 1 + voeventparse/convenience.py | 2 ++ voeventparse/tests/test_voeventparse.py | 15 +++++++++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a2b88a9..020bdd4 100755 --- a/setup.py +++ b/setup.py @@ -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 " diff --git a/tox.ini b/tox.ini index 20a2436..c4d4953 100644 --- a/tox.ini +++ b/tox.ini @@ -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 diff --git a/voeventparse/convenience.py b/voeventparse/convenience.py index 31f43cc..8168d36 100644 --- a/voeventparse/convenience.py +++ b/voeventparse/convenience.py @@ -6,6 +6,7 @@ from collections import OrderedDict from voeventparse.misc import (Param, Group, Reference, Inference, Position2D, Citation) +from copy import deepcopy @@ -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) diff --git a/voeventparse/tests/test_voeventparse.py b/voeventparse/tests/test_voeventparse.py index 9d879cf..eeff308 100644 --- a/voeventparse/tests/test_voeventparse.py +++ b/voeventparse/tests/test_voeventparse.py @@ -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) \ No newline at end of file