From d231259627a26c0baade46d09ef89c24db9d6cf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <henrik@trineo.org> Date: Tue, 5 Jan 2021 15:27:01 +0100 Subject: [PATCH] ENH: Remove TransactionBenchmark from hased xml --- src/caosadvancedtools/cache.py | 19 +++++++++++++++---- unittests/test_cache.py | 20 ++++++++++++++++++-- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/caosadvancedtools/cache.py b/src/caosadvancedtools/cache.py index bde76abf..c255a00d 100644 --- a/src/caosadvancedtools/cache.py +++ b/src/caosadvancedtools/cache.py @@ -29,9 +29,8 @@ import os import sqlite3 from hashlib import sha256 -from lxml import etree - import caosdb as db +from lxml import etree def put_in_container(stuff): @@ -44,11 +43,23 @@ def put_in_container(stuff): return stuff +def cleanXML(xml): + # remove transaction benchmark + props = xml.findall('TransactionBenchmark') + + for prop in props: + parent = prop.find("..") + parent.remove(prop) + + return xml + + def get_pretty_xml(cont): cont = put_in_container(cont) + xml = cont.to_xml(local_serialization=True) + cleanXML(xml) - return etree.tounicode(cont.to_xml( - local_serialization=True), pretty_print=True) + return etree.tounicode(xml, pretty_print=True) class Cache(object): diff --git a/unittests/test_cache.py b/unittests/test_cache.py index 985ac15c..2d7b863f 100644 --- a/unittests/test_cache.py +++ b/unittests/test_cache.py @@ -26,8 +26,8 @@ from copy import deepcopy from tempfile import NamedTemporaryFile import caosdb as db - -from caosadvancedtools.cache import Cache +from caosadvancedtools.cache import Cache, cleanXML +from lxml import etree class CacheTest(unittest.TestCase): @@ -75,3 +75,19 @@ class CacheTest(unittest.TestCase): self.cache.insert_list(hashes, entities) self.assertEqual(self.cache.check_existing(hashes[0]), 1001) self.assertEqual(self.cache.check_existing(hashes[2]), 1003) + + def test_clean(self): + xml = etree.XML( + """\ + <Entities> + <TransactionBenchmark> + </TransactionBenchmark> + <RecordType id="110" name="Guitar"> + <Version id="eb8c7527980e598b887e84d055db18cfc3806ce6" head="true"/> + <Parent id="108" name="MusicalInstrument" flag="inheritance:OBLIGATORY,"/> + <Property id="106" name="electric" datatype="BOOLEAN" importance="RECOMMENDED" flag="inheritance:FIX"/> + </RecordType> + </Entities> +""") + cleanXML(xml) + assert len(xml.findall('TransactionBenchmark')) == 0 -- GitLab