Ejemplo n.º 1
0
def test_doc_5():
    res1 = unpack("isf", "100 'She''s the best' 125.6", quote="'")
    res2 = unpack("isf", '3 "A ""quote"" test"  93.4 ignored', quote='"')
    assert len(res1) == 3
    assert res1[0] == 100
    assert res1[1] == "She's the best"
    assert res1[2] == pytest.approx(125.6)
    assert len(res2) == 3
    assert res2[0] == 3
    assert res2[1] == 'A "quote" test'
    assert res2[2] == pytest.approx(93.4)
Ejemplo n.º 2
0
def test_fun_15():
    s = "*ole*  'donald duck'  * doffen"
    res = unpack('sss', s, sep="*", quote="'")
    assert len(res) == 3
    assert res[0] == ''
    assert res[1] == 'ole'
    assert res[2] == "  'donald duck'  "
Ejemplo n.º 3
0
def test_fun_14():
    s = "*ole*donald duck*doffen"
    res = unpack('sss', s, sep="*")
    assert len(res) == 3
    assert res[0] == ''
    assert res[1] == 'ole'
    assert res[2] == 'donald duck'
Ejemplo n.º 4
0
def test_fun_10():
    s = '25  "She\'s the best" -34.5'
    res = unpack('isf', s, quote='"')
    assert len(res) == 3
    assert res[0] == 25
    assert res[1] == "She's the best"
    assert -34.5 == pytest.approx(res[2])
Ejemplo n.º 5
0
def test_fun_21():
    s = '2.3 "" " " 12'
    res = unpack("fssi", s, quote='"', none=True)
    assert len(res) == 4
    assert 2.3 == pytest.approx(res[0])
    assert res[1] is None
    assert res[2] == " "
    assert res[3] == 12
Ejemplo n.º 6
0
def test_fun_28():
    s = '3 "A ""quote"" test" 93.4 knut ignored'
    res = unpack('isfs', s, sep=' ', quote='"', quote_escape='""')
    assert len(res) == 4
    assert res[0] == 3
    assert res[1] == 'A "quote" test'
    assert res[2] == pytest.approx(93.4)
    assert res[3] == 'knut'
Ejemplo n.º 7
0
def test_fun_19():
    s = '3,4.5,yes,  ole,dole,5,doffen'
    res = unpack('.f?s..s', s, sep=',')
    assert len(res) == 4
    assert 4.5 == pytest.approx(res[0])
    assert res[1] is True
    assert res[2] == "  ole"
    assert res[3] == "doffen"
Ejemplo n.º 8
0
def test_fun_24():
    s = r'5 2 4.5     "ole is great \" but stupid!"    6'
    res = unpack('i.fsi', s, sep=None, quote='"', quote_escape=r'\"')
    assert len(res) == 4
    assert res[0] == 5
    assert res[1] == pytest.approx(4.5)
    assert res[2] == 'ole is great " but stupid!'
    assert res[3] == 6
Ejemplo n.º 9
0
def test_fun_25():
    s = r'5 <> 2 <> 4.5 <>"ole is great """" <> but stupid!"<>    6'
    res = unpack('i.fsi', s, sep='<>', quote='"', quote_escape='""')
    assert len(res) == 4
    assert res[0] == 5
    assert res[1] == pytest.approx(4.5)
    assert res[2] == 'ole is great "" <> but stupid!'
    assert res[3] == 6
Ejemplo n.º 10
0
def test_fun_13():
    s = "3 'A ''quote'' test' 93.4 knut ignored"
    res = unpack('isfs', s, sep=' ', quote="'", quote_escape="''")
    assert len(res) == 4
    assert res[0] == 3
    assert res[1] == "A 'quote' test"
    assert 93.4 == pytest.approx(res[2])
    assert res[3] == 'knut'
Ejemplo n.º 11
0
def test_fun_17():
    s = " ole,,,peter"
    res = unpack('ssss', s, sep=",")
    assert len(res) == 4
    assert res[0] == ' ole'
    assert res[1] == ''
    assert res[2] == ''
    assert res[3] == 'peter'
Ejemplo n.º 12
0
def test_fun_22():
    s = '1999,Chevy,"Venture ""Extended Edition, Very Large""","",5000.00'
    res = unpack('isssf', s, sep=',', quote='"', quote_escape='""')
    assert len(res) == 5
    assert res[0] == 1999
    assert res[1] == "Chevy"
    assert res[2] == 'Venture "Extended Edition, Very Large"'
    assert res[3] == ""
    assert res[4] == pytest.approx(5000.0)
Ejemplo n.º 13
0
def test_fun_20():
    s = ',, ,,'
    res = unpack('sssss', s, sep=',', none=True)
    assert len(res) == 5
    assert res[0] is None
    assert res[1] is None
    assert res[2] == " "
    assert res[3] is None
    assert res[4] is None
