File size: 2,384 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | # -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals
from contextlib import closing
import io
import os.path
import shutil
from hwp5.hwp5html import HTMLTransform
from hwp5.plat import get_xslt
from hwp5.storage.fs import FileSystemStorage
from . import test_xmlmodel
class TestBase(test_xmlmodel.TestBase):
def make_base_dir(self):
base_dir = self.id()
if os.path.exists(base_dir):
shutil.rmtree(base_dir)
os.mkdir(base_dir)
return base_dir
class HtmlConvTest(TestBase):
@property
def xslt(self):
return get_xslt()
@property
def xhwp5_path(self):
return self.id() + '.xhwp5'
@property
def transform(self):
return HTMLTransform()
def create_xhwp5(self):
xhwp5_path = self.xhwp5_path
with io.open(xhwp5_path, 'wb') as xhwp5_file:
self.hwp5file.xmlevents(embedbin=False).dump(xhwp5_file)
return xhwp5_path
def test_generate_css_file(self):
base_dir = self.make_base_dir()
css_path = os.path.join(base_dir, 'styles.css')
with closing(self.hwp5file) as hwp5file:
with io.open(css_path, 'wb+') as f:
self.transform.transform_hwp5_to_css(hwp5file, f)
def test_generate_html_file(self):
base_dir = self.make_base_dir()
html_path = os.path.join(base_dir, 'index.xhtml')
with closing(self.hwp5file) as hwp5file:
with io.open(html_path, 'wb+') as f:
self.transform.transform_hwp5_to_xhtml(hwp5file, f)
def test_extract_bindata_dir(self):
base_dir = self.make_base_dir()
hwp5file = self.hwp5file
bindata_dir = os.path.join(base_dir, 'bindata')
self.transform.extract_bindata_dir(hwp5file, bindata_dir)
bindata_stg = hwp5file['BinData']
self.assertEqual(set(bindata_stg),
set(FileSystemStorage(bindata_dir)))
def test_extract_bindata_dir_without_bindata(self):
self.hwp5file_name = 'charshape.hwp'
base_dir = self.make_base_dir()
hwp5file = self.hwp5file
bindata_dir = os.path.join(base_dir, 'bindata')
self.transform.extract_bindata_dir(hwp5file, bindata_dir)
self.assertFalse(os.path.exists(bindata_dir))
|