@@ -3104,6 +3104,9 @@ def testExpandfile(self):
31043104 { "name" : "file_with_missing.js" ,
31053105 "content" : ('hello world %(base)s, %(idontexist)s' ),
31063106 },
3107+ { "name" : "file_with_bare_%.js" ,
3108+ "content" : ('expr = 3 % 5 + (var1+var2)' ),
3109+ },
31073110 { "name" : "subdir/file_to_read.js" ,
31083111 "content" : ('hello world from subdir' ),
31093112 },
@@ -3247,7 +3250,36 @@ def testExpandfile(self):
32473250 self .assertEqual (self ._caplog .text , '' )
32483251 self ._caplog .clear ()
32493252
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
32513283 r = tu .expandfile ("subdir/file_to_read.js" )
32523284 self .assertEqual (r , 'hello world from subdir' )
32533285 r = None
0 commit comments