1414import tempfile
1515import traceback
1616import unittest
17- import warnings
1817
1918import pytest
2019from six import StringIO , b , string_types , text_type
@@ -424,14 +423,11 @@ def test_compile_string_deprecated_source_comments_line_numbers(self):
424423 color: red;
425424 }'''
426425 expected = sass .compile (string = source , source_comments = True )
427- with warnings .catch_warnings (record = True ) as w :
428- warnings .simplefilter ('always' )
426+ with pytest .warns (FutureWarning ):
429427 actual = sass .compile (
430428 string = source ,
431429 source_comments = 'line_numbers' ,
432430 )
433- assert len (w ) == 1
434- assert issubclass (w [- 1 ].category , FutureWarning )
435431 assert expected == actual
436432
437433 def test_compile_filename (self ):
@@ -465,15 +461,12 @@ def test_compile_source_map_deprecated_source_comments_map(self):
465461 filename = filename ,
466462 source_map_filename = 'a.scss.css.map' ,
467463 )
468- with warnings .catch_warnings (record = True ) as w :
469- warnings .simplefilter ('always' )
464+ with pytest .warns (FutureWarning ):
470465 actual , actual_map = sass .compile (
471466 filename = filename ,
472467 source_comments = 'map' ,
473468 source_map_filename = 'a.scss.css.map' ,
474469 )
475- assert len (w ) == 1
476- assert issubclass (w [- 1 ].category , FutureWarning )
477470 assert expected == actual
478471 self .assert_source_map_equal (expected_map , actual_map )
479472
@@ -595,8 +588,7 @@ def test_output_style(self):
595588class ManifestTestCase (BaseTestCase ):
596589
597590 def test_normalize_manifests (self ):
598- with warnings .catch_warnings (record = True ) as w :
599- warnings .simplefilter ('always' )
591+ with pytest .warns (FutureWarning ) as warninfo :
600592 manifests = Manifest .normalize_manifests ({
601593 'package' : 'sass/path' ,
602594 'package.name' : ('sass/path' , 'css/path' ),
@@ -607,8 +599,7 @@ def test_normalize_manifests(self):
607599 'strip_extension' : True ,
608600 },
609601 })
610- assert len (w ) == 3
611- assert all (issubclass (x .category , FutureWarning ) for x in w )
602+ assert len (warninfo ) == 3
612603 assert len (manifests ) == 4
613604 assert isinstance (manifests ['package' ], Manifest )
614605 assert manifests ['package' ].sass_path == 'sass/path'
@@ -635,11 +626,8 @@ def replace_source_path(s, name):
635626 return s .replace ('SOURCE' , test_source_path (name ))
636627
637628 shutil .copytree ('test' , src_path )
638- with warnings .catch_warnings (record = True ) as w :
639- warnings .simplefilter ('always' )
629+ with pytest .warns (FutureWarning ):
640630 m = Manifest (sass_path = 'test' , css_path = 'css' )
641- assert len (w ) == 1
642- assert issubclass (w [- 1 ].category , FutureWarning )
643631
644632 m .build_one (d , 'a.scss' )
645633 with open (os .path .join (d , 'css' , 'a.scss.css' )) as f :
@@ -720,15 +708,12 @@ def test_wsgi_sass_middleware(self):
720708 with tempdir () as css_dir :
721709 src_dir = os .path .join (css_dir , 'src' )
722710 shutil .copytree ('test' , src_dir )
723- with warnings .catch_warnings (record = True ) as w :
724- warnings .simplefilter ('always' )
711+ with pytest .warns (FutureWarning ):
725712 app = SassMiddleware (
726713 self .sample_wsgi_app , {
727714 __name__ : (src_dir , css_dir , '/static' ),
728715 },
729716 )
730- assert len (w ) == 1
731- assert issubclass (w [- 1 ].category , FutureWarning )
732717 client = Client (app , Response )
733718 r = client .get ('/asdf' )
734719 assert r .status_code == 200
@@ -746,6 +731,27 @@ def test_wsgi_sass_middleware(self):
746731 self .assertEqual (b'/static/not-exists.sass.css' , r .data )
747732 assert r .mimetype == 'text/plain'
748733
734+ def test_wsgi_sass_middleware_without_extension (self ):
735+ with tempdir () as css_dir :
736+ src_dir = os .path .join (css_dir , 'src' )
737+ shutil .copytree ('test' , src_dir )
738+ app = SassMiddleware (
739+ self .sample_wsgi_app , {
740+ __name__ : {
741+ 'sass_path' : src_dir ,
742+ 'css_path' : css_dir ,
743+ 'wsgi_path' : '/static' ,
744+ 'strip_extension' : True ,
745+ },
746+ },
747+ )
748+ client = Client (app , Response )
749+ r = client .get ('/static/a.css' )
750+ assert r .status_code == 200
751+ expected = A_EXPECTED_CSS_WITH_MAP .replace ('.scss.css' , '.css' )
752+ self .assertEqual (expected .encode (), r .data )
753+ assert r .mimetype == 'text/css'
754+
749755
750756class DistutilsTestCase (BaseTestCase ):
751757
@@ -828,15 +834,12 @@ def test_pysassc_stdout(self):
828834 assert A_EXPECTED_CSS .strip () == self .out .getvalue ().strip ()
829835
830836 def test_sassc_stdout (self ):
831- with warnings .catch_warnings (record = True ) as w :
832- warnings .simplefilter ('always' )
837+ with pytest .warns (FutureWarning ) as warninfo :
833838 exit_code = sassc .main (
834839 ['sassc' , 'test/a.scss' ],
835840 self .out , self .err ,
836841 )
837- assert len (w ) == 1
838- assert issubclass (w [- 1 ].category , FutureWarning )
839- assert 'use `pysassc`' in str (w [- 1 ].message )
842+ assert 'use `pysassc`' in warninfo [0 ].message .args [0 ]
840843 assert exit_code == 0
841844 assert self .err .getvalue () == ''
842845 assert A_EXPECTED_CSS .strip () == self .out .getvalue ().strip ()
0 commit comments