Skip to content

Commit

Permalink
to_marc21: fix xslt transform
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Rossi <leonardo.r@cern.ch>
  • Loading branch information
Leonardo Rossi committed Feb 2, 2016
1 parent 21d4c2d commit 5dc3e05
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dojson/contrib/to_marc21/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def dumps_etree(records, xslt_filename=None):
if xslt_filename is not None:
xslt_root = etree.parse(open(xslt_filename))
transform = etree.XSLT(xslt_root)
root = transform(root)
root = transform(root).getroot()

return root

Expand Down
20 changes: 19 additions & 1 deletion tests/test_contrib_to_marc21_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
import os

import pkg_resources
from lxml import etree
from lxml.etree import _Element

import pytest
from click.testing import CliRunner
from dojson.contrib.marc21.utils import load
from dojson.contrib.to_marc21.utils import dumps
from dojson.contrib.to_marc21.utils import dumps, dumps_etree
from test_core import RECORD_SIMPLE


Expand Down Expand Up @@ -55,3 +57,19 @@ def test_entry_points():
output = dump(data,
xslt_filename='{0}/demo_marc21_to_dc.xslt'.format(path))
assert output.decode('utf-8') == expect


def test_output_type_from_dumps_etree():
"""Test output type from dumps_etree."""
path = os.path.dirname(__file__)
data = list(load('{0}/demo_marc21_to_dc.xml'.format(path)))
# test without arguments
output1 = dumps_etree(data)
# test with xslt_filename argument
output2 = dumps_etree(
data,
xslt_filename='{0}/demo_marc21_to_dc.xslt'.format(path)
)
# it should not generate a TypeError exception
assert isinstance(output1, _Element)
assert isinstance(output2, _Element)

0 comments on commit 5dc3e05

Please sign in to comment.