14
14
import tempfile
15
15
import traceback
16
16
import unittest
17
- import warnings
18
17
19
18
import pytest
20
19
from six import StringIO , b , string_types , text_type
@@ -424,14 +423,11 @@ def test_compile_string_deprecated_source_comments_line_numbers(self):
424
423
color: red;
425
424
}'''
426
425
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 ):
429
427
actual = sass .compile (
430
428
string = source ,
431
429
source_comments = 'line_numbers' ,
432
430
)
433
- assert len (w ) == 1
434
- assert issubclass (w [- 1 ].category , FutureWarning )
435
431
assert expected == actual
436
432
437
433
def test_compile_filename (self ):
@@ -465,15 +461,12 @@ def test_compile_source_map_deprecated_source_comments_map(self):
465
461
filename = filename ,
466
462
source_map_filename = 'a.scss.css.map' ,
467
463
)
468
- with warnings .catch_warnings (record = True ) as w :
469
- warnings .simplefilter ('always' )
464
+ with pytest .warns (FutureWarning ):
470
465
actual , actual_map = sass .compile (
471
466
filename = filename ,
472
467
source_comments = 'map' ,
473
468
source_map_filename = 'a.scss.css.map' ,
474
469
)
475
- assert len (w ) == 1
476
- assert issubclass (w [- 1 ].category , FutureWarning )
477
470
assert expected == actual
478
471
self .assert_source_map_equal (expected_map , actual_map )
479
472
@@ -595,8 +588,7 @@ def test_output_style(self):
595
588
class ManifestTestCase (BaseTestCase ):
596
589
597
590
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 :
600
592
manifests = Manifest .normalize_manifests ({
601
593
'package' : 'sass/path' ,
602
594
'package.name' : ('sass/path' , 'css/path' ),
@@ -607,8 +599,7 @@ def test_normalize_manifests(self):
607
599
'strip_extension' : True ,
608
600
},
609
601
})
610
- assert len (w ) == 3
611
- assert all (issubclass (x .category , FutureWarning ) for x in w )
602
+ assert len (warninfo ) == 3
612
603
assert len (manifests ) == 4
613
604
assert isinstance (manifests ['package' ], Manifest )
614
605
assert manifests ['package' ].sass_path == 'sass/path'
@@ -635,11 +626,8 @@ def replace_source_path(s, name):
635
626
return s .replace ('SOURCE' , test_source_path (name ))
636
627
637
628
shutil .copytree ('test' , src_path )
638
- with warnings .catch_warnings (record = True ) as w :
639
- warnings .simplefilter ('always' )
629
+ with pytest .warns (FutureWarning ):
640
630
m = Manifest (sass_path = 'test' , css_path = 'css' )
641
- assert len (w ) == 1
642
- assert issubclass (w [- 1 ].category , FutureWarning )
643
631
644
632
m .build_one (d , 'a.scss' )
645
633
with open (os .path .join (d , 'css' , 'a.scss.css' )) as f :
@@ -720,15 +708,12 @@ def test_wsgi_sass_middleware(self):
720
708
with tempdir () as css_dir :
721
709
src_dir = os .path .join (css_dir , 'src' )
722
710
shutil .copytree ('test' , src_dir )
723
- with warnings .catch_warnings (record = True ) as w :
724
- warnings .simplefilter ('always' )
711
+ with pytest .warns (FutureWarning ):
725
712
app = SassMiddleware (
726
713
self .sample_wsgi_app , {
727
714
__name__ : (src_dir , css_dir , '/static' ),
728
715
},
729
716
)
730
- assert len (w ) == 1
731
- assert issubclass (w [- 1 ].category , FutureWarning )
732
717
client = Client (app , Response )
733
718
r = client .get ('/asdf' )
734
719
assert r .status_code == 200
@@ -746,6 +731,27 @@ def test_wsgi_sass_middleware(self):
746
731
self .assertEqual (b'/static/not-exists.sass.css' , r .data )
747
732
assert r .mimetype == 'text/plain'
748
733
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
+
749
755
750
756
class DistutilsTestCase (BaseTestCase ):
751
757
@@ -828,15 +834,12 @@ def test_pysassc_stdout(self):
828
834
assert A_EXPECTED_CSS .strip () == self .out .getvalue ().strip ()
829
835
830
836
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 :
833
838
exit_code = sassc .main (
834
839
['sassc' , 'test/a.scss' ],
835
840
self .out , self .err ,
836
841
)
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 ]
840
843
assert exit_code == 0
841
844
assert self .err .getvalue () == ''
842
845
assert A_EXPECTED_CSS .strip () == self .out .getvalue ().strip ()
0 commit comments