comparison test/test_cgi.py @ 7837:e90be54708e9

test: add test for bare % in expanded file.
author John Rouillard <rouilj@ieee.org>
date Tue, 26 Mar 2024 14:51:50 -0400
parents 219fc5804345
children a430339f55e6
comparison
equal deleted inserted replaced
7836:219fc5804345 7837:e90be54708e9
3102 "content": ('hello world %(base)s, %(No,token)s'), 3102 "content": ('hello world %(base)s, %(No,token)s'),
3103 }, 3103 },
3104 { "name": "file_with_missing.js", 3104 { "name": "file_with_missing.js",
3105 "content": ('hello world %(base)s, %(idontexist)s'), 3105 "content": ('hello world %(base)s, %(idontexist)s'),
3106 }, 3106 },
3107 { "name": "file_with_bare_%.js",
3108 "content": ('expr = 3 % 5 + (var1+var2)'),
3109 },
3107 { "name": "subdir/file_to_read.js", 3110 { "name": "subdir/file_to_read.js",
3108 "content": ('hello world from subdir'), 3111 "content": ('hello world from subdir'),
3109 }, 3112 },
3110 { # for future test expanding TAL 3113 { # for future test expanding TAL
3111 "name": "_generic.expandfile_success.html", 3114 "name": "_generic.expandfile_success.html",
3245 3248
3246 # no logging 3249 # no logging
3247 self.assertEqual(self._caplog.text, '') 3250 self.assertEqual(self._caplog.text, '')
3248 self._caplog.clear() 3251 self._caplog.clear()
3249 3252
3250 # testcase 11 - file exists in subdir 3253 # testcase 11 - handle a file with a bare % that raises TypeError
3254 r = tu.expandfile("file_with_bare_%.js", {"var1": "bar"})
3255 self.assertEqual(r, '')
3256
3257 # self._caplog.record_tuples[0] - without line breaks
3258 # ('roundup.template', 40, "Found an incorrect token when
3259 # expandfile applied string subsitution on
3260 # '/home/roundup/_test_template/html/file_with_broken_expand_type.js.
3261 # ValueError('incomplete format') was raised. Check the format
3262 # of your named conversion specifiers."
3263
3264 # name used for logging
3265 self.assertEqual(self._caplog.record_tuples[0][0], 'roundup.template')
3266 # severity ERROR = 40
3267 self.assertEqual(self._caplog.record_tuples[0][1], 40,
3268 msg="logging level != 40 (ERROR)")
3269 # message. It includes a full path to the problem file, so Regex
3270 # match the changable filename directory
3271 self.assertRegex(self._caplog.record_tuples[0][2], (
3272 r"^Found an incorrect token when expandfile applied "
3273 r"string subsitution on "
3274 r"'[^']*/_test_template/html/file_with_bare_%.js'. "
3275 r"ValueError\("
3276 r"'unsupported format character ' ' \(0x20\) at index 12'\) was "
3277 r"raised. Check the format "
3278 r"of your named conversion specifiers."))
3279 self._caplog.clear()
3280 r = None
3281
3282 # testcase 12 - file exists in subdir
3251 r = tu.expandfile("subdir/file_to_read.js") 3283 r = tu.expandfile("subdir/file_to_read.js")
3252 self.assertEqual(r, 'hello world from subdir') 3284 self.assertEqual(r, 'hello world from subdir')
3253 r = None 3285 r = None
3254 3286
3255 3287

Roundup Issue Tracker: http://roundup-tracker.org/