Anonymous avatar Anonymous committed cf94447

more test fixes for py3

Comments (0)

Files changed (2)

src/tests/test_parse.py

 try:
     from minimock import mock, restore
 except ImportError:
-    mock = None 
+    mock = None
     print "install minimock with ``easy_install minimock`` to run all tests"
 
-PY2x = sys.version_info < (3,0)
 
 class CSSParserTestCase(basetest.BaseTestCase):
-    
+
     def setUp(self):
         self._saved = cssutils.log.raiseExceptions
-    
+
     def tearDown(self):
         cssutils.log.raiseExceptions = self._saved
-    
+
     def test_init(self):
         "CSSParser.__init__()"
         self.assertEqual(True, cssutils.log.raiseExceptions)
-        
+
         # also the default:
         cssutils.log.raiseExceptions = True
-        
+
         # default non raising parser
         p = cssutils.CSSParser()
         s = p.parseString('$')
         self.assertEqual(s.cssText, u''.encode())
-        
+
         # explicit raiseExceptions=False
         p = cssutils.CSSParser(raiseExceptions=False)
         s = p.parseString('$')
         self.assertEqual(s.cssText, u''.encode())
 
-        # working with sheet does raise though! 
+        # working with sheet does raise though!
         self.assertRaises(xml.dom.DOMException, s.__setattr__, u'cssText', u'$')
 
-        # ---- 
-        
+        # ----
+
         # raiseExceptions=True
         p = cssutils.CSSParser(raiseExceptions=True)
         self.assertRaises(xml.dom.SyntaxErr, p.parseString, u'$')
-        
+
         # working with a sheet does raise too
         s = cssutils.css.CSSStyleSheet()
         self.assertRaises(xml.dom.DOMException, s.__setattr__, u'cssText', u'$')
     def test_parseComments(self):
         "cssutils.CSSParser(parseComments=False)"
         css = u'/*1*/ a { color: /*2*/ red; }'
-        
+
         p = cssutils.CSSParser(parseComments=False)
         self.assertEqual(p.parseString(css).cssText,
                          u'a {\n    color: red\n    }'.encode())
         p = cssutils.CSSParser(parseComments=True)
         self.assertEqual(p.parseString(css).cssText,
                          u'/*1*/\na {\n    color: /*2*/ red\n    }'.encode())
-        
+
 #    def test_parseFile(self):
 #        "CSSParser.parseFile()"
 #        # see test_cssutils
         if mock:
             # parseUrl(self, href, encoding=None, media=None, title=None):
             parser = cssutils.CSSParser()
