Skip to content

Commit

Permalink
test: Test DatatrackerToBibConverter
Browse files Browse the repository at this point in the history
  • Loading branch information
kesara committed Nov 28, 2024
1 parent db42593 commit 053bae3
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from xml2rfc.boilerplate_rfc_7841 import boilerplate_rfc_status_of_memo
from xml2rfc.walkpdf import xmldoc
from xml2rfc.writers.base import default_options, BaseV3Writer, RfcWriterError
from xml2rfc.writers import DatatrackerToBibConverter
from xml2rfc.writers.text import MAX_WIDTH

try:
Expand Down Expand Up @@ -847,5 +848,39 @@ def test_validate_draft_name(self):
self.writer.validate_draft_name()


class DatatrackerToBibConverterTest(unittest.TestCase):
"""DatatrackerToBibConverter tests"""

def setUp(self):
xml2rfc.log.quiet = True
path = "tests/input/elements.xml"
self.parser = xml2rfc.XmlRfcParser(path,
quiet=True,
options=default_options,
**options_for_xmlrfcparser)
self.xmlrfc = self.parser.parse()
self.writer = xml2rfc.DatatrackerToBibConverter(self.xmlrfc, quiet=True)

def test_convert(self):
reference_a = "reference.I-D.ietf-sipcore-multiple-reasons.xml"
reference_b = "reference.I-D.draft-ietf-sipcore-multiple-reasons-01.xml"
rfc = lxml.etree.fromstring(f"""
<rfc xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="https://datatracker.ietf.org/doc/bibxml3/{reference_a}"/>
<xi:include href="https://datatracker.ietf.org/doc/bibxml3/{reference_b}"/>
</rfc>""")
self.writer.root = rfc
self.writer.convert_xincludes()

ns = {"xi": b"http://www.w3.org/2001/XInclude"}
xincludes = self.writer.root.xpath("//xi:include", namespaces=ns)

# reference without revision
self.assertEqual(xincludes[0].get("href"), f"https://bib.ietf.org/public/rfc/bibxml-ids/{reference_a}")

# reference with revision
self.assertEqual(xincludes[1].get("href"), f"https://bib.ietf.org/public/rfc/bibxml-ids/{reference_b}")


if __name__ == '__main__':
unittest.main()

0 comments on commit 053bae3

Please sign in to comment.