def loadFromFile(self, file): with open(file, 'rb') as f: while True: raw_size = f.read(4) if len(raw_size) < 4: break size = struct.unpack('I', raw_size)[0] buffer = f.read(size) account = Account('') account.fromBytes(buffer) self.__addAccount(account)
def test_marshalling(self): # Create an account and convert it to bytes in_name = 'Love that hard c**k!' account = Account('Visual') account.generateKeys() logging.debug('Before marshal %s', account) buffer = account.toBytes() # print('test_marshalling:',buffer.hex()) logging.debug('Marshalled buffer: %s', buffer.hex()) # Create a new account from the bytes new_account = Account('') new_account.fromBytes(buffer) logging.debug('Unmarshalled %s', account) # Check if they have the content self.assertTrue(new_account.equals(account)) # Different names should be okay, if all else is the same new_name = 'resurected!' new_account.setName(new_name) self.assertEqual(new_name, new_account.getName(),'Account name not set correctly!') self.assertTrue(new_account.equals(account), "Names should not affect Account equality!")