Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/prov/tests/utility.py @ 0:26e78fe6e8c4 draft
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
| author | shellac |
|---|---|
| date | Sat, 02 May 2020 07:14:21 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:26e78fe6e8c4 |
|---|---|
| 1 from __future__ import (absolute_import, division, print_function, | |
| 2 unicode_literals) | |
| 3 | |
| 4 import io | |
| 5 import logging | |
| 6 import unittest | |
| 7 | |
| 8 from prov.model import ProvDocument | |
| 9 | |
| 10 | |
| 11 logger = logging.getLogger(__name__) | |
| 12 | |
| 13 | |
| 14 class DocumentBaseTestCase(unittest.TestCase): | |
| 15 def do_tests(self, prov_doc, msg=None): | |
| 16 pass | |
| 17 | |
| 18 | |
| 19 class RoundTripTestCase(DocumentBaseTestCase): | |
| 20 """A serializer test should subclass this class and set the class property | |
| 21 FORMAT to the correct value (e.g. 'json', 'xml', 'rdf'). | |
| 22 """ | |
| 23 FORMAT = None # a subclass should change this | |
| 24 | |
| 25 def do_tests(self, prov_doc, msg=None): | |
| 26 self.assertRoundTripEquivalence(prov_doc, msg) | |
| 27 | |
| 28 def assertRoundTripEquivalence(self, prov_doc, msg=None): | |
| 29 if self.FORMAT is None: | |
| 30 # This is a dummy test, just return | |
| 31 return | |
| 32 | |
| 33 with io.BytesIO() as stream: | |
| 34 prov_doc.serialize(destination=stream, format=self.FORMAT, indent=4) | |
| 35 stream.seek(0, 0) | |
| 36 | |
| 37 prov_doc_new = ProvDocument.deserialize(source=stream, | |
| 38 format=self.FORMAT) | |
| 39 stream.seek(0, 0) | |
| 40 # Assume UTF-8 encoding which is forced by the particular | |
| 41 # PROV XML implementation and should also work for the PROV | |
| 42 # JSON implementation. | |
| 43 msg_extra = u"'%s' serialization content:\n%s" % ( | |
| 44 self.FORMAT, stream.read().decode("utf-8")) | |
| 45 msg = u'\n'.join((msg, msg_extra)) if msg else msg_extra | |
| 46 self.assertEqual(prov_doc, prov_doc_new, msg) |
