Skip to content

Commit

Permalink
Fixes for #1318, #1319
Browse files Browse the repository at this point in the history
  • Loading branch information
RhetTbull committed Dec 9, 2023
1 parent d81c58f commit e2100cc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion osxphotos/phototemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,8 @@ def _render_template_string(
raise SyntaxError(
"var must have a subfield and value in form {var:subfield,value}"
)
# strip empty string from default, #1318, #512
default = [d for d in default if d != ""]
self.variables[subfield] = default
vals = []
else:
Expand Down Expand Up @@ -740,7 +742,7 @@ def comparison_test(test_function):
pre = ts.pre or ""
post = ts.post or ""

rendered = [pre + str(val) + post for val in vals]
rendered = [pre + str(val) + post for val in vals] if vals else [pre + post]
results_new = []
for ren in rendered:
for res in results:
Expand Down
21 changes: 21 additions & 0 deletions tests/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -1406,3 +1406,24 @@ def test_float_concatenation(photosdb):
rendered, _ = photo.render_template("{,+photo.location}")
assert len(rendered) == 1
assert rendered[0] == f"{photo.location[0]},{photo.location[1]}"


def test_var_eval(photosdb):
"""Test {%varname?True,False} #1318"""
photo = [p for p in photosdb.photos() if not p.title][0]
template = "{var:test,{title,}}{%test?True,False}"
rendered, _ = photo.render_template(template)
assert rendered[0] == "False"

photo = [p for p in photosdb.photos() if p.title][0]
template = "{var:test,{title,}}{%test?True,False}"
rendered, _ = photo.render_template(template)
assert rendered[0] == "True"


def test_null_template(photosdb):
"""Test that template with null value renders correctly, #1319"""
photo = [p for p in photosdb.photos() if not p.title][0]
template = "{var:test,{title,}}Foo-{%test,}-Bar"
rendered, _ = photo.render_template(template)
assert rendered[0] == "Foo--Bar"

0 comments on commit e2100cc

Please sign in to comment.