本文整理汇总了Python中static_precompiler.compilers.LESS类的典型用法代码示例。如果您正苦于以下问题:Python LESS类的具体用法?Python LESS怎么用?Python LESS使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LESS类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_find_imports
def test_find_imports(self):
compiler = LESS()
source = """
@import "foo.css";
@import " ";
@import "foo.less";
@import "@{VAR}.less";
@import (reference) "reference.less";
@import (inline) "inline.css";
@import (less) "less.less";
@import (css) "css.css";
@import (once) "once.less";
@import (multiple) "multiple.less";
@import "screen.less" screen;
@import url(url-import);
@import 'single-quotes.less';
@import "no-extension";
"""
expected = sorted([
"foo.less",
"global-var.less",
"reference.less",
"inline.css",
"less.less",
"once.less",
"multiple.less",
"screen.less",
"single-quotes.less",
"no-extension",
])
self.assertEqual(
compiler.find_imports(source),
expected
)
示例2: test_get_output_filename
def test_get_output_filename(self):
compiler = LESS()
self.assertEqual(compiler.get_output_filename("dummy.less"), "dummy.css")
self.assertEqual(
compiler.get_output_filename("dummy.less.less"),
"dummy.less.css"
)
示例3: test_find_dependencies
def test_find_dependencies(self):
compiler = LESS()
files = {
"A.less": "@import 'B/C.less';",
"B/C.less": "@import '../E';",
"E.less": "p {color: red;}",
}
compiler.get_source = MagicMock(side_effect=lambda x: files[x])
root = os.path.dirname(__file__)
existing_files = set()
for f in files:
existing_files.add(os.path.join(root, "static", normalize_path(f)))
with patch("os.path.exists") as mocked_os_path_exist:
mocked_os_path_exist.side_effect = lambda x: x in existing_files
self.assertEqual(
compiler.find_dependencies("A.less"),
["B/C.less", "E.less"]
)
self.assertEqual(
compiler.find_dependencies("B/C.less"),
["E.less"]
)
self.assertEqual(
compiler.find_dependencies("E.less"),
[]
)
示例4: test_find_imports
def test_find_imports(self):
compiler = LESS()
source = """
@import "foo.css", ;
@import " ";
@import "foo.less";
@import (less) "bar";
@import "foo";
@import "foo.css";
@import "foo" screen;
@import "http://foo.com/bar";
@import url(foo);
@import "rounded-corners", "text-shadow";
"""
expected = [
"bar",
"foo",
"foo.less",
"rounded-corners",
"text-shadow",
]
self.assertEqual(
compiler.find_imports(source),
expected
)
示例5: test_postprocesss
def test_postprocesss(monkeypatch):
compiler = LESS()
convert_urls = call_recorder(lambda *args: "spam")
monkeypatch.setattr("static_precompiler.compilers.less.convert_urls", convert_urls)
assert compiler.postprocess("ham", "eggs") == "spam"
assert convert_urls.calls == [call("ham", "eggs")]
示例6: test_compile_source
def test_compile_source():
compiler = LESS()
assert compiler.compile_source("p {font-size: 15px; a {color: red;}}") == "p {\n font-size: 15px;\n}\np a {\n color: red;\n}\n"
with pytest.raises(StaticCompilationError):
compiler.compile_source('invalid syntax')
# Test non-ascii
NON_ASCII = """.external_link:first-child:before {
content: "Zobacz także:";
background: url(картинка.png);
}
"""
assert compiler.compile_source(NON_ASCII) == NON_ASCII
示例7: test_compile_file
def test_compile_file(self):
compiler = LESS()
self.assertEqual(
compiler.compile_file("styles/test.less"),
"""p {
font-size: 15px;
}
p a {
color: #ff0000;
}
h1 {
color: blue;
}
"""
)
示例8: test_find_dependencies
def test_find_dependencies(monkeypatch):
compiler = LESS()
files = {
"A.less": "@import 'B/C.less';",
"B/C.less": "@import '../E';",
"E.less": "p {color: red;}",
}
monkeypatch.setattr("static_precompiler.compilers.less.LESS.get_source", lambda self, x: files[x])
root = os.path.dirname(__file__)
existing_files = set()
for f in files:
existing_files.add(os.path.join(root, "static", normalize_path(f)))
monkeypatch.setattr("os.path.exists", lambda path: path in existing_files)
assert compiler.find_dependencies("A.less") == ["B/C.less", "E.less"]
assert compiler.find_dependencies("B/C.less") == ["E.less"]
assert compiler.find_dependencies("E.less") == []
示例9: test_locate_imported_file
def test_locate_imported_file(self):
compiler = LESS()
with patch("os.path.exists") as mocked_os_path_exist:
root = os.path.dirname(__file__)
existing_files = set()
for f in ("A/B.less", "D.less"):
existing_files.add(os.path.join(root, "static", normalize_path(f)))
mocked_os_path_exist.side_effect = lambda x: x in existing_files
self.assertEqual(
compiler.locate_imported_file("A", "B.less"),
"A/B.less"
)
self.assertEqual(
compiler.locate_imported_file("E", "../D"),
"D.less"
)
self.assertEqual(
compiler.locate_imported_file("E", "../A/B.less"),
"A/B.less"
)
self.assertEqual(
compiler.locate_imported_file("", "D.less"),
"D.less"
)
self.assertRaises(
StaticCompilationError,
lambda: compiler.locate_imported_file("", "Z.less")
)
示例10: test_locate_imported_file
def test_locate_imported_file(self):
compiler = LESS()
with patch("os.path.exists") as mocked_os_path_exist:
existing_files = set()
for f in ("A/B.less", "D.less"):
existing_files.add(os.path.join(STATIC_ROOT, f))
mocked_os_path_exist.side_effect = lambda x: x in existing_files
self.assertEqual(
compiler.locate_imported_file("A", "B.less"),
"A/B.less"
)
self.assertEqual(
compiler.locate_imported_file("E", "../D"),
"D.less"
)
self.assertEqual(
compiler.locate_imported_file("E", "../A/B.less"),
"A/B.less"
)
self.assertEqual(
compiler.locate_imported_file("", "D.less"),
"D.less"
)
self.assertRaises(
StaticCompilationError,
lambda: compiler.locate_imported_file("", "Z.less")
)
示例11: test_compile_source
def test_compile_source(self):
compiler = LESS()
self.assertEqual(
compiler.compile_source("p {font-size: 15px; a {color: red;}}"),
"p {\n font-size: 15px;\n}\np a {\n color: red;\n}\n"
)
self.assertRaises(
StaticCompilationError,
lambda: compiler.compile_source('invalid syntax')
)
# Test non-ascii
NON_ASCII = """.external_link:first-child:before {
content: "Zobacz także:";
background: url(картинка.png);
}
"""
self.assertEqual(
compiler.compile_source(NON_ASCII),
NON_ASCII
)
示例12: test_locate_imported_file
def test_locate_imported_file(monkeypatch):
compiler = LESS()
root = os.path.dirname(__file__)
existing_files = set()
for f in ("A/B.less", "D.less"):
existing_files.add(os.path.join(root, "static", normalize_path(f)))
monkeypatch.setattr("os.path.exists", lambda path: path in existing_files)
assert compiler.locate_imported_file("A", "B.less") == "A/B.less"
assert compiler.locate_imported_file("E", "../D") == "D.less"
assert compiler.locate_imported_file("E", "../A/B.less") == "A/B.less"
assert compiler.locate_imported_file("", "D.less") == "D.less"
with pytest.raises(StaticCompilationError):
compiler.locate_imported_file("", "Z.less")
示例13: test_postprocesss
def test_postprocesss(self):
compiler = LESS()
with patch("static_precompiler.compilers.less.convert_urls") as mocked_convert_urls:
mocked_convert_urls.return_value = "spam"
self.assertEqual(compiler.postprocess("ham", "eggs"), "spam")
mocked_convert_urls.assert_called_with("ham", "eggs")
示例14: test_is_supported
def test_is_supported(self):
compiler = LESS()
self.assertEqual(compiler.is_supported("dummy"), False)
self.assertEqual(compiler.is_supported("dummy.less"), True)
示例15: test_compile_file
def test_compile_file():
compiler = LESS()
assert compiler.compile_file("styles/test.less") == """p {