Exemple #1
0
def test_var_operations():
    foo = Var("foo")
    bar = Var("bar")

    assert foo == "foo"
    assert -foo == "-foo"
    assert --foo == "--foo"
    assert ~foo == "not foo"

    assert foo - bar == "foo-bar"
    assert foo + bar == "foo+bar"
    assert foo / bar == "foo/bar"
    assert foo & bar == "foo and bar"
    assert foo | bar == "foo or bar"

    assert bar - "baz" == "bar-baz"
    assert bar + "baz" == "bar+baz"
    assert bar / "baz" == "bar/baz"
    assert bar & "baz" == "bar and baz"
    assert bar | "baz" == "bar or baz"

    assert "baz" - bar == "baz-bar"
    assert "baz" + bar == "baz+bar"
    assert "baz" / bar == "baz/bar"
    assert "baz" & bar == "baz and bar"
    assert "baz" | bar == "baz or bar"
Exemple #2
0
def test_override():
    webkit, moz, ms, o, linear, gradient = Var.many(
        "webkit moz ms o linear gradient")
    css = {
        ".foo": {
            "background":
            override(
                -webkit - linear - gradient("left", "blue", "red", "blue"),
                -moz - linear - gradient("left", "blue", "red", "blue"),
                -ms - linear - gradient("left", "blue", "red", "blue"),
                -o - linear - gradient("left", "blue", "red", "blue"),
                linear - gradient("left", "blue", "red", "blue"),
            )
        }
    }

    assert (render_css(css, mode=Modes.NORMAL) == """\
.foo {
  background: -webkit-linear-gradient(left, blue, red, blue);
  background: -moz-linear-gradient(left, blue, red, blue);
  background: -ms-linear-gradient(left, blue, red, blue);
  background: -o-linear-gradient(left, blue, red, blue);
  background: linear-gradient(left, blue, red, blue);
}
""")
Exemple #3
0
def test_var_many():
    aa, bb = Var.many("aa bb")
    assert aa == "aa"
    assert isinstance(aa, Var)
    assert bb == "bb"
    assert isinstance(bb, Var)

    cc, dd = Var.many("cc", "dd")
    assert cc == "cc"
    assert isinstance(cc, Var)
    assert dd == "dd"
    assert isinstance(dd, Var)

    ee, ff = Unit.many("ee", "ff")
    assert ee == "ee"
    assert isinstance(ee, Unit)
    assert ff == "ff"
    assert isinstance(ff, Unit)
Exemple #4
0
def test12():
    # https://css-tricks.com/logic-in-media-queries/#article-header-id-8
    expected = ("@media "
                "only screen and (min-width: 100px), "
                "not all and (min-width: 100px), "
                "not print and (min-height: 100px), "
                "(color), "
                "(min-height: 100px) and (max-height: 1000px), "
                "handheld and (orientation: landscape)")

    only, screen, min, width, all, print, height, color, max, handheld, orientation, landscape = Var.many(
        "only screen min width all print height color max handheld orientation landscape"
    )
    px = Unit("px")

    m = media(
        only(screen) & {min - width: 100 * px},
        ~all & {min - width: 100 * px},
        ~print & {min - height: 100 * px},
        {color},
        _ & {min - height: 100 * px} & {max - height: 1000 * px},
        handheld & {orientation: landscape},
    )
    assert m == expected

    minw = 100 * px
    minh = 100 * px
    maxh = 1000 * px

    m = media(
        only(screen) & {min - width: minw},
        ~all & {min - width: minw},
        ~print & {min - height: minh},
        {color},
        _ & {min - height: minh} & {max - height: maxh},
        handheld & {orientation: landscape},
    )
    assert m == expected

    minw = {min - width: 100 * px}
    minh = {min - height: 100 * px}
    maxh = {max - height: 1000 * px}

    m = media(
        only(screen) & minw,
        ~all & minw,
        ~print & minh,
        {color},
        _ & minh & maxh,
        handheld & {orientation: landscape},
    )
    assert m == expected
Exemple #5
0
def test11():
    screen, print, color = Var.many("screen print color")
    assert (media(
        ~screen & {color},
        print & {color}) == "@media not screen and (color), print and (color)")
Exemple #6
0
def test9():
    all, max, width = Var.many("all max width")
    em = Unit("em")
    assert (media(~all & {max - width: 40 *
                          em}) == "@media not all and (max-width: 40em)")
Exemple #7
0
def test_7():
    screen = Var("screen")
    assert (media(screen & {"foo": "bar"} & {"baz": "qux"}) ==
            "@media screen and (foo: bar) and (baz: qux)")
Exemple #8
0
def test_empty_var():
    foo = Var("")
    bar = Var("bar")
    qux = Var("")

    assert foo == ""
    assert -foo == ""
    assert --foo == ""
    assert ~foo == "not "

    assert foo - bar == "-bar"
    assert foo + bar == "+bar"
    assert foo / bar == "/bar"
    assert foo & bar == "bar"
    assert foo | bar == "bar"

    assert bar - foo == "bar"
    assert bar + foo == "bar"
    assert bar / foo == "bar"
    assert bar & foo == "bar"
    assert bar | foo == "bar"

    assert foo - "baz" == "-baz"
    assert foo + "baz" == "+baz"
    assert foo / "baz" == "/baz"
    assert foo & "baz" == "baz"
    assert foo | "baz" == "baz"

    assert "baz" - foo == "baz"
    assert "baz" + foo == "baz"
    assert "baz" / foo == "baz"
    assert "baz" & foo == "baz"
    assert "baz" | foo == "baz"

    assert foo - qux == ""
    assert foo + qux == ""
    assert foo / qux == ""
    assert foo & qux == ""
    assert foo | qux == ""

    assert qux - foo == ""
    assert qux + foo == ""
    assert qux / foo == ""
    assert qux & foo == ""
    assert qux | foo == ""

    assert foo - "" == ""
    assert foo + "" == ""
    assert foo / "" == ""
    assert foo & "" == ""
    assert foo | "" == ""

    assert "" - foo == ""
    assert "" + foo == ""
    assert "" / foo == ""
    assert "" & foo == ""
    assert "" | foo == ""

    assert bar - "" == "bar"
    assert bar + "" == "bar"
    assert bar / "" == "bar"
    assert bar & "" == "bar"
    assert bar | "" == "bar"

    assert "" - bar == "-bar"
    assert "" + bar == "+bar"
    assert "" / bar == "/bar"
    assert "" & bar == "bar"
    assert "" | bar == "bar"
Exemple #9
0
def test_call_var():
    foo = Var("foo")
    obj = foo(1, 2, 3)
    assert obj == "foo(1, 2, 3)"
    assert isinstance(obj, Var)