| | 85 | def test_include_from_unicode_dir(self): |
| | 86 | if not os.path.supports_unicode_filenames: |
| | 87 | return |
| | 88 | subdir = os.path.join(self.dirname, u'b\xf6se') |
| | 89 | os.mkdir(subdir) |
| | 90 | file1 = open(os.path.join(subdir, 'tmpl1.html'), 'w') |
| | 91 | try: |
| | 92 | file1.write("""<div>Included</div>""") |
| | 93 | finally: |
| | 94 | file1.close() |
| | 95 | file2 = open(os.path.join(subdir, 'tmpl2.html'), 'w') |
| | 96 | try: |
| | 97 | file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> |
| | 98 | <xi:include href="tmpl1.html" /> |
| | 99 | </html>""") |
| | 100 | finally: |
| | 101 | file2.close() |
| | 102 | # subdir is still a unicode string here |
| | 103 | loader = TemplateLoader([subdir]) |
| | 104 | tmpl = loader.load('tmpl2.html') |
| | 105 | self.assertEqual("""<html> |
| | 106 | <div>Included</div> |
| | 107 | </html>""", tmpl.generate().render(encoding=None)) |
| | 108 | file3 = open(os.path.join(subdir, 'module.py'), 'w') |
| | 109 | try: |
| | 110 | file3.write("""# module""") |
| | 111 | finally: |
| | 112 | file2.close() |
| | 113 | from imp import find_module |
| | 114 | subdir = os.path.dirname(find_module('module', [subdir])[1]) |
| | 115 | # now subdir is a string in file system encoding |
| | 116 | loader = TemplateLoader([subdir]) |
| | 117 | tmpl = loader.load('tmpl2.html') |
| | 118 | self.assertEqual("""<html> |
| | 119 | <div>Included</div> |
| | 120 | </html>""", tmpl.generate().render(encoding=None)) |
| | 121 | |