def test_write_raises_exception_if_given_list_and_no_root(): """ Checks that the generic `write` method raises an exception if it is given a list and no root tag. """ with assert_raises(Error) as context: Writer.write([]) assert_regexp_matches(str(context.exception), "root.*mandatory")
def test_write_integer_1(): """ Checks that given the value `0` the `write_integer` method generates the expected XML text. """ io_buffer = make_buffer() xml_writer = XmlWriter(io_buffer) Writer.write_integer(xml_writer, 'value', 1) xml_writer.flush() assert_equals(decode_buffer(io_buffer), '<value>1</value>')
def test_write_boolean_false(): """ Checks that given the value `False` the `write_boolean` method generates the expected XML text. """ io_buffer = make_buffer() xml_writer = XmlWriter(io_buffer) Writer.write_boolean(xml_writer, 'value', False) xml_writer.flush() assert_equals(decode_buffer(io_buffer), '<value>false</value>')
def test_write_string(): """ Checks that given an name and a value the `write_string` method generates the expected XML text. """ io_buffer = make_buffer() xml_writer = XmlWriter(io_buffer) Writer.write_string(xml_writer, 'value', 'myvalue') xml_writer.flush() assert_equals(decode_buffer(io_buffer), '<value>myvalue</value>')
def test_write_uses_alternative_root_tag(): """ Checks that the generic `write` method uses the alternative root tag if provided. """ vm = types.Vm() result = Writer.write(vm, root='list') assert_equals(result, '<list/>')
def test_write_accepts_list_with_two_elements(): """ Checks that the generic `write` method accets lists with two elements. """ vm = types.Vm() result = Writer.write([vm, vm], root='list') assert_equals(result, '<list><vm/><vm/></list>')
def test_write_does_not_require_xml_writer(): """ Checks that the generic `write` method doesn't require an XML writer paramater. """ vm = types.Vm() result = Writer.write(vm) assert_equals(result, '<vm/>')
def test_write_accepts_elements_of_different_types(): """ Checks that the generic `write` method accets lists containing elements of different types. """ vm = types.Vm() disk = types.Disk() result = Writer.write([vm, disk], root='list') assert_equals(result, '<list><vm/><disk/></list>')
def test_write_accepts_xml_writer(): """ Checks that the generic `write` method accepts an XML writer as parameter. """ vm = types.Vm() writer = XmlWriter(None) result = Writer.write(vm, target=writer) text = writer.string() writer.close() assert_is_none(result) assert_equals(text, '<vm/>')
def test_write_accepts_empty_lists(): """ Checks that the generic `write` method accepts empty lists. """ result = Writer.write([], root='list') assert_equals(result, '<list/>')