Beispiel #1
0
def test_malformed_custom():
    with pytest.raises(ValueError):
        PageXml.parseCustomAttr("a {x1;}")
    with pytest.raises(ValueError):
        PageXml.parseCustomAttr("a x1;}")
    with pytest.raises(ValueError):
        PageXml.parseCustomAttr("a { x1;")
    with pytest.raises(ValueError):
        PageXml.parseCustomAttr("a { x1 }")

    #with pytest.raises(ValueError): PageXml.parseCustomAttr("a { x:1 }")  #should it fail?
    assert PageXml.parseCustomAttr("a { x:1  2}") == {'a': {'x': '1  2'}}

    #with pytest.raises(ValueError): PageXml.parseCustomAttr("a { x:1  2}")#should it fail? (or do we allow spaces in names or values?)
    assert PageXml.parseCustomAttr("  a b   {   x y : 1  2  }") == {
        'a b': {
            'x y': '1  2'
        }
    }
Beispiel #2
0
def test_custom():
    assert PageXml.parseCustomAttr("") == {}
    assert PageXml.parseCustomAttr(" ") == {}
    assert PageXml.parseCustomAttr("   ") == {}

    assert PageXml.parseCustomAttr("a {x:1;}") == {'a': {'x': '1'}}
    assert PageXml.parseCustomAttr(" a {x:1;}") == {'a': {'x': '1'}}
    assert PageXml.parseCustomAttr("a {x:1;} ") == {'a': {'x': '1'}}
    assert PageXml.parseCustomAttr(" a {x:1;} ") == {'a': {'x': '1'}}
    assert PageXml.parseCustomAttr("a {x:1 ;}") == {'a': {'x': '1'}}
    assert PageXml.parseCustomAttr("a {x:1 ; }") == {'a': {'x': '1'}}
    assert PageXml.parseCustomAttr("a { x:1 ; }") == {'a': {'x': '1'}}

    assert PageXml.parseCustomAttr("a{x:1;}") == {'a': {'x': '1'}}
    assert PageXml.parseCustomAttr("a{x:1 ;}") == {'a': {'x': '1'}}
    assert PageXml.parseCustomAttr("a{x:1 ; }") == {'a': {'x': '1'}}
    assert PageXml.parseCustomAttr("a{ x:1 ; }") == {'a': {'x': '1'}}

    assert PageXml.parseCustomAttr("a,b{x:1;}") == {
        'a': {
            'x': '1'
        },
        'b': {
            'x': '1'
        }
    }
    assert PageXml.parseCustomAttr("a, b{x:1 ;}") == {
        'a': {
            'x': '1'
        },
        'b': {
            'x': '1'
        }
    }
    assert PageXml.parseCustomAttr("a , b{x:1 ; }") == {
        'a': {
            'x': '1'
        },
        'b': {
            'x': '1'
        }
    }
    assert PageXml.parseCustomAttr("a ,b{ x:1 ; }") == {
        'a': {
            'x': '1'
        },
        'b': {
            'x': '1'
        }
    }
    assert PageXml.parseCustomAttr("a ,b { x:1 ; }") == {
        'a': {
            'x': '1'
        },
        'b': {
            'x': '1'
        }
    }

    assert PageXml.parseCustomAttr("a { x:1 ; y:2 }") == {
        'a': {
            'x': '1',
            'y': '2'
        }
    }
    assert PageXml.parseCustomAttr("a,b { x:1 ; y:2 }") == {
        'a': {
            'x': '1',
            'y': '2'
        },
        'b': {
            'x': '1',
            'y': '2'
        }
    }

    assert PageXml.parseCustomAttr("a {}") == {'a': {}}

    assert PageXml.parseCustomAttr(
        "readingOrder {index:4;} structure {type:catch-word;}") == {
            'readingOrder': {
                'index': '4'
            },
            'structure': {
                'type': 'catch-word'
            }
        }