Commit 573f8201 authored by narugo1992's avatar narugo1992
Browse files

dev(narugo): optimize unittest

parent dc0a5fd3
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
"""
Overview:
    Get edge with ``cv2.Canny``.

    Having **the fastest running speed and the lowest system resource overhead**.
"""
from functools import partial
from typing import Optional
+3 −0
Original line number Diff line number Diff line
"""
Overview:
    Get edge with lineart model.

    Having the **best effect**, closest to the drawing lines,
    but consuming a large amount of memory and computing power at runtime.
"""
from functools import lru_cache, partial
from typing import Optional

test/edge/__init__.py

0 → 100644
+0 −0

Empty file added.

+30 −0
Original line number Diff line number Diff line
import os.path

import pytest
from hbutils.testing import tmatrix

from imgutils.data import load_image
from imgutils.edge import edge_image_with_canny
from test.testings import get_testfile


@pytest.mark.unittest
class TestEdgeCannyAnime:
    @pytest.mark.parametrize(*tmatrix({
        'original_image': ['6125785.jpg', '6125901.jpg'],
        'backcolor': ['transparent', 'white'],
        'forecolor': ['', 'black'],
    }))
    def test_edge_image_with_canny(self, original_image, backcolor, forecolor, image_diff):
        image = edge_image_with_canny(
            get_testfile(original_image),
            backcolor=backcolor, forecolor=None if not forecolor else forecolor,
        )
        body, _ = os.path.splitext(original_image)

        assert image_diff(
            load_image(get_testfile(f'canny_{body}_{backcolor}_{forecolor}.png'),
                       mode='RGB', force_background='pink'),
            load_image(image, mode='RGB', force_background='pink'),
            throw_exception=False
        ) < 1e-2
+31 −0
Original line number Diff line number Diff line
import os.path

import pytest
from hbutils.testing import tmatrix

from imgutils.data import load_image
from imgutils.edge import edge_image_with_lineart
from test.testings import get_testfile


@pytest.mark.unittest
class TestEdgeLineart:
    @pytest.mark.parametrize(*tmatrix({
        'original_image': ['6125785.jpg', '6125901.jpg'],
        'backcolor': ['transparent', 'white'],
        'forecolor': ['', 'black'],
        'coarse': [True, False],
    }))
    def test_edge_image_with_lineart(self, original_image, backcolor, forecolor, coarse, image_diff):
        image = edge_image_with_lineart(
            get_testfile(original_image), coarse=coarse,
            backcolor=backcolor, forecolor=None if not forecolor else forecolor,
        )
        body, _ = os.path.splitext(original_image)

        assert image_diff(
            load_image(get_testfile(f'lineart_{body}_{backcolor}_{forecolor}_{coarse}.png'),
                       mode='RGB', force_background='pink'),
            load_image(image, mode='RGB', force_background='pink'),
            throw_exception=False
        ) < 1e-2
Loading