Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit 713d7a8

Browse files
committed
Windows compatibility fixes
1 parent 4434012 commit 713d7a8

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

sasstests.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@
2121
from sassutils.wsgi import SassMiddleware
2222

2323

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+
2442
A_EXPECTED_CSS = '''\
2543
body {
2644
background-color: green; }
@@ -41,7 +59,7 @@
4159
A_EXPECTED_MAP = {
4260
'version': 3,
4361
'file': 'test/a.css',
44-
'sources': ['test/a.scss'],
62+
'sources': [normalize_source_map_path('test/a.scss')],
4563
'names': [],
4664
'mappings': ';AAKA;EAHE,kBAAkB;;EAIpB,KAAK;IAED,OAAO'
4765
}
@@ -233,7 +251,7 @@ def test_compile_source_map(self):
233251
self.assertEqual(
234252
A_EXPECTED_CSS_WITH_MAP.replace(
235253
'SOURCE',
236-
os.path.abspath(filename)
254+
normalize_path(filename)
237255
),
238256
actual
239257
)
@@ -342,13 +360,7 @@ def test_normalize_manifests(self):
342360
def test_build_one(self):
343361
d = tempfile.mkdtemp()
344362
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(
352364
os.path.join(d, 'test', *path)
353365
)
354366
replace_source_path = lambda s, name: s.replace(
@@ -372,7 +384,7 @@ def test_build_one(self):
372384
{
373385
'version': 3,
374386
'file': '../test/b.css',
375-
'sources': [normalize('../test/b.scss')],
387+
'sources': [normalize_source_map_path('../test/b.scss')],
376388
'names': [],
377389
'mappings': ';AAAA,EAAE;EAEE,WAAW'
378390
},
@@ -389,7 +401,7 @@ def test_build_one(self):
389401
{
390402
'version': 3,
391403
'file': '../test/d.css',
392-
'sources': [normalize('../test/d.scss')],
404+
'sources': [normalize_source_map_path('../test/d.scss')],
393405
'names': [],
394406
'mappings': ';AAKA;EAHE,kBAAkB;;EAIpB,KAAK;IAED,MAAM'
395407
},
@@ -431,7 +443,7 @@ def test_wsgi_sass_middleware(self):
431443
self.assertEqual('text/plain', r.mimetype)
432444
r = client.get('/static/a.scss.css')
433445
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'))
435447
self.assert_bytes_equal(
436448
b(A_EXPECTED_CSS_WITH_MAP.replace('SOURCE', src_path)),
437449
r.data
@@ -538,7 +550,9 @@ def test_sassc_sourcemap(self):
538550
self.assertEqual('', self.out.getvalue())
539551
with open(out_filename) as f:
540552
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+
),
542556
f.read().strip()
543557
)
544558
with open(out_filename + '.map') as f:

0 commit comments

Comments
 (0)