@@ -143,6 +143,14 @@ def normalize_path(path):
143143re_base64_data_uri = re .compile (r'^data:[^;]*?;base64,(.+)$' )
144144
145145
146+ def _map_in_output_dir (s ):
147+ def cb (match ):
148+ filename = os .path .basename (match .group (1 ))
149+ return '/*# sourceMappingURL={} */' .format (filename )
150+
151+ return re_sourcemap_url .sub (cb , s )
152+
153+
146154@pytest .fixture (autouse = True )
147155def no_warnings (recwarn ):
148156 yield
@@ -696,12 +704,6 @@ def test_build_one(self):
696704 with tempdir () as d :
697705 src_path = os .path .join (d , 'test' )
698706
699- def test_source_path (* path ):
700- return normalize_path (os .path .join (d , 'test' , * path ))
701-
702- def replace_source_path (s , name ):
703- return s .replace ('SOURCE' , test_source_path (name ))
704-
705707 shutil .copytree ('test' , src_path )
706708 with pytest .warns (FutureWarning ):
707709 m = Manifest (sass_path = 'test' , css_path = 'css' )
@@ -713,14 +715,11 @@ def replace_source_path(s, name):
713715 with io .open (
714716 os .path .join (d , 'css' , 'b.scss.css' ), encoding = 'UTF-8' ,
715717 ) as f :
716- self .assertEqual (
717- replace_source_path (B_EXPECTED_CSS_WITH_MAP , 'b.scss' ),
718- f .read (),
719- )
718+ assert f .read () == _map_in_output_dir (B_EXPECTED_CSS_WITH_MAP )
720719 self .assert_source_map_file (
721720 {
722721 'version' : 3 ,
723- 'file' : '../test/b .css' ,
722+ 'file' : 'b.scss .css' ,
724723 'sources' : ['../test/b.scss' ],
725724 'names' : [],
726725 'mappings' : (
@@ -734,14 +733,11 @@ def replace_source_path(s, name):
734733 with io .open (
735734 os .path .join (d , 'css' , 'd.scss.css' ), encoding = 'UTF-8' ,
736735 ) as f :
737- assert (
738- replace_source_path (D_EXPECTED_CSS_WITH_MAP , 'd.scss' ) ==
739- f .read ()
740- )
736+ assert f .read () == _map_in_output_dir (D_EXPECTED_CSS_WITH_MAP )
741737 self .assert_source_map_file (
742738 {
743739 'version' : 3 ,
744- 'file' : '../test/d .css' ,
740+ 'file' : 'd.scss .css' ,
745741 'sources' : ['../test/d.scss' ],
746742 'names' : [],
747743 'mappings' : (
@@ -799,7 +795,7 @@ def test_wsgi_sass_middleware(self):
799795 r = client .get ('/static/a.scss.css' )
800796 assert r .status_code == 200
801797 self .assertEqual (
802- b (A_EXPECTED_CSS_WITH_MAP ),
798+ b (_map_in_output_dir ( A_EXPECTED_CSS_WITH_MAP ) ),
803799 r .data ,
804800 )
805801 assert r .mimetype == 'text/css'
@@ -825,32 +821,30 @@ def test_wsgi_sass_middleware_without_extension(self):
825821 client = Client (app , Response )
826822 r = client .get ('/static/a.css' )
827823 assert r .status_code == 200
828- expected = A_EXPECTED_CSS_WITH_MAP .replace ('.scss.css' , '.css' )
824+ expected = A_EXPECTED_CSS_WITH_MAP
825+ expected = expected .replace ('.scss.css' , '.css' )
826+ expected = _map_in_output_dir (expected )
829827 self .assertEqual (expected .encode (), r .data )
830828 assert r .mimetype == 'text/css'
831829
832830 def test_wsgi_sass_middleware_without_extension_sass (self ):
833831 with tempdir () as css_dir :
834- src_dir = os .path .join (css_dir , 'src' )
835- os .makedirs (src_dir )
836- with open (os .path .join (src_dir , 'a.sass' ), 'w' ) as f :
837- f .write ('a\n \t b\n \t \t color: blue;' )
838832 app = SassMiddleware (
839833 self .sample_wsgi_app , {
840834 __name__ : {
841- 'sass_path' : src_dir ,
835+ 'sass_path' : 'test' ,
842836 'css_path' : css_dir ,
843837 'wsgi_path' : '/static' ,
844838 'strip_extension' : True ,
845839 },
846840 },
847841 )
848842 client = Client (app , Response )
849- r = client .get ('/static/a .css' )
843+ r = client .get ('/static/h .css' )
850844 assert r .status_code == 200
851845 expected = (
852846 'a b {\n color: blue; }\n \n '
853- '/*# sourceMappingURL=../a .css.map */'
847+ '/*# sourceMappingURL=h .css.map */'
854848 )
855849 self .assertEqual (expected .encode (), r .data )
856850 assert r .mimetype == 'text/css'
0 commit comments