diff options
-rw-r--r-- | markdown/odict.py | 6 | ||||
-rw-r--r-- | tests/test_apis.py | 8 |
2 files changed, 11 insertions, 3 deletions
diff --git a/markdown/odict.py b/markdown/odict.py index bf3ef07..36d5553 100644 --- a/markdown/odict.py +++ b/markdown/odict.py @@ -150,13 +150,13 @@ class OrderedDict(dict): """ Change location of an existing item. """ n = self.keyOrder.index(key) del self.keyOrder[n] - i = self.index_for_location(location) try: + i = self.index_for_location(location) if i is not None: self.keyOrder.insert(i, key) else: self.keyOrder.append(key) - except Error: + except Exception as e: # restore to prevent data loss and reraise self.keyOrder.insert(n, key) - raise Error + raise e diff --git a/tests/test_apis.py b/tests/test_apis.py index 218c009..0296f27 100644 --- a/tests/test_apis.py +++ b/tests/test_apis.py @@ -214,6 +214,14 @@ class TestOrderedDict(unittest.TestCase): [('first', 'This'), ('fourth', 'self'), ('third', 'a'), ('fifth', 'test')]) + def textBadLink(self): + """ Test OrderedDict change order with bad location. """ + self.assertRaises(ValueError, self.odict.link('fourth', '<bad')) + # Check for data integrity ("fourth" wasn't deleted).' + self.assertEqual(self.odict.items(), + [('first', 'This'), ('third', 'a'), + ('fourth', 'self'), ('fifth', 'test')]) + class TestErrors(unittest.TestCase): """ Test Error Reporting. """ |