W3C home > Mailing lists > Public > www-validator-cvs@w3.org > January 2008

2008/link-testsuite/harness/lib Documentation.py,NONE,1.1

From: Olivier Thereaux via cvs-syncmail <cvsmail@w3.org>
Date: Wed, 30 Jan 2008 07:05:42 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1JK70w-0000WU-QG@lionel-hutz.w3.org>

Update of /sources/public/2008/link-testsuite/harness/lib
In directory hutz:/tmp/cvs-serv1987

Added Files:
Log Message:
simple template engine class using jinja http://jinja.pocoo.org

--- NEW FILE: Documentation.py ---
#!/usr/bin/env python
# encoding: utf-8
Generate Link Test Suite index and documentation

Created by olivier Thereaux on 2008-01-30.
Copyright (c) 2008 W3C. Licensed under the W3C Software License

import sys
import os
import unittest
import LinkTestCase
import datetime

class Documentation:
    def __init__(self, type=None):
        ok_types = ['test', 'index']
        if type in ok_types:
            self.type = type
            self.type = 'index'
        self.test_collections = list()
    def addCollection(self, test_collection):
        if isinstance(test_collection, LinkTestCase.LinkTestCollection) == 0:
            raise TypeError("not a proper test collection") 
    def generate(self, template_path=None):
        """pass through template engine"""
        import jinja,datetime
        if template_path == None:
            template_path= os.path.abspath('..')
            template_path=os.path.join(template_path, "templates")    
        template_engine = jinja.Environment(loader=jinja.FileSystemLoader(template_path))
        template = template_engine.get_template(os.path.join(self.type+'.html'))
        return template.render(collections=self.test_collections,

class DocumentationTests(unittest.TestCase):
    def test_has_jinja(self):
            import jinja
        except ImportError:
            self.fail("you need to install the jinja templating system -- http://jinja.pocoo.org/download")

    def test_init(self):
        """initialize a Documentation Generator"""
        generator = Documentation()
        self.assertEquals(generator.type, 'index')
    def test_init_default_fallback(self):
        """initialize a Documentation Generator with a bogus type"""
        generator = Documentation(type="grut")
        self.assertEquals(generator.type, 'index')

    def test_addCollection(self):
        """add test collection"""
        generator = Documentation()
        test_col = LinkTestCase.LinkTestCollection()
        self.assertEquals(len(generator.test_collections), 1)
    def test_boguscollection(self):
        """add bogus test collection and raise error"""
        generator = Documentation()
        test_col = 5 
        self.assertRaises(TypeError, Documentation.addCollection, generator, test_col)
    def test_generate_test(self):
        """generate collections index without any collection"""
        generator = Documentation('test')
        self.assertEqual(generator.generate(), str(datetime.date.today().year))

if __name__ == '__main__':
Received on Wednesday, 30 January 2008 07:05:55 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 26 April 2012 12:55:00 GMT