-            mock("cssutils.util._defaultFetcher", 
+            mock("cssutils.util._defaultFetcher",
                  mock_obj=self._make_fetcher(None, u''))
             sheet = parser.parseUrl('http://example.com',
-                                    media='tv,print', 
+                                    media='tv,print',
                                     title='test')
             restore()
             #self.assertEqual(sheet, 1)
             self.assertEqual(sheet.encoding, u'utf-8')
             self.assertEqual(sheet.media.mediaText, u'tv, print')
             self.assertEqual(sheet.title, u'test')
-            
+
             # URL and content tests
             tests = {
                 # (url, content): isSheet, encoding, cssText
-                ('', None): (False, None, None), 
-                ('1', None): (False, None, None), 
-                ('mailto:a@bb.cd', None): (False, None, None), 
-                ('http://cthedot.de/test.css', None): (False, None, None), 
-                ('http://cthedot.de/test.css', ''): (True, u'utf-8', u''), 
-                ('http://cthedot.de/test.css', 'a'): (True, u'utf-8', u''), 
-                ('http://cthedot.de/test.css', 'a {color: red}'): (True, u'utf-8', 
-                                                                 u'a {\n    color: red\n    }'), 
-                ('http://cthedot.de/test.css', 'a {color: red}'): (True, u'utf-8', 
-                                                                 u'a {\n    color: red\n    }'), 
-                ('http://cthedot.de/test.css', '@charset "ascii";a {color: red}'): (True, u'ascii', 
-                                                                 u'@charset "ascii";\na {\n    color: red\n    }'), 
+                ('', None): (False, None, None),
+                ('1', None): (False, None, None),
+                ('mailto:a@bb.cd', None): (False, None, None),
+                ('http://cthedot.de/test.css', None): (False, None, None),
+                ('http://cthedot.de/test.css', ''): (True, u'utf-8', u''),
+                ('http://cthedot.de/test.css', 'a'): (True, u'utf-8', u''),
+                ('http://cthedot.de/test.css', 'a {color: red}'): (True, u'utf-8',
+                                                                 u'a {\n    color: red\n    }'),
+                ('http://cthedot.de/test.css', 'a {color: red}'): (True, u'utf-8',
+                                                                 u'a {\n    color: red\n    }'),
+                ('http://cthedot.de/test.css', '@charset "ascii";a {color: red}'): (True, u'ascii',
+                                                                 u'@charset "ascii";\na {\n    color: red\n    }'),
             }
             override = 'iso-8859-1'
             overrideprefix = u'@charset "iso-8859-1";'
             httpencoding = None
-            
+
             for (url, content), (isSheet, expencoding, cssText) in tests.items():
                 parser.setFetcher(self._make_fetcher(httpencoding, content))
                 sheet1 = parser.parseUrl(url)
             # new for 2.x and 3.x
             (u'/*\xe4*/'.encode('utf-8'), None): (u'utf-8', u'/*\xe4*/'.encode('utf-8')),
             (u'/*\xe4*/'.encode('utf-8'), 'utf-8'): (u'utf-8', u'@charset "utf-8";\n/*\xe4*/'.encode('utf-8')),
-                            
+
             ('@charset "ascii";/*a*/', None): (u'ascii', u'@charset "ascii";\n/*a*/'.encode('ascii')),
             ('@charset "utf-8";/*a*/', None): (u'utf-8', u'@charset "utf-8";\n/*a*/'.encode('utf-8')),
             ('@charset "iso-8859-1";/*a*/', None): (u'iso-8859-1', u'@charset "iso-8859-1";\n/*a*/'.encode('iso-8859-1')),
-            
+
             # unicode string, no encoding: encoding, cssText
             (u'/*€*/', None): (
                u'utf-8', u'/*€*/'.encode('utf-8')),
 
     def test_fetcher(self):
         """CSSParser.fetcher
-        
+
         order:
            0. explicity given encoding OVERRIDE (cssutils only)
-           
+
            1. An HTTP "charset" parameter in a "Content-Type" field (or similar parameters in other protocols)
            2. BOM and/or @charset (see below)
            3. <link charset=""> or other metadata from the linking mechanism (if any)
             #    encoding, importIndex, importEncoding, importText
 
             # 0/0 override/override => ASCII/ASCII
-            (u'@charset "utf-16"; @import "x";', 'ASCII', ('iso-8859-1', 
-                                                          '@charset "latin1";/*t*/')): (
-                 'ascii', 1, 'ascii', '@charset "ascii";\n/*t*/'),
+            (u'@charset "utf-16"; @import "x";', 'ASCII', ('iso-8859-1',
+                                                          u'@charset "latin1";/*t*/')): (
+                 'ascii', 1, 'ascii', u'@charset "ascii";\n/*t*/'.encode()),
             # 1/1 not tested her but same as next
             # 2/1 @charset/HTTP => UTF-16/ISO-8859-1
-            (u'@charset "UTF-16"; @import "x";', None, ('ISO-8859-1', 
-                                                       '@charset "latin1";/*t*/')): (
-                 'utf-16', 1, 'iso-8859-1', '@charset "iso-8859-1";\n/*t*/'),
+            (u'@charset "UTF-16"; @import "x";', None, ('ISO-8859-1',
+                                                       u'@charset "latin1";/*t*/')): (
+                 'utf-16', 1, 'iso-8859-1', u'@charset "iso-8859-1";\n/*t*/'.encode('iso-8859-1')),
             # 2/2 @charset/@charset => UTF-16/ISO-8859-1
-            (u'@charset "UTF-16"; @import "x";', None, (None, 
-                                                      '@charset "ISO-8859-1";/*t*/')): (
-                 'utf-16', 1, 'iso-8859-1', '@charset "iso-8859-1";\n/*t*/'),
+            (u'@charset "UTF-16"; @import "x";', None, 
+                (None, u'@charset "ISO-8859-1";/*t*/')): (
+                 'utf-16', 1, 'iso-8859-1', u'@charset "iso-8859-1";\n/*t*/'.encode('iso-8859-1')),
             # 2/4 @charset/referrer => ASCII/ASCII
-            ('@charset "ASCII"; @import "x";', None, (None, '/*t*/')): (
-                 'ascii', 1, 'ascii', '@charset "ascii";\n/*t*/'),
+            ('@charset "ASCII"; @import "x";', None, (None, u'/*t*/')): (
+                 'ascii', 1, 'ascii', u'@charset "ascii";\n/*t*/'.encode()),
             # 5/5 default/default or referrer
-            ('@import "x";', None, (None, '/*t*/')): (
-                 'utf-8', 0, 'utf-8', '/*t*/'),
+            ('@import "x";', None, (None, u'/*t*/')): (
+                 'utf-8', 0, 'utf-8', u'/*t*/'.encode()),
             # 0/0 override/override+unicode
             ('@charset "utf-16"; @import "x";', 'ASCII', (
                      None, u'@charset "latin1";/*\u0287*/')): (
-                 'ascii', 1, 'ascii', u'@charset "ascii";\n/*\\287 */'),
+                 'ascii', 1, 'ascii', u'@charset "ascii";\n/*\\287 */'.encode()),
             # 2/1 @charset/HTTP+unicode
             ('@charset "ascii"; @import "x";', None, ('iso-8859-1', u'/*\u0287*/')): (
-                 'ascii', 1, 'iso-8859-1', '@charset "iso-8859-1";\n/*\\287 */'),
+                 'ascii', 1, 'iso-8859-1', u'@charset "iso-8859-1";\n/*\\287 */'.encode()),
             # 2/4 @charset/referrer+unicode
             ('@charset "ascii"; @import "x";', None, (None, u'/*\u0287*/')): (
-                 'ascii', 1, 'ascii', '@charset "ascii";\n/*\\287 */'),
+                 'ascii', 1, 'ascii', u'@charset "ascii";\n/*\\287 */'.encode()),
             # 5/1 default/HTTP+unicode
             ('@import "x";', None, ('ascii', u'/*\u0287*/')): (
-                 'utf-8', 0, 'ascii', '@charset "ascii";\n/*\\287 */'),
+                 'utf-8', 0, 'ascii', u'@charset "ascii";\n/*\\287 */'.encode()),
             # 5/5 default+unicode/default+unicode
             ('@import "x";', None, (None, u'/*\u0287*/')): (
-                 'utf-8', 0, 'utf-8', '/*\xca\x87*/')
+                 'utf-8', 0, 'utf-8', u'/*\u0287*/'.encode('utf-8'))
         }
         parser = cssutils.CSSParser()
         for test in tests:
         "cssutils.parseString nesting"
         # examples from csslist 27.11.2007
         tests = {
-            '@1; div{color:green}': u'div {\n    color: green\n    }', 
-            '@1 []; div{color:green}': u'div {\n    color: green\n    }', 
-            '@1 [{}]; div { color:green; }': u'div {\n    color: green\n    }', 
-            '@media all { @ } div{color:green}': 
+            '@1; div{color:green}': u'div {\n    color: green\n    }',
+            '@1 []; div{color:green}': u'div {\n    color: green\n    }',
+            '@1 [{}]; div { color:green; }': u'div {\n    color: green\n    }',
+            '@media all { @ } div{color:green}':
                 u'div {\n    color: green\n    }',
-            # should this be u''? 
+            # should this be u''?
             '@1 { [ } div{color:green}': u'',
             # red was eaten:
-            '@1 { [ } ] div{color:red}div{color:green}': u'div {\n    color: green\n    }', 
+            '@1 { [ } ] div{color:red}div{color:green}': u'div {\n    color: green\n    }',
              }
         for css, exp in tests.items():
             self.assertEqual(exp.encode(), cssutils.parseString(css).cssText)

src/tests/test_scripts_csscombine.py

         self.assertEqual(combined, ('@charset "ascii";' + self.C).encode())
 
         # cssText
-        cssText=open(csspath).read()
+        # TODO: really need binary or can handle str too?
+        cssText=open(csspath, mode="rb").read()
         combined = csscombine(cssText=cssText, href=cssurl)
         self.assertEqual(combined, self.C.encode())
         combined = csscombine(cssText=cssText, href=cssurl, 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.