root/trunk/test/w3c/testCSSMedia.py

Revision 389, 2.7 kB (checked in by sholloway, 5 years ago)

Changed CSS implementation so that it always tracks the importance of attributes
Fixed the tests to handle the changes

Line 
1 #!/usr/bin/env python
2 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 ##~ Copyright (C) 2002-2004  TechGame Networks, LLC.
4 ##~
5 ##~ This library is free software; you can redistribute it and/or
6 ##~ modify it under the terms of the BSD style License as found in the
7 ##~ LICENSE file included with this distribution.
8 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9
10 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11 #~ Imports
12 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13
14 import sys
15 import os
16 import glob
17
18 from TG.common.testPackageRunner import TestSuite, FunctionTestCase, TestProgram
19 from TG.w3c.css import CSSParser, CSSParseError
20
21 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22 #~ Definitions
23 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24
25 class TestCSSMediaFiles(TestSuite):
26     def generateTests(self):
27         rootPath = os.path.dirname(__file__)
28         cssFilenames = glob.glob(os.path.join(rootPath, 'media', '*.css'))
29         self.getCSSFileTests(cssFilenames)
30         self.getSingleParserCSSFileTests(cssFilenames)
31
32     def _generateTestCallback(self, name):
33         return lambda:self._testCSSFile(name)
34
35     def getCSSFileTests(self, cssFilenames):
36         for cssfilename in cssFilenames:
37             testfn = FunctionTestCase(self._generateTestCallback(cssfilename),
38                     description='CSSFile with standalone parser for \'%s\''%str(cssfilename))
39             self.addTest(testfn)
40    
41     def _generateSharedTestCallback(self, name, parser):
42         return lambda:self._testCSSFileWithParser(name, parser)
43
44     def getSingleParserCSSFileTests(self, cssFilenames):
45         parser = CSSParser()
46         for cssfilename in cssFilenames:
47             testfn = FunctionTestCase(self._generateSharedTestCallback(cssfilename, parser),
48                     description='CSSFile with shared parser for \'%s\''%str(cssfilename))
49             self.addTest(testfn)
50
51     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
52
53     def _testCSSFile(self, cssfilename):
54         parser = CSSParser()
55         self._testCSSFileWithParser(cssfilename, parser)
56
57     def _testCSSFileWithParser(self, cssfilename, parser):
58         cssfile = open(cssfilename, 'r')
59         try:
60             try:
61                 stylesheet = parser.parseFile(cssfile)
62             except CSSParseError, err:
63                 assert False, 'CSSParser failed to parse \'%s\':: %s' % (cssfilename, err)
64         finally:
65             cssfile.close()
66    
67 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68 #~ Unittest Main
69 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70
71 if __name__=='__main__':
72     TestProgram()
73
Note: See TracBrowser for help on using the browser.