1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
"""
Test the high-level compile function
"""
import unittest
from six import StringIO
from lesscpy import compile
class TestCompileFunction(unittest.TestCase):
"""
Unit tests for compile
"""
def test_compile_from_stream(self):
"""
It can compile input from a file-like object
"""
output = compile(StringIO("a { border-width: 2px * 3; }"), minify=True)
self.assertEqual(output, "a{border-width:6px;}")
def test_compile_from_file(self):
"""
It can compile input from a file object
"""
import tempfile
in_file = tempfile.NamedTemporaryFile(mode='w+')
in_file.write("a { border-width: 2px * 3; }")
in_file.seek(0)
output = compile(in_file, minify=True)
self.assertEqual(output, "a{border-width:6px;}")
def test_raises_exception(self):
"""
Test if a syntax error raises an exception
"""
from lesscpy.exceptions import CompilationError
def fail_func():
compile(StringIO("a }"), minify=True)
self.assertRaises(CompilationError, fail_func)
|