Ejemplo n.º 1
0
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")
Ejemplo n.º 2
0
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")
Ejemplo n.º 3
0
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>')
Ejemplo n.º 4
0
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>')
Ejemplo n.º 5
0
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>')
Ejemplo n.º 6
0
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>')
Ejemplo n.º 7
0
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>')
Ejemplo n.º 8
0
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>')
Ejemplo n.º 9
0
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/>')
Ejemplo n.º 10
0
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>')
Ejemplo n.º 11
0
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/>')
Ejemplo n.º 12
0
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/>')
Ejemplo n.º 13
0
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/>')
Ejemplo n.º 14
0
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>')
Ejemplo n.º 15
0
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>')
Ejemplo n.º 16
0
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>')
Ejemplo n.º 17
0
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/>')
Ejemplo n.º 18
0
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/>')
Ejemplo n.º 19
0
def test_write_accepts_empty_lists():
    """
    Checks that the generic `write` method accepts empty lists.
    """
    result = Writer.write([], root='list')
    assert_equals(result, '<list/>')
Ejemplo n.º 20
0
def test_write_accepts_empty_lists():
    """
    Checks that the generic `write` method accepts empty lists.
    """
    result = Writer.write([], root='list')
    assert_equals(result, '<list/>')