예제 #1
0
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"""
예제 #2
0
def test_process_image_width():
    ctx = Context()
    ctx.image_max_width = 200
    ctx.image_extras = '{width="10cm"}'
    image._process_image_width(ctx)
    assert ctx.image_extras == '{width="100mm"}'
예제 #3
0
def test_process_image_width_no_width_given():
    ctx = Context()
    ctx.image_max_width = 100
    ctx.image_extras = ''
    image._process_image_width(ctx)
    assert ctx.image_extras == '{width="100mm"}'
예제 #4
0
def test_shrink():
    ctx = Context()
    ctx.image_width_str = '50cm'
    ctx.image_max_width = 20
    image._get_correct_width(ctx)
    assert ctx.image_width == 20
예제 #5
0
def test_get_correct_width_wrong_unit():
    ctx = Context()
    ctx.image_width_str = '9pm'
    ctx.image_max_width = 300
    with pytest.raises(ValueError):
        image._get_correct_width(ctx)
예제 #6
0
def test_get_correct_width(width_str):
    ctx = Context()
    ctx.image_width_str = width_str
    ctx.image_max_width = 300
    image._get_correct_width(ctx)
    assert ctx.image_width <= 300
예제 #7
0
def _set_max_image_width(ctx: Context):
    paper_size = ctx.paper_size.lower()
    if paper_size not in PAPER_FORMATS_WIDTH:
        raise ValueError(paper_size)
    ctx.image_max_width = int(PAPER_FORMATS_WIDTH[paper_size])