aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2012-03-19 10:18:21 -0400
committerWaylan Limberg <waylan@gmail.com>2012-03-19 10:18:21 -0400
commit4dd11abae221fdd76d863487fac16ee45b05c96b (patch)
tree9571e6cd49f689492b500a34360ba02ec707ad75
parentf842c9aaabd1815a5a045b0575ef73e7d02c3136 (diff)
downloadmarkdown-4dd11abae221fdd76d863487fac16ee45b05c96b.tar.gz
markdown-4dd11abae221fdd76d863487fac16ee45b05c96b.tar.bz2
markdown-4dd11abae221fdd76d863487fac16ee45b05c96b.zip
Fixed #85. Odict now handles link errors correctly.
Also added a test. Thanks for the report.
-rw-r--r--markdown/odict.py6
-rw-r--r--tests/test_apis.py8
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. """