| 343 | def test_garbage_templates(self): |
| 344 | garbage_tests = { |
| 345 | 'garbage-input01' : 'content %}', |
| 346 | 'garbage-input02' : ' content %}', |
| 347 | 'garbage-input03' : 'content #}', |
| 348 | 'garbage-input04' : ' content #}', |
| 349 | 'garbage-input05' : 'content }}', |
| 350 | 'garbage-input06' : ' content }}', |
| 351 | 'garbage-input07' : '% content %}', |
| 352 | 'garbage-input08' : '# content #}', |
| 353 | 'garbage-input09' : '{ content }}', |
| 354 | 'garbage-input10' : '{% content }', |
| 355 | 'garbage-input11' : '{% content %', |
| 356 | 'garbage-input12' : '{# content }', |
| 357 | 'garbage-input13' : '{# content #', |
| 358 | 'garbage-input14' : '{{ content }', |
| 359 | 'garbage-input15' : '{{ content }', |
| 360 | 'garbage-input16' : '{{ content %}', |
| 361 | 'garbage-input17' : '{% content }}', |
| 362 | 'garbage-input18' : '{{ content #}', |
| 363 | 'garbage-input19' : '{# content }}', |
| 364 | 'garbage-input20' : '{{ con #} tent #}', |
| 365 | 'garbage-input21' : '{{ con %} tent #}', |
| 366 | 'garbage-input22' : '{{ con #} tent %}', |
| 367 | 'garbage-input23' : '{{ con %} tent %}', |
| 368 | 'garbage-input24' : '{% con #} tent #}', |
| 369 | 'garbage-input25' : '{% con }} tent #}', |
| 370 | 'garbage-input26' : '{% con #} tent }}', |
| 371 | 'garbage-input27' : '{% con }} tent }}', |
| 372 | 'garbage-input28' : '{# con %} tent %}', |
| 373 | 'garbage-input29' : '{# con }} tent %}', |
| 374 | 'garbage-input30' : '{# con %} tent }}', |
| 375 | 'garbage-input31' : '{# con }} tent }}', |
| 376 | 'garbage-input32' : '{# con {# tent }}', |
| 377 | 'garbage-input33' : '{# con {% tent }}', |
| 378 | 'garbage-input34' : '{% con {% tent }}', |
| 379 | 'garbage-input35' : '{ { content }}', |
| 380 | 'garbage-input36' : '{ % content %}', |
| 381 | 'garbage-input37' : '{ # content #}', |
| 382 | 'garbage-input38' : '{\n{ content }}', |
| 383 | 'garbage-input39' : '{\n# content #}', |
| 384 | 'garbage-input40' : '{\n% content %}', |
| 385 | 'garbage-input41' : '{{\n content }}', |
| 386 | 'garbage-input42' : '{#\n content #}', |
| 387 | 'garbage-input43' : '{%\n content %}', |
| 388 | 'garbage-input44' : '{{ content \n}}', |
| 389 | 'garbage-input45' : '{# content \n#}', |
| 390 | 'garbage-input46' : '{% content \n%}', |
| 391 | 'garbage-input47' : '{{ content }\n}', |
| 392 | 'garbage-input48' : '{# content #\n}', |
| 393 | 'garbage-input49' : '{% content %\n}', |
| 394 | 'garbage-input50' : '{{ content } }', |
| 395 | 'garbage-input51' : '{% content % }', |
| 396 | 'garbage-input52' : '{# content # }', |
| 397 | 'garbage-input53' : '{ { content } }', |
| 398 | 'garbage-input54' : '{ % content % }', |
| 399 | 'garbage-input55' : '{ # content # }', |
| 400 | 'garbage-input56' : '{{ content }%', |
| 401 | 'garbage-input57' : '{# content #%', |
| 402 | 'garbage-input58' : '{% content %%', |
| 403 | 'garbage-input59' : '{{ content }A', |
| 404 | 'garbage-input60' : '{# content #A', |
| 405 | 'garbage-input61' : '{% content %A', |
| 406 | 'garbage-input62' : '{{ content A}', |
| 407 | 'garbage-input63' : '{# content A#', |
| 408 | 'garbage-input64' : '{% content A%', |
| 409 | 'garbage-input65' : '{# content A}', |
| 410 | 'garbage-input66' : '{% content A}', |
| 411 | 'garbage-input67' : 'A{ content }}', |
| 412 | 'garbage-input68' : 'A# content #}', |
| 413 | 'garbage-input69' : 'A% content %}', |
| 414 | 'garbage-input60' : '{A content }}', |
| 415 | 'garbage-input71' : '{A content #}', |
| 416 | 'garbage-input72' : '{A content %}', |
| 417 | 'garbage-input73' : '{A content #}', |
| 418 | 'garbage-input74' : '{A content %}', |
| 419 | 'garbage-input75' : '{A content A}', |
| 420 | 'garbage-input76' : '}} content }}', |
| 421 | 'garbage-input77' : '}} content {{', |
| 422 | 'garbage-input78' : '#} content #}', |
| 423 | 'garbage-input79' : '#} content {#', |
| 424 | 'garbage-input80' : '%} content %}', |
| 425 | 'garbage-input81' : '%} content {%', |
| 426 | 'garbage-input82' : '#{ content }#', |
| 427 | 'garbage-input83' : '%{ content }%', |
| 428 | } |
| 429 | |
| 430 | tests = garbage_tests.items() |
| 431 | tests.sort() |
| 432 | |
| 433 | # Register our custom template loader. |
| 434 | def test_garbage_loader(template_name, template_dirs=None): |
| 435 | "A custom template loader that loads the unit-test templates." |
| 436 | try: |
| 437 | return (garbage_tests[template_name], "test:%s" % template_name) |
| 438 | except KeyError: |
| 439 | raise template.TemplateDoesNotExist, template_name |
| 440 | |
| 441 | old_template_loaders = loader.template_source_loaders |
| 442 | loader.template_source_loaders = [test_garbage_loader] |
| 443 | |
| 444 | failures = [] |
| 445 | |
| 446 | for name, input_content in tests: |
| 447 | test_template = loader.get_template(name) |
| 448 | output = test_template.render(Context()) |
| 449 | |
| 450 | if output != input_content: |
| 451 | failures.append("Garbage test: %s -- FAILED. Expected %r, got %r" % (name, input_content, output)) |
| 452 | |
| 453 | loader.template_source_loaders = old_template_loaders |
| 454 | |
| 455 | self.assertEqual(failures, [], "Tests failed:\n%s\n%s" % |
| 456 | ('-'*70, ("\n%s\n" % ('-'*70)).join(failures))) |
| 457 | |
| 458 | |