21
21
from sassutils .wsgi import SassMiddleware
22
22
23
23
24
+ if os .sep != '/' and os .altsep :
25
+ def normalize_path (path ):
26
+ path = os .path .abspath (os .path .normpath (path ))
27
+ return path .replace (os .sep , os .altsep )
28
+
29
+ def normalize_source_map_path (path ):
30
+ """To workaround strange path separators made by libsass ---
31
+ which seems a bug of libsass on win32.
32
+
33
+ """
34
+ return path .replace (os .altsep , '//' )
35
+ else :
36
+ def normalize_path (path ):
37
+ return path
38
+
39
+ normalize_source_map_path = normalize_path
40
+
41
+
24
42
A_EXPECTED_CSS = '''\
25
43
body {
26
44
background-color: green; }
41
59
A_EXPECTED_MAP = {
42
60
'version' : 3 ,
43
61
'file' : 'test/a.css' ,
44
- 'sources' : ['test/a.scss' ],
62
+ 'sources' : [normalize_source_map_path ( 'test/a.scss' ) ],
45
63
'names' : [],
46
64
'mappings' : ';AAKA;EAHE,kBAAkB;;EAIpB,KAAK;IAED,OAAO'
47
65
}
@@ -233,7 +251,7 @@ def test_compile_source_map(self):
233
251
self .assertEqual (
234
252
A_EXPECTED_CSS_WITH_MAP .replace (
235
253
'SOURCE' ,
236
- os . path . abspath (filename )
254
+ normalize_path (filename )
237
255
),
238
256
actual
239
257
)
@@ -342,13 +360,7 @@ def test_normalize_manifests(self):
342
360
def test_build_one (self ):
343
361
d = tempfile .mkdtemp ()
344
362
src_path = os .path .join (d , 'test' )
345
- if os .sep != '/' and os .altsep :
346
- normalize = lambda p : os .path .abspath (
347
- os .path .normpath (os .path .join (src_path , p ))
348
- ).replace (os .sep , os .altsep )
349
- else :
350
- normalize = lambda p : p
351
- test_source_path = lambda * path : normalize (
363
+ test_source_path = lambda * path : normalize_path (
352
364
os .path .join (d , 'test' , * path )
353
365
)
354
366
replace_source_path = lambda s , name : s .replace (
@@ -372,7 +384,7 @@ def test_build_one(self):
372
384
{
373
385
'version' : 3 ,
374
386
'file' : '../test/b.css' ,
375
- 'sources' : [normalize ('../test/b.scss' )],
387
+ 'sources' : [normalize_source_map_path ('../test/b.scss' )],
376
388
'names' : [],
377
389
'mappings' : ';AAAA,EAAE;EAEE,WAAW'
378
390
},
@@ -389,7 +401,7 @@ def test_build_one(self):
389
401
{
390
402
'version' : 3 ,
391
403
'file' : '../test/d.css' ,
392
- 'sources' : [normalize ('../test/d.scss' )],
404
+ 'sources' : [normalize_source_map_path ('../test/d.scss' )],
393
405
'names' : [],
394
406
'mappings' : ';AAKA;EAHE,kBAAkB;;EAIpB,KAAK;IAED,MAAM'
395
407
},
@@ -431,7 +443,7 @@ def test_wsgi_sass_middleware(self):
431
443
self .assertEqual ('text/plain' , r .mimetype )
432
444
r = client .get ('/static/a.scss.css' )
433
445
self .assertEqual (200 , r .status_code )
434
- src_path = os . path . abspath (os .path .join (src_dir , 'a.scss' ))
446
+ src_path = normalize_path (os .path .join (src_dir , 'a.scss' ))
435
447
self .assert_bytes_equal (
436
448
b (A_EXPECTED_CSS_WITH_MAP .replace ('SOURCE' , src_path )),
437
449
r .data
@@ -538,7 +550,9 @@ def test_sassc_sourcemap(self):
538
550
self .assertEqual ('' , self .out .getvalue ())
539
551
with open (out_filename ) as f :
540
552
self .assertEqual (
541
- A_EXPECTED_CSS_WITH_MAP .replace ('SOURCE' , src_filename ),
553
+ A_EXPECTED_CSS_WITH_MAP .replace (
554
+ 'SOURCE' , normalize_path (src_filename )
555
+ ),
542
556
f .read ().strip ()
543
557
)
544
558
with open (out_filename + '.map' ) as f :
0 commit comments