Edgewall Software

Ticket #412: loader_test.2.patch

File loader_test.2.patch, 2.7 KB (added by Christoph Zwerschke <cito@…>, 13 years ago)

test method for genshi.template.tests.loader

  • genshi/template/tests/loader.py

     
    8282              <div>Included</div>
    8383            </html>""", tmpl.generate().render(encoding=None))
    8484
     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            file3.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
    85122    def test_relative_include_parentdir(self):
    86123        file1 = open(os.path.join(self.dirname, 'tmpl1.html'), 'w')
    87124        try:
     
    396433    def test_prefix_delegation_to_directories(self):
    397434        """
    398435        Test prefix delegation with the following layout:
    399        
     436
    400437        templates/foo.html
    401438        sub1/templates/tmpl1.html
    402439        sub2/templates/tmpl2.html
    403        
     440
    404441        Where sub1 and sub2 are prefixes, and both tmpl1.html and tmpl2.html
    405442        incldue foo.html.
    406443        """
     
    442479    def test_prefix_delegation_to_directories_with_subdirs(self):
    443480        """
    444481        Test prefix delegation with the following layout:
    445        
     482
    446483        templates/foo.html
    447484        sub1/templates/tmpl1.html
    448485        sub1/templates/tmpl2.html
    449486        sub1/templates/bar/tmpl3.html
    450        
     487
    451488        Where sub1 is a prefix, and tmpl1.html includes all the others.
    452489        """
    453490        dir1 = os.path.join(self.dirname, 'templates')