Exemple #1
0
def test_pformat_nostr():
    p = PFormat('int', 8)
    assert p.minmax == (-2**7, 2**7 - 1)
    assert p.bits == 8
    assert p.typ == 'int'
    assert p._halfmaxint == 2**7
    assert p._maxint == 2**8
Exemple #2
0
def test_pformat_uint():
    p = PFormat('uint', 8)
    assert p.minmax == (0, 2**8 - 1)
    assert p.is_valid(256) == False
    assert p.is_valid(255) == True
    assert p.is_valid(0) == True
    assert p.is_valid(-1) == False
    assert p._tohex(0) == Byt('\x00')
    assert p._tohex(241) == Byt('\xf1')
Exemple #3
0
def test_pformat_parse():
    p = PFormat('str')
    assert p._parse('zertzrt') is None
    assert p._parse('int') is None
    assert p._parse('float') is None
    assert p._parse('uint') is None
    assert p._parse('str') == ('str', 0)
    assert p._parse('int8') == ('int', 8)
    assert p._parse('<uint-16>') == ('uint', 16)
    assert p._parse('<float(32)>') == ('float', 32)
Exemple #4
0
def test_pformat_str():
    p = PFormat('str')
    assert p.minmax == (0, 255)
    assert p.bits == 0
    assert p.typ == 'str'
    assert p.is_valid(['a']) == False
    assert p.is_valid('ab') == False
    assert p.is_valid(32) == False
    assert p.is_valid('a') == True
    assert p.is_valid('\x01') == True
    assert p._tohex('a') == Byt('a')
    assert p._tohex('\x41') == Byt('A')
Exemple #5
0
def test_pformat_NotImplemented():
    p = PFormat('float', 8)
    p._tohex(12.0)
Exemple #6
0
def test_pformat_float():
    p = PFormat('float', 8)
    assert p.is_valid('e') == False
    assert p.is_valid(0) == False
    assert p.is_valid(0.0) == True
Exemple #7
0
def test_pformat_int():
    p = PFormat('int', 8)
    assert p.is_valid(128) == False
    assert p.is_valid(127) == True
    assert p.is_valid(-128) == True
    assert p.is_valid(-129) == False
Exemple #8
0
def test_pformat_WrongFormatBitLength4():
    p = PFormat('int', 65)
Exemple #9
0
def test_pformat_WrongFormatBitLength2():
    p = PFormat('int', 8.0)
Exemple #10
0
def test_pformat_UnknownFormat():
    p = PFormat('issdgnt')
Exemple #11
0
def test_pformat_MissingFormatInput():
    p = PFormat('int')