def test_multiple_template(): ctx = Context() ctx.source_folder = Path('.').absolute() sub1 = Path('./sub1').absolute() sub1.mkdir() template_file1 = Path(sub1, 'template.tex').absolute() template_file1.touch() sub2 = Path(sub1, 'sub2').absolute() sub2.mkdir() template_file2 = Path(sub2, 'template.tex').absolute() template_file2.touch() sub3 = Path(sub2, 'sub3').absolute() sub3.mkdir() template_file3 = Path(sub3, 'template.tex').absolute() template_file3.touch() ctx.source_folder = Path(sub3).absolute() template.get_template(ctx) assert ctx.template_source == template_file3 template_file3.unlink() template.get_template(ctx) assert ctx.template_source == template_file2 template_file2.unlink() template.get_template(ctx) assert ctx.template_source == template_file1
def test_empty_settings(): ctx = Context() ctx.source_folder = Path('.').absolute() settings_ = Path('./settings.yml') settings_.write_text('', encoding='utf8') with pytest.raises(ConvertError): settings.get_settings(ctx)
def test_simple_template(): ctx = Context() ctx.source_folder = Path('.').absolute() template_file = Path('./template.tex').absolute() template_file.touch() template.get_template(ctx) assert ctx.template_source == template_file
def test_single_settings(): ctx = Context() ctx.source_folder = Path('.').absolute() settings_ = Path('./settings.yml') settings_.write_text('key: value') settings.get_settings(ctx) assert ctx.settings.data == {'key': 'value'}
def test_get_media_folder(): ctx = Context() ctx.source_folder = Path('.').absolute() media = Path('./media').absolute() media.mkdir() get_media_folders(ctx) assert ctx.media_folders == [media]
def _get_standard_build_folder() -> typing.Tuple[Context, Path]: ctx = Context() pandoc = Path('pandoc') pandoc.touch() src_folder = Path('./test').absolute() src_folder.mkdir() ctx.source_folder = src_folder source_file = Path('./test/index.md') source_file.touch() ctx.source_file = source_file ctx.markdown_text = '' return ctx, pandoc
def make_pdf(ctx: Context, source_folder: Path): """ Makes a PDF document from a source folder Args: ctx: Context source_folder: source folder """ _remove_artifacts() source_folder = elib.path.ensure_dir(source_folder).absolute() LOGGER.info(f'analyzing folder: "{source_folder}"') if _is_source_folder(source_folder): ctx.source_folder = source_folder _build_folder(ctx) else: for child in source_folder.iterdir(): if _is_source_folder(child): ctx.source_folder = child.absolute() _build_folder(ctx)
def test_get_media_folder_multiple(): sub1 = Path('./sub1').absolute() sub1.mkdir() media1 = Path(sub1, 'media').absolute() media1.mkdir() sub2 = Path(sub1, 'sub2').absolute() sub2.mkdir() media2 = Path(sub2, 'media').absolute() media2.mkdir() sub3 = Path(sub2, 'sub3').absolute() sub3.mkdir() media3 = Path(sub3, 'media').absolute() media3.mkdir() ctx = Context() ctx.source_folder = sub3 get_media_folders(ctx) assert ctx.media_folders == [media3, media2, media1]
def test_nested_settings(): sub1 = Path('./sub1').absolute() sub1.mkdir() settings_1 = Path(sub1, 'settings.yml').absolute() settings_1.write_text( 'key1: value1\n' 'key2: value1\n' 'key3: value1\n' 'key4:\n' ' key1: value1\n' ' key2: value1\n' ' key3: value1\n', encoding='utf8') sub2 = Path(sub1, 'sub2').absolute() sub2.mkdir() settings_2 = Path(sub2, 'settings.yml').absolute() settings_2.write_text('key2: value2\n' 'key4:\n' ' key2: value2\n', encoding='utf8') sub3 = Path(sub2, 'sub3').absolute() sub3.mkdir() settings_3 = Path(sub3, 'settings.yml').absolute() settings_3.write_text('key3: value3\n' 'key4:\n' ' key3: value3\n', encoding='utf8') ctx = Context() ctx.source_folder = sub3 settings.get_settings(ctx) assert ctx.settings.data == { 'key1': 'value1', 'key2': 'value2', 'key3': 'value3', 'key4': { 'key1': 'value1', 'key2': 'value2', 'key3': 'value3', }, }
def test_no_template(): ctx = Context() ctx.source_folder = Path('.').absolute() with pytest.raises(FileNotFoundError): template.get_template(ctx)
def test_no_setting_file(): ctx = Context() ctx.source_folder = Path('.').absolute() with pytest.raises(ConvertError): settings.get_settings(ctx)