Commit 5c80575e authored by narugo1992's avatar narugo1992
Browse files

dev(narugo): auto release some resource when running on windows

parent 2557909f
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
import os.path
from unittest import skipUnless

import pytest
from hbutils.testing import tmatrix, OS
from hbutils.testing import tmatrix

from imgutils.data import load_image
from imgutils.edge import edge_image_with_lineart
@@ -20,7 +19,6 @@ def _release_model_after_run():

@pytest.mark.unittest
class TestEdgeLineart:
    @skipUnless(OS.linux or OS.macos, 'Not run on windows')
    @pytest.mark.parametrize(*tmatrix({
        'original_image': ['6125785.jpg', '6125901.jpg'],
        'backcolor': ['transparent', 'white'],
+11 −1
Original line number Diff line number Diff line
@@ -5,9 +5,18 @@ from hbutils.testing import tmatrix

from imgutils.data import load_image
from imgutils.edge import edge_image_with_lineart_anime
from imgutils.edge.lineart_anime import _open_la_anime_model
from test.testings import get_testfile


@pytest.fixture()
def _release_model_after_run():
    try:
        yield
    finally:
        _open_la_anime_model.cache_clear()


@pytest.mark.unittest
class TestEdgeLineartAnime:
    @pytest.mark.parametrize(*tmatrix({
@@ -15,7 +24,8 @@ class TestEdgeLineartAnime:
        'backcolor': ['transparent', 'white'],
        'forecolor': ['', 'black']
    }))
    def test_edge_image_with_lineart_anime(self, original_image, backcolor, forecolor, image_diff):
    def test_edge_image_with_lineart_anime(self, original_image, backcolor, forecolor,
                                           image_diff, _release_model_after_run):
        image = edge_image_with_lineart_anime(
            get_testfile(original_image),
            backcolor=backcolor, forecolor=None if not forecolor else forecolor,
+10 −1
Original line number Diff line number Diff line
import pytest

from imgutils.tagging import get_deepdanbooru_tags
from imgutils.tagging.deepdanbooru import _get_deepdanbooru_model
from test.testings import get_testfile


@pytest.fixture()
def _release_model_after_run():
    try:
        yield
    finally:
        _get_deepdanbooru_model.cache_clear()


@pytest.mark.unittest
class TestTaggingDeepdanbooru:
    def test_get_deepdanbooru_tags(self):
    def test_get_deepdanbooru_tags(self, _release_model_after_run):
        rating, tags, chars = get_deepdanbooru_tags(get_testfile('6124220.jpg'))
        assert rating['rating:safe'] > 0.9
        assert tags['greyscale'] >= 0.8
+9 −0
Original line number Diff line number Diff line
import pytest

from imgutils.tagging import get_wd14_tags
from imgutils.tagging.wd14 import _get_wd14_model
from test.testings import get_testfile


@pytest.fixture()
def _release_model_after_run():
    try:
        yield
    finally:
        _get_wd14_model.cache_clear()


@pytest.mark.unittest
class TestTaggingWd14:
    def test_get_wd14_tags(self):
+9 −1
Original line number Diff line number Diff line
@@ -3,7 +3,15 @@ import os.path
import pytest
from hbutils.testing import tmatrix

from imgutils.validate.monochrome import get_monochrome_score, is_monochrome
from imgutils.validate.monochrome import get_monochrome_score, is_monochrome, _monochrome_validate_model


@pytest.fixture(scope='module', autouse=True)
def _release_model_after_run():
    try:
        yield
    finally:
        _monochrome_validate_model.cache_clear()


def get_samples():