def test_from_data_dict(self): """ Test from_data_dict. """ cdt = CompositeDataType([('one', EepromByte((1, 2))), ('two', EepromByte((1, 3)))]) addr1 = EepromAddress(1, 2, 1) addr2 = EepromAddress(1, 3, 1) data_dict = {addr1 : EepromData(addr1, str(chr(12))), addr2 : EepromData(addr2, str(chr(34)))} self.assertEquals([12, 34], cdt.from_data_dict(data_dict))
def test_to_eeprom_data(self): """ Test to_eeprom_data. """ cdt = CompositeDataType([('one', EepromByte((1, 2))), ('two', EepromByte((1, 3)))]) data = cdt.to_eeprom_data([34, 12]) self.assertEquals(2, len(data)) self.assertEquals(EepromAddress(1, 2, 1), data[0].address) self.assertEquals(str(chr(34)), data[0].bytes) self.assertEquals(EepromAddress(1, 3, 1), data[1].address) self.assertEquals(str(chr(12)), data[1].bytes)
def test_get_addresses(self): """ Test get_addresses. """ cdt = CompositeDataType([('one', EepromByte((1, 2))), ('two', EepromByte((1, 3)))]) addresses = cdt.get_addresses(None, 'cdt') self.assertEquals(2, len(addresses)) self.assertEquals(1, addresses['one'].bank) self.assertEquals(2, addresses['one'].offset) self.assertEquals(1, addresses['one'].length) self.assertEquals(1, addresses['two'].bank) self.assertEquals(3, addresses['two'].offset) self.assertEquals(1, addresses['two'].length)
def test_get_addresses_id(self): """ Test get_addresses with an id. """ cdt = CompositeDataType([('one', EepromByte(lambda id: (1, 10 + id))), ('two', EepromByte(lambda id: (1, 20 + id)))]) addresses = cdt.get_addresses(5, 'cdt') self.assertEquals(2, len(addresses)) self.assertEquals(1, addresses['one'].bank) self.assertEquals(15, addresses['one'].offset) self.assertEquals(1, addresses['one'].length) self.assertEquals(1, addresses['two'].bank) self.assertEquals(25, addresses['two'].offset) self.assertEquals(1, addresses['two'].length)
class Model8(EepromModel): """ Dummy model with multiple fields, including eext fields, without an id. """ name = EepromString(10, (1, 4)) link = EepromByte((1, 14)) room = EextByte()
class Model7(EepromModel): """ Dummy model with multiple fields, including eext fields and an id. """ id = EepromId(3) name = EepromString(10, lambda id: (id, 4)) link = EepromByte(lambda id: (id, 14)) room = EextByte()
class Model6(EepromModel): """ Dummy model with a CompositeDataType. """ name = EepromString(10, (3, 4)) status = CompositeDataType([('link', EepromByte((3, 14))), ('out', EepromWord((3, 15)))])
class Model5(EepromModel): """ Dummy model with multiple fields and an id. """ id = EepromId(3) name = EepromString(10, lambda id: (3 + id, 4)) link = EepromByte(lambda id: (3 + id, 14)) out = EepromWord(lambda id: (3 + id, 15))
class Model3(EepromModel): """ Dummy model with multiple fields. """ name = EepromString(10, (3, 4)) link = EepromByte((3, 14)) out = EepromWord((3, 15))
def test_get_name(self): """ Test get_name. """ cdt = CompositeDataType([('one', EepromByte((1, 2))), ('two', EepromByte((1, 3)))]) self.assertEquals("[one(Byte),two(Byte)]", cdt.get_name())
class RoModel(EepromModel): """ Dummy model. """ id = EepromId(10) name = EepromString(100, lambda id: (1, 2 + id)) other = EepromByte(lambda id: (2, 2 + id), read_only=True)
class TestModel(EepromModel): id = EepromId(102) normal_eeprom_field = EepromByte((0, 6)) int_field = EextByte() str_field = EextString()