diff --git a/.travis.yml b/.travis.yml index 5c1aa2d8..0d716726 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: python dist: trusty matrix: include: - - python: pypy-5.4.1 + - python: pypy2.7-5.10.0 - python: 3.7 dist: xenial sudo: required diff --git a/sasstests.py b/sasstests.py index 597e539e..4351ef33 100644 --- a/sasstests.py +++ b/sasstests.py @@ -14,7 +14,6 @@ import tempfile import traceback import unittest -import warnings import pytest from six import StringIO, b, string_types, text_type @@ -424,14 +423,11 @@ def test_compile_string_deprecated_source_comments_line_numbers(self): color: red; }''' expected = sass.compile(string=source, source_comments=True) - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter('always') + with pytest.warns(FutureWarning): actual = sass.compile( string=source, source_comments='line_numbers', ) - assert len(w) == 1 - assert issubclass(w[-1].category, FutureWarning) assert expected == actual def test_compile_filename(self): @@ -465,15 +461,12 @@ def test_compile_source_map_deprecated_source_comments_map(self): filename=filename, source_map_filename='a.scss.css.map', ) - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter('always') + with pytest.warns(FutureWarning): actual, actual_map = sass.compile( filename=filename, source_comments='map', source_map_filename='a.scss.css.map', ) - assert len(w) == 1 - assert issubclass(w[-1].category, FutureWarning) assert expected == actual self.assert_source_map_equal(expected_map, actual_map) @@ -595,8 +588,7 @@ def test_output_style(self): class ManifestTestCase(BaseTestCase): def test_normalize_manifests(self): - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter('always') + with pytest.warns(FutureWarning) as warninfo: manifests = Manifest.normalize_manifests({ 'package': 'sass/path', 'package.name': ('sass/path', 'css/path'), @@ -607,8 +599,7 @@ def test_normalize_manifests(self): 'strip_extension': True, }, }) - assert len(w) == 3 - assert all(issubclass(x.category, FutureWarning) for x in w) + assert len(warninfo) == 3 assert len(manifests) == 4 assert isinstance(manifests['package'], Manifest) assert manifests['package'].sass_path == 'sass/path' @@ -635,11 +626,8 @@ def replace_source_path(s, name): return s.replace('SOURCE', test_source_path(name)) shutil.copytree('test', src_path) - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter('always') + with pytest.warns(FutureWarning): m = Manifest(sass_path='test', css_path='css') - assert len(w) == 1 - assert issubclass(w[-1].category, FutureWarning) m.build_one(d, 'a.scss') with open(os.path.join(d, 'css', 'a.scss.css')) as f: @@ -720,15 +708,12 @@ def test_wsgi_sass_middleware(self): with tempdir() as css_dir: src_dir = os.path.join(css_dir, 'src') shutil.copytree('test', src_dir) - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter('always') + with pytest.warns(FutureWarning): app = SassMiddleware( self.sample_wsgi_app, { __name__: (src_dir, css_dir, '/static'), }, ) - assert len(w) == 1 - assert issubclass(w[-1].category, FutureWarning) client = Client(app, Response) r = client.get('/asdf') assert r.status_code == 200 @@ -746,6 +731,27 @@ def test_wsgi_sass_middleware(self): self.assertEqual(b'/static/not-exists.sass.css', r.data) assert r.mimetype == 'text/plain' + def test_wsgi_sass_middleware_without_extension(self): + with tempdir() as css_dir: + src_dir = os.path.join(css_dir, 'src') + shutil.copytree('test', src_dir) + app = SassMiddleware( + self.sample_wsgi_app, { + __name__: { + 'sass_path': src_dir, + 'css_path': css_dir, + 'wsgi_path': '/static', + 'strip_extension': True, + }, + }, + ) + client = Client(app, Response) + r = client.get('/static/a.css') + assert r.status_code == 200 + expected = A_EXPECTED_CSS_WITH_MAP.replace('.scss.css', '.css') + self.assertEqual(expected.encode(), r.data) + assert r.mimetype == 'text/css' + class DistutilsTestCase(BaseTestCase): @@ -828,15 +834,12 @@ def test_pysassc_stdout(self): assert A_EXPECTED_CSS.strip() == self.out.getvalue().strip() def test_sassc_stdout(self): - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter('always') + with pytest.warns(FutureWarning) as warninfo: exit_code = sassc.main( ['sassc', 'test/a.scss'], self.out, self.err, ) - assert len(w) == 1 - assert issubclass(w[-1].category, FutureWarning) - assert 'use `pysassc`' in str(w[-1].message) + assert 'use `pysassc`' in warninfo[0].message.args[0] assert exit_code == 0 assert self.err.getvalue() == '' assert A_EXPECTED_CSS.strip() == self.out.getvalue().strip() diff --git a/sassutils/builder.py b/sassutils/builder.py index 33060f57..29e48786 100644 --- a/sassutils/builder.py +++ b/sassutils/builder.py @@ -188,6 +188,20 @@ def resolve_filename(self, package_dir, filename): css_path = os.path.join(package_dir, self.css_path, css_filename) return sass_path, css_path + def unresolve_filename(self, filename): + """Retrieves the probable source path from the output filename. Pass + in a .css path to get out a .scss path. + + :param filename: the css filename + :type filename: :class:`str` + :returns: the scss filename + :rtype: :class:`str` + """ + filename, _ = os.path.splitext(filename) + if self.strip_extension: + filename = filename + '.scss' + return filename + def build(self, package_dir, output_style='nested'): """Builds the Sass/SCSS files in the specified :attr:`sass_path`. It finds :attr:`sass_path` and locates :attr:`css_path` diff --git a/sassutils/wsgi.py b/sassutils/wsgi.py index 4ae75ebe..29f5faf5 100644 --- a/sassutils/wsgi.py +++ b/sassutils/wsgi.py @@ -125,7 +125,7 @@ def __call__(self, environ, start_response): if not path.startswith(prefix): continue css_filename = path[len(prefix):] - sass_filename = css_filename[:-4] + sass_filename = manifest.unresolve_filename(css_filename) try: result = manifest.build_one( package_dir,
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: