From 86aa603fc2bf49c2d727724fb31ad89abe7b3d1f Mon Sep 17 00:00:00 2001 From: Mohamed Feddad Date: Sun, 14 Jul 2024 23:44:52 +0400 Subject: [PATCH 1/3] fix: missing go dependency exception with default options Resolves #97 --- flask_minify/parsers.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/flask_minify/parsers.py b/flask_minify/parsers.py index fd963a6..8920e08 100644 --- a/flask_minify/parsers.py +++ b/flask_minify/parsers.py @@ -125,11 +125,10 @@ def __init__( runtime_options={}, go=False, ): - self.default_parsers = self._go_default_parsers if go else self._default_parsers + self.go = go self.parsers = {**self.default_parsers, **parsers} self.runtime_options = {**runtime_options} self.fail_safe = fail_safe - self.go = go if self.has_go_parser and not minify_go: raise FlaskMinifyException( @@ -137,6 +136,12 @@ def __init__( "Go optional dependency: `pip install flask-minify[go]`" ) + @property + def default_parsers(self): + return ( + self._go_default_parsers if self.go and minify_go else self._default_parsers + ) + @property def has_go_parser(self): return any(p.go for p in self.parsers.values()) From d1007734329a6970d5e059153ec6dfb89ce4c528 Mon Sep 17 00:00:00 2001 From: Mohamed Feddad Date: Sun, 14 Jul 2024 23:49:37 +0400 Subject: [PATCH 2/3] test: missing go dependency exception with default options --- tests/units.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/units.py b/tests/units.py index f9e5845..8d1574d 100644 --- a/tests/units.py +++ b/tests/units.py @@ -59,6 +59,8 @@ def setup(self): self.bypass = [] self.bypass_caching = [] self.caching_limit = 1 + self.parsers = {} + self.go = True self.patch = mock.patch.multiple("flask_minify.main", request=self.mock_request) self.patch.start() @@ -76,6 +78,8 @@ def minify_defaults(self): self.bypass, self.bypass_caching, self.caching_limit, + parsers=self.parsers, + go=self.go, ) def test_request_falsy_endpoint(self): @@ -127,6 +131,26 @@ def executer(self, content, **options): with pytest.raises(FlaskMinifyException): parser.minify(LESS_RAW, "style") + def test_default_parsers_when_go_enabled_and_dependancy_missing(self): + with mock.patch("flask_minify.parsers.minify_go", None): + parser = parsers.Parser(go=True) + assert parser.default_parsers == parser._default_parsers + + def test_default_parsers_when_go_enabled_and_dependency_present(self): + with mock.patch("flask_minify.parsers.minify_go"): + parser = parsers.Parser(go=True) + assert parser.default_parsers == parser._go_default_parsers + + def test_default_parsers_when_go_disabled_and_dependency_present(self): + with mock.patch("flask_minify.parsers.minify_go"): + parser = parsers.Parser(go=False) + assert parser.default_parsers == parser._default_parsers + + def test_go_parsers_passed_with_go_enabled_and_dependency_missing_exception(self): + with mock.patch("flask_minify.parsers.minify_go", None): + with pytest.raises(FlaskMinifyException): + parsers.Parser(parsers=parsers.Parser._go_default_parsers, go=True) + class TestMemoryCache: def setup(self): From 63c24eaff7406b6a8799c635913b14440751b935 Mon Sep 17 00:00:00 2001 From: Mohamed Feddad Date: Sun, 14 Jul 2024 23:49:47 +0400 Subject: [PATCH 3/3] chore: bump version to 0.48 --- flask_minify/about.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flask_minify/about.py b/flask_minify/about.py index a44a283..53409b8 100644 --- a/flask_minify/about.py +++ b/flask_minify/about.py @@ -1,4 +1,4 @@ -__version__ = "0.47" +__version__ = "0.48" __doc__ = "Flask extension to minify html, css, js and less." __license__ = "MIT" __author__ = "Mohamed Feddad"