File size: 1,585 Bytes
3315103 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | # -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals
from unittest import TestCase
from contextlib import closing
from zipfile import ZipFile
from hwp5 import plat
from hwp5.hwp5odt import ODTTransform
from hwp5.hwp5odt import open_odtpkg
from hwp5.xmlmodel import Hwp5File
from .fixtures import get_fixture_path
def example_path(filename):
return get_fixture_path(filename)
def open_example(filename):
path = example_path(filename)
return closing(Hwp5File(path))
class TestPrecondition(TestCase):
def test_example(self):
with open_example('linespacing.hwp') as hwp5file:
assert hwp5file is not None
class TestODTTransform(TestCase):
@property
def odt_path(self):
return self.id() + '.odt'
@property
def transform(self):
xslt = plat.get_xslt_compile()
assert xslt is not None, 'no XSLT implementation is available'
relaxng = plat.get_relaxng_compile()
return ODTTransform(xslt, relaxng)
def test_convert_bindata(self):
with open_example('sample-5017.hwp') as hwp5file:
f = hwp5file['BinData']['BIN0002.jpg'].open()
try:
data1 = f.read()
finally:
f.close()
with open_odtpkg(self.odt_path) as odtpkg:
self.transform.transform_hwp5_to_package(hwp5file, odtpkg)
zf = ZipFile(self.odt_path)
data2 = zf.read('bindata/BIN0002.jpg')
self.assertEqual(data1, data2)
|