def test_get_image_full_path(): test_file = Path('./test.png') test_file.touch() ctx = Context() ctx.media_folders = [Path('.')] ctx.image_current = test_file.name assert image._get_image_full_path(ctx) == str(test_file.absolute())
def test_check_for_used_images_only_one_media_folder(caplog): caplog.set_level(30, 'EDLM') caplog.clear() ctx = Context() ctx.media_folders = ['.'] ctx.images_used = set() check_for_unused_images(ctx) assert not caplog.text
def test_check_for_unused_images(caplog, media: Path): caplog.set_level(30, 'EDLM') caplog.clear() ctx = Context() ctx.media_folders = [str(media.absolute()), '.'] ctx.images_used = set() check_for_unused_images(ctx) for file in media.iterdir(): assert file.name in caplog.text
def test_process_template(): ctx = Context() template = Path('./template.tex').absolute() template_out = Path('./out.tex').absolute() ctx.template_file = template_out ctx.template_source = template ctx.media_folders = [] template.touch() ctx.template_source = template latex.process_latex(ctx) assert ctx.template_file.read_text(encoding='utf8') == ''
def test_process_template_latex_error(): ctx = Context() template = Path('./template.tex').absolute() ctx.template_source = template ctx.media_folders = [] template.touch() when(latex.TexTemplateLoader).get_source(...).thenRaise( TemplateNotFound(ctx)) ctx.template_source = template with pytest.raises(TemplateNotFound): latex.process_latex(ctx)
def test_process_images(media): ctx = Context() ctx.image_max_width = 200 ctx.media_folders = [str(media.absolute()), '.'] pictures = list(media.iterdir()) ctx.markdown_text = f""" ![picture1](http://picture1.com) ![picture2]({pictures[0].name}) ![picture3](http://picture1.com) """ image.process_images(ctx) print(ctx.markdown_text) assert ctx.markdown_text == f"""
def test_image_doesnt_exist(): ctx = Context() ctx.media_folders = [Path('.')] ctx.image_current = Path('./nope').name with pytest.raises(FileNotFoundError): image._get_image_full_path(ctx)