@pytest.mark.parametrize(['data_enc', 'len_enc', 'len_type', 'max_len', 'len_count', 'data', 'result_f2_len'], [('ascii', 'ascii', 2, 8, 'bytes', b'02004000000000000000041234', b'04'), ('ascii', 'ascii', 2, 8, 'nibbles', b'02004000000000000000081234', b'08'), ('ascii', 'b', 2, 8, 'bytes', b'02004000000000000000\x00\x041234', b'\x00\x04'), ('ascii', 'b', 2, 8, 'nibbles', b'02004000000000000000\x00\x081234', b'\x00\x08'), ('b', 'ascii', 2, 8, 'bytes', b'0200400000000000000002\x124', b'02'), ('b', 'ascii', 2, 8, 'nibbles', b'0200400000000000000004\x124', b'04'), ('b', 'b', 2, 8, 'bytes', b'02004000000000000000\x00\x02\x124', b'\x00\x02'), ('b', 'b', 2, 8, 'nibbles', b'02004000000000000000\x00\x04\x124', b'\x00\x04'), ('ascii', 'ascii', 0, 4, 'bytes', b'020040000000000000001234', b''), ('ascii', 'ascii', 0, 8, 'nibbles', b'020040000000000000001234', b''), ('b', 'ascii', 0, 2, 'bytes', b'02004000000000000000\x124', b''), ('b', 'ascii', 0, 4, 'nibbles', b'02004000000000000000\x124', b'')])
def test_decode_nibbles(data_enc: str, len_enc: str, len_type: int, max_len: int, len_count: str, data: bytes, result_f2_len: bytes) -> None:
    spec = copy.deepcopy(iso8583.specs.default)
    spec['t']['data_enc'] = 'ascii'
    spec['p']['data_enc'] = 'ascii'
    spec['2']['data_enc'] = data_enc
    spec['2']['len_enc'] = len_enc
    spec['2']['len_type'] = len_type
    spec['2']['max_len'] = max_len
    spec['2']['len_count'] = len_count
    (decoded, encoded) = iso8583.decode(data, spec)
    assert (decoded['2'] == '1234')
    assert (encoded['2']['len'] == result_f2_len)
@pytest.mark.parametrize(['data_enc', 'len_enc', 'len_type', 'max_len', 'len_count', 'data', 'result_f2_len'], [('ascii', 'ascii', 2, 8, 'bytes', b'02004000000000000000041234', b'04'), ('ascii', 'ascii', 2, 8, 'nibbles', b'02004000000000000000081234', b'08'), ('ascii', 'b', 2, 8, 'bytes', b'02004000000000000000\x00\x041234', b'\x00\x04'), ('ascii', 'b', 2, 8, 'nibbles', b'02004000000000000000\x00\x081234', b'\x00\x08'), ('b', 'ascii', 2, 8, 'bytes', b'0200400000000000000002\x124', b'02'), ('b', 'ascii', 2, 8, 'nibbles', b'0200400000000000000004\x124', b'04'), ('b', 'b', 2, 8, 'bytes', b'02004000000000000000\x00\x02\x124', b'\x00\x02'), ('b', 'b', 2, 8, 'nibbles', b'02004000000000000000\x00\x04\x124', b'\x00\x04'), ('ascii', 'ascii', 0, 4, 'bytes', b'020040000000000000001234', b), ('ascii', 'ascii', 0, 8, 'nibbles', b'020040000000000000001234', b), ('b', 'ascii', 0, 2, 'bytes', b'02004000000000000000\x124', b), ('b', 'ascii', 0, 4, 'nibbles', b'02004000000000000000\x124', b)])
def test_decode_nibbles(data_enc: str, len_enc: str, len_type: int, max_len: int, len_count: str, data: bytes, result_f2_len: bytes) -> None:
    spec = copy.deepcopy(iso8583.specs.default)
    spec['t']['data_enc'] = 'ascii'
    spec['p']['data_enc'] = 'ascii'
    spec['2']['data_enc'] = data_enc
    spec['2']['len_enc'] = len_enc
    spec['2']['len_type'] = len_type
    spec['2']['max_len'] = max_len
    spec['2']['len_count'] = len_count
    (decoded, encoded) = iso8583.decode(data, spec)
    assert (decoded['2'] == '1234')
    assert (encoded['2']['len'] == result_f2_len)