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_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.º 4
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.º 5
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.º 6
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.º 7
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.º 8
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.º 9
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.º 10
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.º 11
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.º 12
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.º 13
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.º 14
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/>')