def test_compass_import(monkeypatch, tmpdir): monkeypatch.setattr("static_precompiler.settings.ROOT", tmpdir.strpath) compiler = scss.SCSS(compass_enabled=True) assert ( compiler.compile_file("styles/sass/test-compass-import.scss") == "COMPILED/styles/sass/test-compass-import.css" ) full_output_path = compiler.get_full_output_path("styles/sass/test-compass-import.scss") assert os.path.exists(full_output_path) with open(full_output_path) as compiled: assert ( compiled.read() == """.round-corners { -moz-border-radius: 4px / 4px; -webkit-border-radius: 4px 4px; border-radius: 4px / 4px; } """ ) compiler = scss.SCSS(compass_enabled=False) with pytest.raises(exceptions.StaticCompilationError): compiler.compile_file("styles/sass/test-compass-import.scss")
def test_get_extra_args(): assert scss.SCSS().get_extra_args() == [] assert scss.SCSS(compass_enabled=True, load_paths=["foo", "bar"]).get_extra_args() == [ "-I", "foo", "-I", "bar", "--compass", ] with pytest.raises(ValueError): scss.SCSS(load_paths="foo")
def test_find_imports(): source = """ @import "foo.css", ; @import " "; @import "foo.scss"; @import "foo"; @import "foo.css"; /* @import "multi-line-comment"; */ @import "foo" screen; @import "http://foo.com/bar"; @import url(foo); // `.class-name { @import "single-line-comment"; }`). @import "rounded-corners", "text-shadow"; @import "compass"; @import "compass.scss"; @import "compass/css3"; @import url(http://fonts.googleapis.com/css?family=Arvo:400,700,400italic,700italic); @import url("http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,700,600,300"); @import "foo,bar", url(bar,baz), 'bar,foo'; """ expected = [ "bar,foo", "compass", "compass.scss", "compass/css3", "foo", "foo,bar", "foo.scss", "rounded-corners", "text-shadow", ] compiler = scss.SCSS(compass_enabled=False) assert compiler.find_imports(source) == expected compiler = scss.SCSS(compass_enabled=True) expected = [ "bar,foo", "foo", "foo,bar", "foo.scss", "rounded-corners", "text-shadow", ] assert compiler.find_imports(source) == expected
def test_get_extra_args(): assert scss.SCSS().get_extra_args() == [] assert scss.SCSS( compass_enabled=True, load_paths=["foo", "bar"], precision=10, output_style="compact" ).get_extra_args() == [ "-I", "foo", "-I", "bar", "--compass", "--precision", "10", "-t", "compact", ] with pytest.raises(ValueError): scss.SCSS(load_paths="foo")
def test_compass(monkeypatch, tmpdir): monkeypatch.setattr("static_precompiler.settings.ROOT", tmpdir.strpath) compiler = scss.SCSS(compass_enabled=True) assert compiler.compile_file("test-compass.scss") == "COMPILED/test-compass.css" full_output_path = compiler.get_full_output_path("test-compass.scss") assert os.path.exists(full_output_path) with open(full_output_path) as compiled: assert compiled.read() == """p {
def test_strip_comments(compiler_module): source = """ // Single-line comment a { color: red; font-family: "Foo // Bar"; background-image: url(/* not a comment */); // Another comment } /* This is * * a multiline comment */ p { /* This is also a comment */ color: blue; background-image: url(//not-a-comment.com); // comment } """ compiler = scss.SCSS() assert ( compiler.strip_comments(source) == """ a { color: red; font-family: "Foo // Bar"; background-image: url(/* not a comment */); } p { color: blue; background-image: url(//not-a-comment.com); } """ )