forked from lektor/lektor
-
-
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.
fix(reporter): describe_build_func fails on functools.partial
PR lektor#1104 uses a functools.partial as a sub-artifact's _build_func_. When verbose logging is enabled, this caused an exception from `lektor.reporter.describe_build_func`.
- Loading branch information
Showing
3 changed files
with
52 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
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,39 @@ | ||
from functools import partial | ||
|
||
import pytest | ||
|
||
from lektor.build_programs import FileAssetBuildProgram | ||
from lektor.builder import Builder | ||
from lektor.reporter import describe_build_func | ||
|
||
|
||
@pytest.fixture | ||
def build_state(pad, tmp_path): | ||
builder = Builder(pad, destination_path=tmp_path) | ||
return builder.new_build_state() | ||
|
||
|
||
def dummy_build_func(*args): | ||
pass | ||
|
||
|
||
def test_describe_build_func(): | ||
assert describe_build_func(dummy_build_func) == "test_reporter.dummy_build_func" | ||
|
||
|
||
def test_describe_build_func_describes_partial(): | ||
build_func = partial(dummy_build_func, "dummy-arg") | ||
assert describe_build_func(build_func) == "test_reporter.dummy_build_func" | ||
|
||
|
||
def test_describe_build_func_BuildProgram(pad, build_state): | ||
build_program = FileAssetBuildProgram(pad.get_asset("static/demo.css"), build_state) | ||
build_func = build_program.build_artifact | ||
assert ( | ||
describe_build_func(build_func) == "lektor.build_programs.FileAssetBuildProgram" | ||
) | ||
|
||
|
||
def test_describe_build_func_deals_with_garbage(): | ||
garbage = object() | ||
assert isinstance(describe_build_func(garbage), str) |