File: test_pycompile.py

package info (click to toggle)
python-lesscpy 0.13.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,436 kB
  • sloc: python: 3,572; sh: 20; makefile: 8
file content (45 lines) | stat: -rw-r--r-- 1,139 bytes parent folder | download | duplicates (2)
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)