Skip to content

Commit

Permalink
Test RML to PDF converter
Browse files Browse the repository at this point in the history
  • Loading branch information
Justas Sadzevicius committed Sep 30, 2022
1 parent e2b8b55 commit c8cee63
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def read(*rnames):


TESTS_REQUIRE = [
'mock',
'Pillow',
'coverage',
'zope.pagetemplate',
Expand Down
62 changes: 62 additions & 0 deletions src/z3c/rml/tests/test_rml2pdf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
##############################################################################
#
# Copyright (c) 2007 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTLAR PURPOSE.
#
##############################################################################
"""Test RML to PDF converter.
"""

import io
import unittest

import mock

from z3c.rml import rml2pdf


class RML2PDFTest(unittest.TestCase):

@mock.patch("z3c.rml.rml2pdf.go")
def test_main_minimal(self, go):
rml2pdf.main(["input.rml", "output.pdf"])
go.assert_called_with("input.rml", "output.pdf")

@mock.patch("z3c.rml.rml2pdf.go")
def test_main_all_args(self, go):
rml2pdf.main(["input.rml", "output.pdf", "./out/pdf/", "./out/dtd/"])
go.assert_called_with(
"input.rml", "output.pdf", "./out/pdf/", "./out/dtd/"
)

def test_go(self):
rml = """
<!DOCTYPE document SYSTEM "rml_1_0.dtd">
<document filename="test.pdf">
</document>
"""
rml2pdf.go(io.StringIO(rml))

def test_parseString(self):
rml = """
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE document SYSTEM "rml_1_0.dtd">
<document filename="test.pdf">
<template>
<pageTemplate id="main">
<frame id="first" x1="1in" y1="1in"
width="7in" height="9in"/>
</pageTemplate>
</template>
<story><para>Hello</para></story>
</document>
""".strip()
stream = rml2pdf.parseString(rml)
self.assertEqual(stream.read()[:8], b"%PDF-1.4")

0 comments on commit c8cee63

Please sign in to comment.