File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change 22
22
import sys
23
23
import warnings
24
24
25
- from six import string_types , text_type
25
+ from six import string_types , text_type , PY2 , PY3
26
26
27
27
from _sass import OUTPUT_STYLES , compile_filename , compile_string
28
28
48
48
MODES = set (['string' , 'filename' , 'dirname' ])
49
49
50
50
51
+ def to_native_s (s ):
52
+ if isinstance (s , bytes ) and PY3 : # pragma: no cover (py3)
53
+ s = s .decode ('UTF-8' )
54
+ elif isinstance (s , text_type ) and PY2 : # pragma: no cover (py2)
55
+ s = s .encode ('UTF-8' )
56
+ return s
57
+
58
+
51
59
class CompileError (ValueError ):
52
60
"""The exception type that is raised by :func:`compile()`.
53
61
It is a subtype of :exc:`exceptions.ValueError`.
54
62
"""
63
+ def __init__ (self , msg ):
64
+ super (CompileError , self ).__init__ (to_native_s (msg ))
55
65
56
66
57
67
def mkdirp (path ):
Original file line number Diff line number Diff line change 13
13
import subprocess
14
14
import sys
15
15
import tempfile
16
+ import traceback
16
17
import unittest
17
18
import warnings
18
19
@@ -914,7 +915,7 @@ def test_error(self):
914
915
assert False , 'Expected to raise'
915
916
except sass .CompileError as e :
916
917
msg , = e .args
917
- assert msg .decode ( 'UTF-8' ). startswith (
918
+ assert msg .startswith (
918
919
'Error: Invalid CSS after '
919
920
), msg
920
921
return
@@ -1182,7 +1183,7 @@ def assert_raises_compile_error(expected):
1182
1183
with pytest .raises (sass .CompileError ) as excinfo :
1183
1184
yield
1184
1185
msg , = excinfo .value .args
1185
- assert msg . decode ( 'UTF-8' ) == expected , (msg , expected )
1186
+ assert msg == expected , (msg , expected )
1186
1187
1187
1188
1188
1189
class RegexMatcher (object ):
@@ -1417,3 +1418,17 @@ def test_map_with_map_key(self):
1417
1418
),
1418
1419
'a{content:baz}\n ' ,
1419
1420
)
1421
+
1422
+
1423
+ def test_stack_trace_formatting ():
1424
+ try :
1425
+ sass .compile (string = u'a{☃' )
1426
+ assert False , 'expected to raise CompileError'
1427
+ except sass .CompileError :
1428
+ tb = traceback .format_exc ()
1429
+ assert tb .endswith (
1430
+ 'CompileError: Error: Invalid CSS after "a{☃": expected "{", was ""\n '
1431
+ ' on line 1 of stdin\n '
1432
+ '>> a{☃\n '
1433
+ ' --^\n \n '
1434
+ )
You can’t perform that action at this time.
0 commit comments