# Path: pyipmi/errors.py
# class DecodingError(Exception):
#     """Error on message decoding."""
#     pass
# 
# class EncodingError(Exception):
#     """Error on message encoding."""
#     pass
# 
# Path: pyipmi/msgs/message.py
# class BaseField(object):
# class ByteArray(BaseField):
# class VariableByteArray(ByteArray):
# class UnsignedInt(BaseField):
# class String(BaseField):
# class CompletionCode(UnsignedInt):
# class UnsignedIntMask(UnsignedInt):
# class Timestamp(UnsignedInt):
# class Conditional(object):
# class Optional(object):
# class RemainingBytes(BaseField):
# class Bitfield(BaseField):
#     class Bit(object):
#     class ReservedBit(Bit):
#     class BitWrapper(object):
# class GroupExtensionIdentifier(UnsignedInt):
# class Message(object):
#     def __init__(self, name, length, default=None):
#     def decode(self, obj, data):
#     def encode(self, obj, data):
#     def create(self):
#     def __init__(self, name, length, default=None):
#     def _length(self, obj):
#     def encode(self, obj, data):
#     def decode(self, obj, data):
#     def create(self):
#     def __init__(self, name, length_func):
#     def _length(self, obj):
#     def create(self):
#     def encode(self, obj, data):
#     def decode(self, obj, data):
#     def create(self):
#     def encode(self, obj, data):
#     def decode(self, obj, data):
#     def create(self):
#     def __init__(self, name='completion_code'):
#     def decode(self, obj, data):
#     def __init__(self, name, length, mask, default=None):
#     def __init__(self, name):
#     def __init__(self, cond_fn, field):
#     def __getattr__(self, name):
#     def encode(self, obj, data):
#     def decode(self, obj, data):
#     def create(self):
#     def __init__(self, field):
#     def __getattr__(self, name):
#     def decode(self, obj, data):
#     def encode(self, obj, data):
#     def create(self):
#     def __init__(self, name):
#     def encode(self, obj, data):
#     def decode(self, obj, data):
#     def create(self):
#         def __init__(self, name, width=1, default=None):
#         def __init__(self, width, default=0):
#         def __init__(self, bits, length):
#         def __str__(self):
#         def __int__(self):
#         def _get_value(self):
#         def _set_value(self, value):
#     def __init__(self, name, length, *bits):
#     def _precalc_offsets(self):
#     def encode(self, obj, data):
#     def decode(self, obj, data):
#     def create(self):
#     def __init__(self, name='picmg_identifier', value=None):
#     def __init__(self, *args, **kwargs):
#     def _set_field(self, name, value):
#     def __str__(self):
#     def _create_fields(self):
#     def _pack(self):
#     def _encode(self):
#     def _decode(self, data):
#     def _is_request(self):
#     def _is_response(self):
#     RESERVED_FIELD_NAMES = ['cmdid', 'netfn', 'lun', 'group_extension']


from array import array
from nose.tools import eq_, raises
from pyipmi.errors import DecodingError, EncodingError
from pyipmi.msgs import encode_message, decode_message
import pyipmi.msgs.fru
    m = pyipmi.msgs.fru.WriteFruDataReq()
    decode_message(m, b'\x01\x02\x03')
    eq_(m.fru_id, 1)
    eq_(m.offset, 0x302)
    eq_(m.data, array('B'))


def test_writefrudatareq_encode_valid_req_wo_data():
    m = pyipmi.msgs.fru.WriteFruDataReq()
    m.fru_id = 1
    m.offset = 0x302
    m.data = array('B')
    data = encode_message(m)
    eq_(data, b'\x01\x02\x03')


@raises(DecodingError)
def test_writefrudatareq_decode_invalid_req():
    m = pyipmi.msgs.fru.WriteFruDataReq()
    decode_message(m, b'\x01\x02')


def test_readfrudatareq_decode_valid_req():
    m = pyipmi.msgs.fru.ReadFruDataReq()
    decode_message(m, b'\x01\x02\x03\x04')
    eq_(m.fru_id, 1)
    eq_(m.offset, 0x302)
    eq_(m.count, 4)



