2017-05-27 20:32:50 +01:00
|
|
|
import unittest
|
2017-05-27 16:43:23 +01:00
|
|
|
import os
|
2017-05-28 14:11:35 +01:00
|
|
|
from md_pdf.consts import TEMPLATES_DIR, STATIC_DIR
|
2017-06-01 22:04:21 +01:00
|
|
|
from md_pdf.build.templates import FILE_NAME_FORMAT
|
2017-05-28 22:12:22 +01:00
|
|
|
from bs4 import BeautifulSoup
|
2017-05-27 16:37:10 +01:00
|
|
|
|
|
|
|
|
2017-05-27 20:32:50 +01:00
|
|
|
class BaseTestCase(unittest.TestCase):
|
2017-05-28 16:58:58 +01:00
|
|
|
def setUp(self):
|
|
|
|
super().setUp()
|
|
|
|
self.BASE_VALID_CONFIG = {
|
|
|
|
'title': 'test title',
|
|
|
|
'input': 'test-files/*.md',
|
|
|
|
'output_formats': [
|
|
|
|
'html', 'pdf'
|
|
|
|
],
|
|
|
|
'output_dir': 'out/',
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-05-28 22:12:22 +01:00
|
|
|
def parse_html(self, html):
|
|
|
|
return BeautifulSoup(html, 'html.parser')
|
|
|
|
|
|
|
|
def remove_file(self, file):
|
2017-05-28 14:11:35 +01:00
|
|
|
try:
|
|
|
|
os.remove(file)
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
2017-06-01 22:04:21 +01:00
|
|
|
def touch_file(self, file):
|
|
|
|
open(file, 'w').close()
|
|
|
|
|
|
|
|
def create_fake_templates(self):
|
|
|
|
for template in [
|
|
|
|
'header',
|
|
|
|
'footer',
|
|
|
|
'cover'
|
|
|
|
]:
|
|
|
|
self.touch_file(FILE_NAME_FORMAT.format(template))
|
|
|
|
|
2017-05-28 22:19:45 +01:00
|
|
|
def extend_config(self, *args):
|
|
|
|
base_config = self.BASE_VALID_CONFIG.copy()
|
|
|
|
for arg in args:
|
|
|
|
base_config = dict(base_config, **arg)
|
|
|
|
return base_config
|
|
|
|
|
2017-05-28 22:12:22 +01:00
|
|
|
def delete_templates(self):
|
2017-05-27 16:43:23 +01:00
|
|
|
for template in [
|
|
|
|
'header.html',
|
|
|
|
'footer.html',
|
|
|
|
'cover.html',
|
2017-05-28 14:11:35 +01:00
|
|
|
'toc.xsl',
|
2017-05-27 16:43:23 +01:00
|
|
|
]:
|
2017-05-28 22:12:22 +01:00
|
|
|
self.remove_file(os.path.join(TEMPLATES_DIR, template))
|
2017-05-27 16:43:23 +01:00
|
|
|
|
|
|
|
def tearDown(self):
|
2017-05-28 22:12:22 +01:00
|
|
|
self.delete_templates()
|
|
|
|
self.remove_file(os.path.join(STATIC_DIR, 'style.css'))
|
2017-05-28 14:11:35 +01:00
|
|
|
|
2017-06-01 22:04:21 +01:00
|
|
|
def call_to_args(self, call):
|
|
|
|
args = tuple(call.call_args)[0]
|
|
|
|
kwargs = tuple(call.call_args)[1]
|
|
|
|
return args, kwargs
|
|
|
|
|