from svg import Document
from svg import text_color

def test_generate_xml():
    doc = Document()
    with doc.tag("svg", 'height="400" width="800"'):
        doc.tag("rect", 'y="20"')
        doc.tag("rect", 'y="30"')
        with doc.tag("g", 'x="20"'):
            with doc.tag("text"):
                doc.text("Hello")
        doc.tag("rect", 'y="40"')

    print(doc.out)

    assert doc.out == '''<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!--
    This file was generated by `beautiful-labels`. Don't edit it directly.
-->
<svg height="400" width="800" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  <rect y="20"/>
  <rect y="30"/>
  <g x="20">
    <text>
      Hello
    </text>
  </g>
  <rect y="40"/>
</svg>
'''

def test_text_color():
    assert text_color("000000") == "white"
    assert text_color("ffffff") == "black"
    assert text_color("f9eea7") == "black"
    assert text_color("5319e7") == "white"
