aboutsummaryrefslogtreecommitdiffstats
path: root/test/mitmproxy/contentviews/test_css.py
blob: 814f6e83f754e9be06a7c1a000cf0a1458a611ce (plain)
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
import pytest

from mitmproxy.contentviews import css
from mitmproxy.test import tutils
from . import full_eval

data = tutils.test_data.push("mitmproxy/contentviews/test_css_data/")


@pytest.mark.parametrize("filename", [
    "animation-keyframe.css",
    "blank-lines-and-spaces.css",
    "block-comment.css",
    "empty-rule.css",
    "import-directive.css",
    "indentation.css",
    "media-directive.css",
    "quoted-string.css",
    "selectors.css",
    "simple.css",
])
def test_beautify(filename):
    path = data.path(filename)
    with open(path) as f:
        input = f.read()
    with open("-formatted.".join(path.rsplit(".", 1))) as f:
        expected = f.read()
    formatted = css.beautify(input)
    assert formatted == expected


def test_simple():
    v = full_eval(css.ViewCSS())
    assert v(b"#foo{color:red}") == ('CSS', [
        [('text', '#foo {')],
        [('text', '    color: red')],
        [('text', '}')]
    ])
    assert v(b"") == ('CSS', [[('text', '')]])
    assert v(b"console.log('not really css')") == (
        'CSS', [[('text', "console.log('not really css')")]]
    )