def test_applystylesheets1():
	with xsc.build():
		with html.html() as e:
			with html.head():
				+html.style("p {color: red;}", type="text/css")
			with html.body():
				+html.p("gurk")

	css.applystylesheets(e)

	assert str(e.walknodes(html.p)[0].attrs.style) == "color: red;"
	assert list(e.walknodes(html.style)) == []
def test_applystylesheets1():
    with xsc.build():
        with html.html() as e:
            with html.head():
                +html.style("p {color: red;}", type="text/css")
            with html.body():
                +html.p("gurk")

    css.applystylesheets(e)

    assert str(e.walknodes(html.p)[0].attrs.style) == "color: red;"
    assert list(e.walknodes(html.style)) == []
def test_applystylesheets5():
	with xsc.build():
		with html.html() as e:
			with html.head():
				+html.style("p#id42 {color: red;}", type="text/css")
			with html.body():
				+html.p("gurk", id="id42", style="color: blue;")

	css.applystylesheets(e)

	# stylesheet always wins (at least in CSS 2.1 and 3)
	assert str(e.walknodes(html.p)[0].attrs.style) == "color: blue;"
	assert list(e.walknodes(html.style)) == []
def test_applystylesheets4():
	with xsc.build():
		with html.html() as e:
			with html.head():
				+html.style("#id42 {color: red;}", type="text/css")
			with html.body():
				+html.p("gurk", id="id42", style="color: blue;")

	css.applystylesheets(e)

	# style attribute wins
	assert str(e.walknodes(html.p)[0].attrs.style) == "color: blue;"
	assert list(e.walknodes(html.style)) == []
def test_applystylesheets5():
    with xsc.build():
        with html.html() as e:
            with html.head():
                +html.style("p#id42 {color: red;}", type="text/css")
            with html.body():
                +html.p("gurk", id="id42", style="color: blue;")

    css.applystylesheets(e)

    # stylesheet always wins (at least in CSS 2.1 and 3)
    assert str(e.walknodes(html.p)[0].attrs.style) == "color: blue;"
    assert list(e.walknodes(html.style)) == []
def test_applystylesheets4():
    with xsc.build():
        with html.html() as e:
            with html.head():
                +html.style("#id42 {color: red;}", type="text/css")
            with html.body():
                +html.p("gurk", id="id42", style="color: blue;")

    css.applystylesheets(e)

    # style attribute wins
    assert str(e.walknodes(html.p)[0].attrs.style) == "color: blue;"
    assert list(e.walknodes(html.style)) == []
def test_applystylesheets_title():
	def makenode():
		with xsc.build():
			with html.html() as e:
				with html.head():
					+html.style("p {color: red;}", type="text/css")
					+html.style("p {color: blue;}", type="text/css", title="blue")
				with html.body():
					+html.p("gurk")
		return e

	# Check that title=None uses only the titleless stylesheets
	e = makenode()
	css.applystylesheets(e, title=None)
	assert str(e.walknodes(html.p)[0].attrs.style) == "color: red;"

	# Check that title="blue" uses only the stylesheet with the specified title
	e = makenode()
	css.applystylesheets(e, title="blue")
	assert str(e.walknodes(html.p)[0].attrs.style) == "color: blue;"
def test_applystylesheets_title():
    def makenode():
        with xsc.build():
            with html.html() as e:
                with html.head():
                    +html.style("p {color: red;}", type="text/css")
                    +html.style(
                        "p {color: blue;}", type="text/css", title="blue")
                with html.body():
                    +html.p("gurk")
        return e

    # Check that title=None uses only the titleless stylesheets
    e = makenode()
    css.applystylesheets(e, title=None)
    assert str(e.walknodes(html.p)[0].attrs.style) == "color: red;"

    # Check that title="blue" uses only the stylesheet with the specified title
    e = makenode()
    css.applystylesheets(e, title="blue")
    assert str(e.walknodes(html.p)[0].attrs.style) == "color: blue;"
def test_applystylesheets_media():
    # Check that media="screen" picks up the media stylesheet
    with xsc.build():
        with html.html() as e:
            with html.head():
                +html.style("p {color: red;}", type="text/css", media="screen")
            with html.body():
                +html.p("gurk")

    css.applystylesheets(e, media="screen")

    assert str(e.walknodes(html.p)[0].attrs.style) == "color: red;"

    # Check that media="screen" doesn't pick up the print stylesheet
    with xsc.build():
        with html.html() as e:
            with html.head():
                +html.style("p {color: red;}", type="text/css", media="screen")
            with html.body():
                +html.p("gurk")

    css.applystylesheets(e, media="print")

    assert str(e.walknodes(html.p)[0].attrs.style) == ""

    # Check that @media rules are treated properly
    with xsc.build():
        with html.html() as e:
            with html.head():
                +html.style("@media screen { p {color: red;}}",
                            type="text/css")
            with html.body():
                +html.p("gurk")

    css.applystylesheets(e, media="screen")

    assert str(e.walknodes(html.p)[0].attrs.style) == "color: red;"

    with xsc.build():
        with html.html() as e:
            with html.head():
                +html.style("@media screen { p {color: red;}}",
                            type="text/css")
            with html.body():
                +html.p("gurk")

    css.applystylesheets(e, media="print")

    assert str(e.walknodes(html.p)[0].attrs.style) == ""
def test_applystylesheets_media():
	# Check that media="screen" picks up the media stylesheet
	with xsc.build():
		with html.html() as e:
			with html.head():
				+html.style("p {color: red;}", type="text/css", media="screen")
			with html.body():
				+html.p("gurk")

	css.applystylesheets(e, media="screen")

	assert str(e.walknodes(html.p)[0].attrs.style) == "color: red;"

	# Check that media="screen" doesn't pick up the print stylesheet
	with xsc.build():
		with html.html() as e:
			with html.head():
				+html.style("p {color: red;}", type="text/css", media="screen")
			with html.body():
				+html.p("gurk")

	css.applystylesheets(e, media="print")

	assert str(e.walknodes(html.p)[0].attrs.style) == ""

	# Check that @media rules are treated properly
	with xsc.build():
		with html.html() as e:
			with html.head():
				+html.style("@media screen { p {color: red;}}", type="text/css")
			with html.body():
				+html.p("gurk")

	css.applystylesheets(e, media="screen")

	assert str(e.walknodes(html.p)[0].attrs.style) == "color: red;"

	with xsc.build():
		with html.html() as e:
			with html.head():
				+html.style("@media screen { p {color: red;}}", type="text/css")
			with html.body():
				+html.p("gurk")

	css.applystylesheets(e, media="print")

	assert str(e.walknodes(html.p)[0].attrs.style) == ""
def test_comments():
	d = b'<html><head><style type="text/css">/*nix*/ p{/*nix*/ color: red;}</style></head><body><p>gurk</p></body></html>'
	node = parse.tree(d, parse.Expat(), parse.NS(html), parse.Node())
	css.applystylesheets(node)
	assert str(node.walknodes(html.p)[0].attrs.style) == "color: red;"
def test_comments():
    d = b'<html><head><style type="text/css">/*nix*/ p{/*nix*/ color: red;}</style></head><body><p>gurk</p></body></html>'
    node = parse.tree(d, parse.Expat(), parse.NS(html), parse.Node())
    css.applystylesheets(node)
    assert str(node.walknodes(html.p)[0].attrs.style) == "color: red;"