Ejemplo n.º 14
0
def test_doc_6():
    res = unpack("isf",
                 r"100 'She\'s the best' 125.6",
                 quote="'",
                 quote_escape=r"\'")
    assert len(res) == 3
    assert res[0] == 100
    assert res[1] == "She's the best"
    assert res[2] == pytest.approx(125.6)
Ejemplo n.º 15
0
def test_doc_1():
    line = "2.3 ole True 55  12"
    res = unpack("fs?ii", line)
    assert len(res) == 5
    assert res[0] == pytest.approx(2.3)
    assert res[1] == "ole"
    assert res[2] is True
    assert res[3] == 55
    assert res[4] == 12
Ejemplo n.º 16
0
def test_fun_26():
    s = r',,5,try,'
    res = unpack('ssiss', s, sep=',')
    assert len(res) == 5
    assert res[0] == ''
    assert res[1] == ''
    assert res[2] == 5
    assert res[3] == 'try'
    assert res[4] == ''
Ejemplo n.º 17
0
def test_fun_23():
    s = '1997,Ford,E350,"ac, abs, moon",3000.00'
    res = unpack('isssf', s, sep=',', quote='"', quote_escape='""')
    assert len(res) == 5
    assert res[0] == 1997
    assert res[1] == "Ford"
    assert res[2] == "E350"
    assert res[3] == "ac, abs, moon"
    assert res[4] == pytest.approx(3000.0)
Ejemplo n.º 18
0
def test_fun_27():
    s = r',,5,try,"",'
    res = unpack('ssisss', s, quote='"', sep=',')
    assert len(res) == 6
    assert res[0] == ''
    assert res[1] == ''
    assert res[2] == 5
    assert res[3] == 'try'
    assert res[4] == ''
    assert res[5] == ''
Ejemplo n.º 19
0
def test_fun_9():
    s = '3 4.5  ole  no   dole -5 doffen'
    res = unpack('ifs?sis', s)
    assert len(res) == 7
    assert res[0] == 3
    assert 4.5 == pytest.approx(res[1])
    assert res[2] == "ole"
    assert res[3] is False
    assert res[4] == "dole"
    assert res[5] == -5
    assert res[6] == "doffen"
Ejemplo n.º 20
0
def test_doc_3():
    res = unpack("f???s.????", "2.3 NO 0 F ole dole yes 1 ON TruE")
    assert len(res) == 9
    assert res[0] == pytest.approx(2.3)
    assert res[1] is False
    assert res[2] is False
    assert res[3] is False
    assert res[4] == 'ole'
    assert res[5] is True
    assert res[6] is True
    assert res[7] is True
    assert res[8] is True
Ejemplo n.º 21
0
def test_fun_8():
    s = 'Positive: y Yes t True On 1    Negative: N no F false   Off 0'
    res = unpack('.??????.??????', s)
    assert len(res) == 12
    assert res[0] is True
    assert res[1] is True
    assert res[2] is True
    assert res[3] is True
    assert res[4] is True
    assert res[5] is True
    assert res[6] is False
    assert res[7] is False
    assert res[8] is False
    assert res[9] is False
    assert res[10] is False
    assert res[11] is False
Ejemplo n.º 22
0
def test_fun_11():
    s = '3,4.5,  ole,dole,5,doffen'
    res = unpack('.fs', s, sep=',')
    assert len(res) == 2
    assert 4.5 == pytest.approx(res[0])
    assert res[1] == "  ole"
Ejemplo n.º 23
0
def test_exception_15():
    with pytest.raises(ValueError):
        s = '2.3 """ " 12'
        # Sep is a white space. There should be space between the two strings
        res = unpack("fssi", s, quote='"', none=True)
Ejemplo n.º 24
0
def test_fun_2():
    s = ' -.3 '
    res = unpack('f', s)
    assert len(res) == 1
    assert -0.3 == pytest.approx(res[0])
Ejemplo n.º 25
0
def test_fun_1():
    s = '4'
    res = unpack('i', s)
    assert len(res) == 1
    assert res[0] == 4
Ejemplo n.º 26
0
def test_fun_7():
    s = '-3 and some trailing junk'
    res = unpack('i', s)
    assert len(res) == 1
    assert res[0] == -3
Ejemplo n.º 27
0
def test_fun_6():
    s = "'ole'"
    res = unpack('s', s, quote="'")
    assert len(res) == 1
    assert res[0] == 'ole'
Ejemplo n.º 28
0
def test_fun_5():
    s = '"ole"'
    res = unpack('s', s, quote='"')
    assert len(res) == 1
    assert res[0] == 'ole'
Ejemplo n.º 29
0
def test_fun_3():
    s = ' ole  '
    res = unpack('s', s)
    assert len(res) == 1
    assert res[0] == 'ole'
Ejemplo n.º 30
0
def test_fun_4():
    s = '"ole"'
    res = unpack('s', s)
    assert len(res) == 1
    assert res[0] == '"ole"'