Changeset 9126 for main/waeup.kofa/trunk


Ignore:
Timestamp:
30 Aug 2012, 08:11:58 (12 years ago)
Author:
Henrik Bettermann
Message:

Catch errors and return message removed.

Location:
main/waeup.kofa/trunk/src/waeup/kofa
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/objecthistory.py

    r9125 r9126  
    9898        """
    9999        msgs = self._getMessages()
     100        if not isinstance(number, int):
     101            return False, 'Not a number'
     102        try:
     103            line = msgs[number]
     104        except IndexError:
     105            return False, 'Number out of range'
    100106        msgs.pop(number)
    101107        self._annotations[self.history_key] = msgs
    102         return
     108        return True, line
  • main/waeup.kofa/trunk/src/waeup/kofa/tests/test_objecthistory.py

    r9125 r9126  
    108108        hist.addMessage('blah')
    109109        hist.addMessage('blow')
    110         self.assertEqual(len(hist._getMessages()),2)
     110        self.assertEqual(len(hist._getMessages()), 2)
    111111        result = ' '.join(hist.messages)
    112112        self.assertTrue('blah by Bob' in result)
    113113        self.assertTrue('blow by Bob' in result)
    114         hist.removeMessage(1)
    115         self.assertEqual(len(hist._getMessages()),1)
     114        success, text = hist.removeMessage('xyz')
     115        self.assertFalse(success)
     116        self.assertEqual(text, 'Not a number')
     117        success, text = hist.removeMessage(100)
     118        self.assertFalse(success)
     119        self.assertEqual(text, 'Number out of range')
     120        success, text = hist.removeMessage(1)
     121        self.assertTrue(success)
     122        self.assertMatches('<YYYY-MM-DD hh:mm:ss> UTC - blow by Bob', text)
     123        self.assertEqual(len(hist.messages), 1)
    116124        result = ' '.join(hist.messages)
    117125        self.assertFalse('blow by Bob' in result)
Note: See TracChangeset for help on using the changeset viewer.