Skip to content
This repository
Browse code

Fix unicode in tests with Python 2.x

  • Loading branch information...
commit 06da45755992e1ea80364f254c064e4a6e36af07 1 parent 12e0452
Simon Sapin authored June 14, 2012
2  cssselect/parser.py
@@ -539,7 +539,7 @@ def __new__(cls, type_, value, pos):
539 539
         return obj
540 540
 
541 541
     def __repr__(self):
542  
-        return '<%s %r at %i>' % (self.type, self.value, self.pos)
  542
+        return "<%s '%s' at %i>" % (self.type, self.value, self.pos)
543 543
 
544 544
     def is_delim(self, *values):
545 545
         return self.type == 'DELIM' and self.value in values
13  cssselect/tests.py
@@ -39,16 +39,15 @@ def u(text):
39 39
 class TestCssselect(unittest.TestCase):
40 40
     def test_tokenizer(self):
41 41
         tokens = [
42  
-            repr(item).replace("u'", "'")  # Py 2/3
43  
-            for item in tokenize(
  42
+            _unicode(item) for item in tokenize(
44 43
                 u(r'E\ é > f [a~="y\"x"]:nth(/* fu /]* */-3.7)'))]
45 44
         assert tokens == [
46  
-            "<IDENT 'E é' at 0>",
  45
+            u("<IDENT 'E é' at 0>"),
47 46
             "<S ' ' at 4>",
48 47
             "<DELIM '>' at 5>",
49 48
             "<S ' ' at 6>",
50 49
             # the no-break space is not whitespace in CSS
51  
-            r"<IDENT 'f\xa0' at 7>",
  50
+            u("<IDENT 'f ' at 7>"),  # f\xa0
52 51
             "<DELIM '[' at 9>",
53 52
             "<IDENT 'a' at 10>",
54 53
             "<DELIM '~' at 11>",
@@ -294,7 +293,7 @@ def get_error(css):
294 293
 
295 294
     def test_translation(self):
296 295
         def xpath(css):
297  
-            return str(GenericTranslator().css_to_xpath(css, prefix=''))
  296
+            return _unicode(GenericTranslator().css_to_xpath(css, prefix=''))
298 297
 
299 298
         assert xpath('*') == "*"
300 299
         assert xpath('e') == "e"
@@ -378,11 +377,11 @@ def xpath(css):
378 377
 
379 378
         # Invalid characters in XPath element names
380 379
         assert xpath(r'di\a0 v') == (
381  
-            "*[name() = 'di\xa0v']")
  380
+            u("*[name() = 'di v']"))  # di\xa0v
382 381
         assert xpath(r'di\[v') == (
383 382
             "*[name() = 'di[v']")
384 383
         assert xpath(r'[h\a0 ref]') == (
385  
-            "*[attribute::*[name() = 'h\xa0ref']]")
  384
+            u("*[attribute::*[name() = 'h ref']]"))  # h\xa0ref
386 385
         assert xpath(r'[h\]ref]') == (
387 386
             "*[attribute::*[name() = 'h]ref']]")
388 387
 

0 notes on commit 06da457

Please sign in to comment.
Something went wrong with that request. Please try again.