예제 #1
0
def test_range_build():
    xml_range = Range("test", 2, 4, Int("testint"))
    obj = [1, 2, 3]
    assert xml_range.build(
        obj
    ) == r"<test><testint>1</testint><testint>2</testint><testint>3</testint></test>"
예제 #2
0
def test_range_build_zero():
    xml_range = Range("test", 0, 2, Int("testint"))
    obj = []
    assert xml_range.build(obj) in (r"<test></test>", "<test />")
예제 #3
0
def test_range_parse_zero():
    xml_range = Range("test", 0, 2, Int("testint"))
    obj = []
    assert xml_range.parse(r"<test></test>") == obj
    assert xml_range.parse("<test />") == obj
예제 #4
0
def test_range_parse_more():
    xml_range = Range("test", 0, 2, Int("testint"))
    with pytest.raises(RangeError):
        xml_range.parse(
            r"<test><testint>1</testint><testint>2</testint><testint>3</testint></test>"
        )
예제 #5
0
def test_range_build_more():
    xml_range = Range("test", 0, 2, Int("testint"))
    obj = [1, 2, 3]
    with pytest.raises(RangeError):
        xml_range.build(obj)
예제 #6
0
def test_range_parse_less():
    xml_range = Range("test", 2, 4, Int("testint"))
    with pytest.raises(RangeError):
        xml_range.parse(r"<test><testint>1</testint></test>")
예제 #7
0
def test_range_build_less():
    xml_range = Range("test", 2, 4, Int("testint"))
    obj = [1]
    with pytest.raises(RangeError):
        xml_range.build(obj)
예제 #8
0
def test_range_parse():
    xml_range = Range("test", 2, 4, Int("testint"))
    obj = [1, 2, 3]
    assert xml_range.parse(
        r"<test><testint>1</testint><testint>2</testint><testint>3</testint></test>"
    ) == obj