コード例 #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")
コード例 #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")
コード例 #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>')
コード例 #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>')
コード例 #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>')
コード例 #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>')
コード例 #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>')
コード例 #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>')
コード例 #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/>')
コード例 #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>')
コード例 #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/>')
コード例 #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/>')
コード例 #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/>')
コード例 #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>')
コード例 #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>')
コード例 #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>')
コード例 #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/>')
コード例 #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/>')
コード例 #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/>')
コード例 #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/>')