File: test_partition.py

package info (click to toggle)
python-csscompressor 0.9.4-2~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 700 kB
  • sloc: python: 1,764; makefile: 36
file content (138 lines) | stat: -rw-r--r-- 3,576 bytes parent folder | download | duplicates (5)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
##
# Copyright (c) 2013 Sprymix Inc.
# All rights reserved.
#
# See LICENSE for details.
##


from csscompressor.tests.base import BaseTest
from csscompressor import compress_partitioned

import unittest


class Tests(unittest.TestCase):
    def test_partition_1(self):
        input = ''
        output = compress_partitioned(input, max_rules_per_file=2)
        assert output == ['']

    def test_partition_2(self):
        input = '''
            a {content: '}}'}
            b {content: '}'}
            c {content: '{'}
        '''

        output = compress_partitioned(input, max_rules_per_file=2)
        assert output == ["a{content:'}}'}b{content:'}'}", "c{content:'{'}"]

    def test_partition_3(self):
        input = '''
            @media{
                a {p: 1}
                b {p: 2}
                x {p: 2}
            }
            @media{
                c {p: 1}
                d {p: 2}
                y {p: 2}
            }
            @media{
                e {p: 1}
                f {p: 2}
                z {p: 2}
            }
        '''

        output = compress_partitioned(input, max_rules_per_file=2)
        assert output == ['@media{a{p:1}b{p:2}x{p:2}}',
                          '@media{c{p:1}d{p:2}y{p:2}}',
                          '@media{e{p:1}f{p:2}z{p:2}}']

    def test_partition_4(self):
        input = '''
            @media{
                a {p: 1}
                b {p: 2}
                x {p: 2}
        '''

        self.assertRaises(ValueError, compress_partitioned,
                          input, max_rules_per_file=2)

    def test_partition_5(self):
        input = '''
            @media{
                a {p: 1}
                b {p: 2}
                x {p: 2}

            @media{
                c {p: 1}
                d {p: 2}
                y {p: 2}
            }
            @media{
                e {p: 1}
                f {p: 2}
                z {p: 2}
            }
        '''

        self.assertRaises(ValueError, compress_partitioned,
                          input, max_rules_per_file=2)

    def test_partition_6(self):
        input = '''
            @media{}}

                a {p: 1}
                b {p: 2}
                x {p: 2}
        '''

        self.assertRaises(ValueError, compress_partitioned,
                          input, max_rules_per_file=2)

    def test_partition_7(self):
        input = '''
            a, a1, a2 {color: red}
            b, b2, b3 {color: red}
            c, c3, c4, c5 {color: red}
            d {color: red}
        '''

        output = compress_partitioned(input, max_rules_per_file=2)
        assert output == ['a,a1,a2{color:red}', 'b,b2,b3{color:red}',
                          'c,c3,c4,c5{color:red}', 'd{color:red}']

    def test_partition_8(self):
        input = '''
            @media{
                a {p: 1}
                b {p: 2}
                x {p: 2}
            }
            @media{
                c {p: 1}
                d {p: 2}
                y {p: 2}
            }
            @media{
                e {p: 1}
                f {p: 2}
                z {p: 2}
            }
            z {p: 2}
        '''

        # carefully pick 'max_linelen' to have a trailing '\n' after
        # '_compress' call
        output = compress_partitioned(input, max_rules_per_file=2, max_linelen=6)
        assert output == ['@media{a{p:1}\nb{p:2}x{p:2}\n}',
                          '@media{c{p:1}\nd{p:2}y{p:2}\n}',
                          '@media{e{p:1}\nf{p:2}z{p:2}\n}',
                          'z{p:2}']