-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more tests code coverage at 89%
- Loading branch information
Showing
9 changed files
with
273 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import logging | ||
|
||
import data | ||
import pytest | ||
|
||
import homepress.renderer | ||
from homepress.renderer import get_renderer | ||
|
||
# Uncomment this if u wish to run the code | ||
# at test_get_renderer_files_unsupported_with_ignore_errors | ||
# | ||
# def _flatten(e, d=None): | ||
# if d is None: | ||
# d = [] | ||
# for x in e: | ||
# if hasattr(x, "renderers"): | ||
# _flatten(x.renderers, d) | ||
# elif hasattr(x, "renderer"): | ||
# _flatten([x.renderer], d) | ||
# else: | ||
# d.append(x) | ||
# | ||
# return d | ||
|
||
|
||
def test_get_renderer_files(): | ||
get_renderer(list(data.dataset.filter_extension(["pdf", "svg", "xps"]))) | ||
|
||
|
||
def test_get_renderer_files_unsupported(): | ||
with pytest.raises(TypeError): | ||
get_renderer(list(data.dataset.filter_extension(["bin"]))) | ||
|
||
|
||
def test_get_renderer_files_unsupported_with_ignore_errors(): | ||
a = get_renderer([data.root], True) | ||
b = get_renderer(list(data.dataset.filter_extension(homepress.renderer.formats))) | ||
|
||
# Code below was used to find differences as to where the file might've been and where it might've not been | ||
# taken up by the get_renderer method | ||
|
||
# sortbyfname = lambda x: str(x.file.resolve()) | ||
# sortbyfname2 = lambda x: str(x.file.resolve().name) | ||
|
||
# a_flat = _flatten(a.renderers) | ||
# b_flat = _flatten(b.renderers) | ||
|
||
# a_flat.sort(key=sortbyfname) | ||
# b_flat.sort(key=sortbyfname) | ||
|
||
# a_n = [sortbyfname2(x) for x in a_flat] | ||
# b_n = [sortbyfname2(x) for x in b_flat] | ||
|
||
# for x, y in zip(a_n, b_n): | ||
# logging.warning(f"{x} {y}") | ||
|
||
assert len(a) == len(b) | ||
|
||
|
||
def test_get_renderer_files_folder(): | ||
assert len(get_renderer([data.root / "testdata" / "filesamples.com"])) != 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import pytest | ||
from test_renderer import TestRenderer | ||
|
||
from homepress.renderer.multi_renderer import MultiRenderer | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def multi_renderer(): | ||
return MultiRenderer([TestRenderer() for _ in range(10)]) | ||
|
||
|
||
def test_multi_renderer_out_of_range(multi_renderer: MultiRenderer): | ||
with pytest.raises(IndexError): | ||
multi_renderer.render(17, (10, 10)) | ||
|
||
|
||
def test_multi_renderer_in_range(multi_renderer: MultiRenderer): | ||
assert "RES" == multi_renderer.render(8, (10, 10)) | ||
|
||
|
||
def test_multi_renderer_preview(multi_renderer: MultiRenderer): | ||
assert "RESPREV" == multi_renderer.render_preview(7) | ||
|
||
|
||
def test_multi_renderer_get_text(multi_renderer: MultiRenderer): | ||
assert TestRenderer().get_text(0) == multi_renderer.get_text(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import pytest | ||
from test_renderer import TestRenderer | ||
|
||
from homepress.renderer import MultiRenderer | ||
from homepress.renderer.page_range_renderer import PageRangeRenderer | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def page_renderer(): | ||
return PageRangeRenderer( | ||
MultiRenderer([TestRenderer(render_res=x) for x in range(10)]), range(2, 8) | ||
) | ||
|
||
|
||
def test_page_renderer_out_of_range(page_renderer: PageRangeRenderer): | ||
with pytest.raises(IndexError): | ||
page_renderer.render(6, (10, 10)) | ||
|
||
|
||
def test_page_renderer_in_range(page_renderer: PageRangeRenderer): | ||
assert 7 == page_renderer.render(5, (10, 10)) | ||
|
||
|
||
def test_page_renderer_preview(page_renderer: PageRangeRenderer): | ||
assert "RESPREV" == page_renderer.render_preview(2) | ||
|
||
|
||
def test_page_renderer_get_text(page_renderer: PageRangeRenderer): | ||
assert TestRenderer().get_text(0) == page_renderer.get_text(1) | ||
|
||
|
||
def test_page_renderer_len(page_renderer: PageRangeRenderer): | ||
assert 6 == len(page_renderer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import logging | ||
from pathlib import Path | ||
|
||
import data | ||
import pytest | ||
|
||
import homepress.renderer | ||
from homepress import Press | ||
|
||
|
||
@pytest.fixture( | ||
scope="module", | ||
params=list(data.dataset.filter_extension_batched(homepress.renderer.formats, 10)), | ||
) | ||
def press_10(request): | ||
return Press(request.param) | ||
|
||
|
||
@pytest.fixture( | ||
scope="module", | ||
params=list(data.dataset.filter_extension_batched(homepress.renderer.formats, 10)), | ||
) | ||
def press_30(request): | ||
return Press(request.param) | ||
|
||
|
||
def test_press_text(press_10: Press): | ||
assert isinstance(press_10.text(), list) | ||
|
||
|
||
def test_press_images_png(press_10: Press, tmpdir: Path): | ||
press_10.images( | ||
tmpdir, format="png", file_prefix="test_png_image", resolution=(64, 64) | ||
) | ||
|
||
|
||
def test_press_images_webp(press_10: Press, tmpdir: Path): | ||
press_10.images( | ||
tmpdir, format="webp", file_prefix="test_webp_image", resolution=(64, 64) | ||
) | ||
|
||
|
||
def test_merge(press_10: Press, tmpdir: Path): | ||
press_10.merge(tmpdir / "merge_test.pdf", resolution=(64, 64)) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"size,margin,ppi,rtl,flip_even", | ||
[ | ||
("A4", [0], 10, False, False), | ||
("Legal", [2], 10, True, False), | ||
("Ledger", [4, 3], 10, False, True), | ||
("Letter", [0, 2, 3], 10, True, True), | ||
((1 / 2, 5), [0, 4, 5, 6], 10, False, False), | ||
], | ||
) | ||
def test_midpage(press_10: Press, tmpdir: Path, size, margin, ppi, rtl, flip_even): | ||
press_10.midpage( | ||
tmpdir / "midpage_test.pdf", | ||
size=size, | ||
margin=margin, | ||
ppi=ppi, | ||
rtl=rtl, | ||
flip_even=flip_even, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"size,margin,ppi,rtl,flip_even,separate_stacks,stack_prefix,stack_size", | ||
[ | ||
("A4", [0], 10, False, False, False, "stack_", 12), | ||
("Legal", [2], 10, True, False, True, "stack_", 12), | ||
("Ledger", [4, 3], 10, False, True, True, "st12_", 12), | ||
("Letter", [0, 2, 3], 10, True, True, False, "", 16), | ||
((1 / 2, 5), [0, 4, 5, 6], 10, False, False, True, "_p", 4), | ||
], | ||
) | ||
def test_midpage_multi( | ||
press_30: Press, | ||
tmpdir: Path, | ||
size, | ||
margin, | ||
ppi, | ||
rtl, | ||
flip_even, | ||
separate_stacks, | ||
stack_prefix, | ||
stack_size, | ||
): | ||
press_30.midpage_multi( | ||
tmpdir / "midpage_test.pdf", | ||
size=size, | ||
margin=margin, | ||
ppi=ppi, | ||
rtl=rtl, | ||
flip_even=flip_even, | ||
separate_stacks=separate_stacks, | ||
stack_prefix=stack_prefix, | ||
stack_size=stack_size, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from homepress.renderer import Renderer | ||
|
||
|
||
class TestRenderer(Renderer): | ||
supported_extensions = [] | ||
|
||
def __init__( | ||
self, | ||
len=1, | ||
render_res="RES", | ||
render_preview_res="RESPREV", | ||
get_text_res="The quick brown fox jumps tonsss", | ||
): | ||
self.len = len | ||
self.render_res = render_res | ||
self.get_text_res = get_text_res | ||
self.render_preview_res = render_preview_res | ||
|
||
def __len__(self): | ||
return self.len | ||
|
||
def render(self, page, res): | ||
return self.render_res | ||
|
||
def render_preview(self, page): | ||
return self.render_preview_res | ||
|
||
def get_text(self, page): | ||
return self.get_text_res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.