# Path: pyipmi/errors.py
# class DecodingError(Exception):
#     """Error on message decoding."""
#     pass
# 
# class EncodingError(Exception):
#     """Error on message encoding."""
#     pass
# 
# Path: pyipmi/msgs/message.py
# class BaseField(object):
# class ByteArray(BaseField):
# class VariableByteArray(ByteArray):
# class UnsignedInt(BaseField):
# class String(BaseField):
# class CompletionCode(UnsignedInt):
# class UnsignedIntMask(UnsignedInt):
# class Timestamp(UnsignedInt):
# class Conditional(object):
# class Optional(object):
# class RemainingBytes(BaseField):
# class Bitfield(BaseField):
#     class Bit(object):
#     class ReservedBit(Bit):
#     class BitWrapper(object):
# class GroupExtensionIdentifier(UnsignedInt):
# class Message(object):
#     def __init__(self, name, length, default=None):
#     def decode(self, obj, data):
#     def encode(self, obj, data):
#     def create(self):
#     def __init__(self, name, length, default=None):
#     def _length(self, obj):
#     def encode(self, obj, data):
#     def decode(self, obj, data):
#     def create(self):
#     def __init__(self, name, length_func):
#     def _length(self, obj):
#     def create(self):
#     def encode(self, obj, data):
#     def decode(self, obj, data):
#     def create(self):
#     def encode(self, obj, data):
#     def decode(self, obj, data):
#     def create(self):
#     def __init__(self, name='completion_code'):
#     def decode(self, obj, data):
#     def __init__(self, name, length, mask, default=None):
#     def __init__(self, name):
#     def __init__(self, cond_fn, field):
#     def __getattr__(self, name):
#     def encode(self, obj, data):
#     def decode(self, obj, data):
#     def create(self):
#     def __init__(self, field):
#     def __getattr__(self, name):
#     def decode(self, obj, data):
#     def encode(self, obj, data):
#     def create(self):
#     def __init__(self, name):
#     def encode(self, obj, data):
#     def decode(self, obj, data):
#     def create(self):
#         def __init__(self, name, width=1, default=None):
#         def __init__(self, width, default=0):
#         def __init__(self, bits, length):
#         def __str__(self):
#         def __int__(self):
#         def _get_value(self):
#         def _set_value(self, value):
#     def __init__(self, name, length, *bits):
#     def _precalc_offsets(self):
#     def encode(self, obj, data):
#     def decode(self, obj, data):
#     def create(self):
#     def __init__(self, name='picmg_identifier', value=None):
#     def __init__(self, *args, **kwargs):
#     def _set_field(self, name, value):
#     def __str__(self):
#     def _create_fields(self):
#     def _pack(self):
#     def _encode(self):
#     def _decode(self, data):
#     def _is_request(self):
#     def _is_response(self):
#     RESERVED_FIELD_NAMES = ['cmdid', 'netfn', 'lun', 'group_extension']


# Path: tests/msgs/test_fru.py
from array import array
from nose.tools import eq_, raises
from pyipmi.errors import DecodingError, EncodingError
from pyipmi.msgs import encode_message, decode_message
import pyipmi.msgs.fru

    m = pyipmi.msgs.fru.WriteFruDataReq()
    decode_message(m, b'\x01\x02\x03')
    eq_(m.fru_id, 1)
    eq_(m.offset, 0x302)
    eq_(m.data, array('B'))


def test_writefrudatareq_encode_valid_req_wo_data():
    m = pyipmi.msgs.fru.WriteFruDataReq()
    m.fru_id = 1
    m.offset = 0x302
    m.data = array('B')
    data = encode_message(m)
    eq_(data, b'\x01\x02\x03')


@raises(DecodingError)
def test_writefrudatareq_decode_invalid_req():
    m = pyipmi.msgs.fru.WriteFruDataReq()
    decode_message(m, b'\x01\x02')


def test_readfrudatareq_decode_valid_req():
    m = pyipmi.msgs.fru.ReadFruDataReq()
    decode_message(m, b'\x01\x02\x03\x04')
    eq_(m.fru_id, 1)
    eq_(m.offset, 0x302)
    eq_(m.count, 4)



@raises(DecodingError)