From 1b7cbccdafbaaa0492706a1b42ac84c1925ea57e Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Tue, 11 Oct 2022 11:41:51 +0100 Subject: [PATCH] Add a test calling a stored python template from a GPM template --- src/calibre/db/tests/reading.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/calibre/db/tests/reading.py b/src/calibre/db/tests/reading.py index 30c68cdaf4..12dc79edcc 100644 --- a/src/calibre/db/tests/reading.py +++ b/src/calibre/db/tests/reading.py @@ -846,4 +846,23 @@ def evaluate(book, db, **kwargs): ''' v = formatter.safe_format(template, {}, 'TEMPLATE ERROR', mi) self.assertEqual(set(v.split(',')), {'Tag One', 'News', 'Tag Two'}) + + # test calling a python stored template from a GPM template + from calibre.utils.formatter_functions import ( + load_user_template_functions, unload_user_template_functions) + load_user_template_functions('aaaaa', + [['python_stored_template', + "", + 0, + '''python: +def evaluate(book, db, globals, arguments): + tags = set(db.new_api.all_field_names('tags')) + tags.add(arguments[0]) + return ','.join(list(tags)) +''' + ]], None) + v = formatter.safe_format('program: python_stored_template("one argument")', {}, + 'TEMPLATE ERROR', mi) + unload_user_template_functions('aaaaa') + self.assertEqual(set(v.split(',')), {'Tag One', 'News', 'Tag Two', 'one argument'}) # }}}