aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2008-10-28 18:25:54 -0400
committerWaylan Limberg <waylan@gmail.com>2008-10-28 18:25:54 -0400
commit83efb118c1bdcb7d44a1fa6b187eb33bf86f72dd (patch)
tree1cfad9c53141ce33b871092f504c3d428568d805
parenta7b2a0c6933b1c8667cd25a58a18e50be0367504 (diff)
downloadmarkdown-83efb118c1bdcb7d44a1fa6b187eb33bf86f72dd.tar.gz
markdown-83efb118c1bdcb7d44a1fa6b187eb33bf86f72dd.tar.bz2
markdown-83efb118c1bdcb7d44a1fa6b187eb33bf86f72dd.zip
Replaced Treap with OrderedDict. Updated regression_tests and extensions. All tests pass. Still needs documentation.
-rwxr-xr-xmarkdown.py356
-rw-r--r--markdown_extensions/tables.py2
-rwxr-xr-xregression-tests.py137
-rw-r--r--treap_test.py50
4 files changed, 269 insertions, 276 deletions
diff --git a/markdown.py b/markdown.py
index a8b4455..368886c 100755
--- a/markdown.py
+++ b/markdown.py
@@ -33,7 +33,7 @@ Limberg](http://achinghead.com/) and [Artem Yunusov](http://blog.splyer.com).
Contact: markdown@freewisdom.org
Copyright 2007, 2008 The Python Markdown Project (v. 1.7 and later)
-Copyright 2007 Benjamin C. Wilson (Treap implementation)
+Copyright 200? Django Software Foundation (OrderedDict implementation)
Copyright 2004, 2005, 2006 Yuri Takhteyev (v. 0.2-1.6b)
Copyright 2004 Manfred Stienstra (the original version)
@@ -1586,149 +1586,169 @@ class HtmlStash:
self.html_counter = 0
self.rawHtmlBlocks = []
+class OrderedDict(dict):
+ """
+ A dictionary that keeps its keys in the order in which they're inserted.
+
+ Copied from Django's SortedDict with some modifications.
-from operator import itemgetter
-
-class Treap(dict):
- """Extends dict to allow assignment of priority.
+ """
+ def __new__(cls, *args, **kwargs):
+ instance = super(OrderedDict, cls).__new__(cls, *args, **kwargs)
+ instance.keyOrder = []
+ return instance
+
+ def __init__(self, data=None):
+ if data is None:
+ data = {}
+ super(OrderedDict, self).__init__(data)
+ if isinstance(data, dict):
+ self.keyOrder = data.keys()
+ else:
+ self.keyOrder = []
+ for key, value in data:
+ if key not in self.keyOrder:
+ self.keyOrder.append(key)
- A treap is a binary search tree that orders the nodes by adding a priority
- attribute to a node, as well as a key. The nodes are ordered so that the
- keys form a binary search tree and the priorities obey the min heap order
- property. The name treap is a composition of tree and heap.
+ def __deepcopy__(self, memo):
+ from copy import deepcopy
+ return self.__class__([(key, deepcopy(value, memo))
+ for key, value in self.iteritems()])
- The priority determines the node's location in the heap, which allows
- extracting the dictionary's nodes in a prioritized order. Each new node
- entry causes the heap to re-balance.
+ def __setitem__(self, key, value):
+ super(OrderedDict, self).__setitem__(key, value)
+ if key not in self.keyOrder:
+ self.keyOrder.append(key)
- Keyword Argument:
- default -- begin/end, determines where unprioritized dict entry is ordered. (Default: begin.)
+ def __delitem__(self, key):
+ super(OrderedDict, self).__delitem__(key)
+ self.keyOrder.remove(key)
- """
- _r_BRACE = re.compile(r'^([<>])?(.+)')
- def __init__(self, default='end'):
- self.default = '_'+('begin',default)[default in ('begin','end')]
- self.priority = None
- self._lastItem = "_begin"
- self._tree = {
- '_begin' : {'heap':('_begin','B'),'kids' : {},'prio' : 'B'}
- ,'_end' : {'heap':('_end','E'),'kids' : {},'prio' : 'E'}
- }
- self._reset()
- dict.__setitem__(self, '_begin', None)
- dict.__setitem__(self, '_end', None)
+ def __iter__(self):
+ for k in self.keyOrder:
+ yield k
- def __delitem__(self, key):
- # Remove item from hash-tree and linking its kids to its parent
- parn, brace = self._prior(self._tree[key]['prio'])
- self._tree[parn]['kids'].pop(key, None)
- for k, b in self._tree[key]['kids'].items():
- self.link(k, b + parn)
- del self._tree[key]
- dict.__delitem__(self, key)
-
- def __setitem__(self, key, val, *args):
- if key not in self._tree:
- if len(args):
- prio = args[0]
- else:
- prio = (self.default, self.priority)[self.priority != None]
-
- self._tree.setdefault(key, {'kids' : {},'prio' : prio})
- self.link(key, prio)
- self._reset()
- dict.__setitem__(self, key, val)
-
- def add(self, k, v, p=None):
- """Adds key/value to dict and sets priority."""
- if p is None:
- p = self._lastItem
- self.__setitem__(k, v, p)
- self._lastItem = ">%s" % k
-
- def _reset(self): self._heap=[];self._keys=[];self._vals=[];self._items=[];
-
- def _prior(self, p):
- m = self._r_BRACE.match(p)
- if m.group(1) is None: b = '='
- else: b = m.group(1)
- return m.group(2), b
-
- def link(self, key, priority):
- """Sets priority for already-existing key/value pair."""
- self._reset()
- parn, brace = self._prior(priority)
- #if parn in self._tree:
+ def pop(self, k, *args):
+ result = super(OrderedDict, self).pop(k, *args)
try:
- self._tree[parn]['kids'][key] = brace
- if 'heap' in self._tree[parn]:
- self._tree[key]['heap']=(
- key,
- self._tree[parn]['heap'][1]+brace
- )
- for k,v in self._tree[key]['kids'].iteritems():
- self.link(k, v+key)
- self._tree[key]['prio'] = priority
-
- except:
- message(CRITICAL,
- "Key (%s)'s parent (%s) missing." % (key, priority))
+ self.keyOrder.remove(k)
+ except ValueError:
+ # Key wasn't in the dictionary in the first place. No problem.
+ pass
+ return result
+
+ def popitem(self):
+ result = super(OrderedDict, self).popitem()
+ self.keyOrder.remove(result[0])
+ return result
def items(self):
- """Returns list of unsorted key/value tuples."""
- if not len(self._items):
- dic = dict.copy(self)
- del dic['_begin']
- del dic['_end']
- self._items = dic.items()
- return self._items
-
- def values(self):
- """Returns list of unsorted values."""
- if not len(self._vals):
- dic = dict.copy(self)
- del dic['_begin']
- del dic['_end']
- self._vals = dic.values()
- return self._vals
+ return zip(self.keyOrder, self.values())
- def keys(self):
- """Returns list of unsorted keys."""
- if not len(self._keys):
- self._keys = dict.keys(self)
- self._keys.remove('_begin')
- self._keys.remove('_end')
-
- return self._keys
-
- def heapsorted(self, keys=0, items=0):
- """Do heap sort and return list. (Default returns values.)
-
- Keyword Arguments:
- keys -- when true, returns heap-sorted list of keys. (default: false)
- items -- when true, returns heap-sorted list of key/value tuples. (default: false)
- (if both set, items have precedent.)
+ def iteritems(self):
+ for key in self.keyOrder:
+ yield key, super(OrderedDict, self).__getitem__(key)
+ def keys(self):
+ return self.keyOrder[:]
+
+ def iterkeys(self):
+ return iter(self.keyOrder)
+
+ def values(self):
+ return [super(OrderedDict, self).__getitem__(k) for k in self.keyOrder]
+
+ def itervalues(self):
+ for key in self.keyOrder:
+ yield super(OrderedDict, self).__getitem__(key)
+
+ def update(self, dict_):
+ for k, v in dict_.items():
+ self.__setitem__(k, v)
+
+ def setdefault(self, key, default):
+ if key not in self.keyOrder:
+ self.keyOrder.append(key)
+ return super(OrderedDict, self).setdefault(key, default)
+
+ def value_for_index(self, index):
+ """Return the value of the item at the given zero-based index."""
+ return self[self.keyOrder[index]]
+
+ def insert(self, index, key, value):
+ """Insert the key, value pair before the item with the given index."""
+ if key in self.keyOrder:
+ n = self.keyOrder.index(key)
+ del self.keyOrder[n]
+ if n < index:
+ index -= 1
+ self.keyOrder.insert(index, key)
+ super(OrderedDict, self).__setitem__(key, value)
+
+ def copy(self):
+ """Return a copy of this object."""
+ # This way of initializing the copy means it works for subclasses, too.
+ obj = self.__class__(self)
+ obj.keyOrder = self.keyOrder[:]
+ return obj
+
+ def __repr__(self):
"""
- if not len(self._heap):
- self._heap = [
- (k, dict.__getitem__(self,k)) for k in [
- s[0] for s in sorted(
- [v['heap'] for v in self._tree.values()]
- ,key=itemgetter(1)
- )
- ]
- ]
- for h in self._heap:
- if h[0] in ('_begin','_end'):
- self._heap.remove(h)
+ Replace the normal dict.__repr__ with a version that returns the keys
+ in their sorted order.
+ """
+ return '{%s}' % ', '.join(['%r: %r' % (k, v) for k, v in self.items()])
+
+ def clear(self):
+ super(OrderedDict, self).clear()
+ self.keyOrder = []
+
+ def index(self, key):
+ """ Return the index of a given key. """
+ return self.keyOrder.index(key)
+
+ def index_for_location(self, location):
+ """ Return index or None for a given location. """
+ if location == '_begin':
+ i = 0
+ elif location == '_end':
+ i = None
+ elif location.startswith('<') or location.startswith('>'):
+ i = self.index(location[1:])
+ if location.startswith('>'):
+ if i >= len(self):
+ # last item
+ i = None
+ else:
+ i += 1
+ else:
+ raise ValueError('Not a valid location: "%s". Location key '
+ 'must start with a ">" or "<".' % location)
+ return i
+
+ def add(self, key, value, location):
+ """ Insert by key location. """
+ i = self.index_for_location(location)
+ if i is not None:
+ self.insert(i, key, value)
+ else:
+ self.__setitem__(key, value)
- if items:
- return self._heap
- elif keys:
- return [ h[0] for h in self._heap ]
+ def link(self, key, location):
+ """ Change location of an existing item. """
+ n = self.keyOrder.index(key)
+ del self.keyOrder[n]
+ i = self.index_for_location(location)
+ try:
+ if i is not None:
+ self.keyOrder.insert(i, key)
+ else:
+ self.keyOrder.append(key)
+ except Error:
+ # restore to prevent data loss and reraise
+ self.keyOrder.insert(n, key)
+ raise Error
- return [ h[1] for h in self._heap ]
"""
Markdown
@@ -1761,47 +1781,47 @@ class Markdown:
self.docType = ""
self.stripTopLevelTags = True
- self.preprocessors = Treap()
- self.preprocessors.add("html_block", HtmlBlockPreprocessor(self))
- self.preprocessors.add("header", HeaderPreprocessor(self))
- self.preprocessors.add("line", LinePreprocessor(self))
- self.preprocessors.add("reference", ReferencePreprocessor(self))
+ self.preprocessors = OrderedDict()
+ self.preprocessors["html_block"] = HtmlBlockPreprocessor(self)
+ self.preprocessors["header"] = HeaderPreprocessor(self)
+ self.preprocessors["line"] = LinePreprocessor(self)
+ self.preprocessors["reference"] = ReferencePreprocessor(self)
# footnote preprocessor will be inserted with "<reference"
- self.treeprocessors = Treap()
- self.treeprocessors.add("inline", InlineProcessor(self))
- self.treeprocessors.add("prettify", PrettifyTreeprocessor(self))
+ self.treeprocessors = OrderedDict()
+ self.treeprocessors["inline"] = InlineProcessor(self)
+ self.treeprocessors["prettify"] = PrettifyTreeprocessor(self)
- self.postprocessors = Treap()
- self.postprocessors.add("raw_html", RawHtmlPostprocessor(self))
- self.postprocessors.add("amp_substitute", AndSubstitutePostprocessor())
+ self.postprocessors = OrderedDict()
+ self.postprocessors["raw_html"] = RawHtmlPostprocessor(self)
+ self.postprocessors["amp_substitute"] = AndSubstitutePostprocessor()
# footnote postprocessor will be inserted with ">amp_substitute"
self.prePatterns = []
- self.inlinePatterns = Treap()
- self.inlinePatterns.add("backtick", BacktickPattern(BACKTICK_RE))
- self.inlinePatterns.add("escape", SimpleTextPattern(ESCAPE_RE))
- self.inlinePatterns.add("reference", ReferencePattern(REFERENCE_RE, self))
- self.inlinePatterns.add("link", LinkPattern(LINK_RE, self))
- self.inlinePatterns.add("image_link", ImagePattern(IMAGE_LINK_RE, self))
- self.inlinePatterns.add("image_reference",
- ImageReferencePattern(IMAGE_REFERENCE_RE, self))
- self.inlinePatterns.add("autolink", AutolinkPattern(AUTOLINK_RE, self))
- self.inlinePatterns.add("automail", AutomailPattern(AUTOMAIL_RE, self))
- self.inlinePatterns.add("linebreak2",
- SubstituteTagPattern(LINE_BREAK_2_RE, 'br'))
- self.inlinePatterns.add("linebreak",
- SubstituteTagPattern(LINE_BREAK_RE, 'br'))
- self.inlinePatterns.add("html", HtmlPattern(HTML_RE, self))
- self.inlinePatterns.add("entity", HtmlPattern(ENTITY_RE, self))
- self.inlinePatterns.add("not_strong", SimpleTextPattern(NOT_STRONG_RE))
- self.inlinePatterns.add("strong_em",
- DoubleTagPattern(STRONG_EM_RE, 'strong,em'))
- self.inlinePatterns.add("strong", SimpleTagPattern(STRONG_RE, 'strong'))
- self.inlinePatterns.add("emphasis", SimpleTagPattern(EMPHASIS_RE, 'em'))
- self.inlinePatterns.add("emphasis2",
- SimpleTagPattern(EMPHASIS_2_RE, 'em'))
+ self.inlinePatterns = OrderedDict()
+ self.inlinePatterns["backtick"] = BacktickPattern(BACKTICK_RE)
+ self.inlinePatterns["escape"] = SimpleTextPattern(ESCAPE_RE)
+ self.inlinePatterns["reference"] = ReferencePattern(REFERENCE_RE, self)
+ self.inlinePatterns["link"] = LinkPattern(LINK_RE, self)
+ self.inlinePatterns["image_link"] = ImagePattern(IMAGE_LINK_RE, self)
+ self.inlinePatterns["image_reference"] = \
+ ImageReferencePattern(IMAGE_REFERENCE_RE, self)
+ self.inlinePatterns["autolink"] = AutolinkPattern(AUTOLINK_RE, self)
+ self.inlinePatterns["automail"] = AutomailPattern(AUTOMAIL_RE, self)
+ self.inlinePatterns["linebreak2"] = \
+ SubstituteTagPattern(LINE_BREAK_2_RE, 'br')
+ self.inlinePatterns["linebreak"] = \
+ SubstituteTagPattern(LINE_BREAK_RE, 'br')
+ self.inlinePatterns["html"] = HtmlPattern(HTML_RE, self)
+ self.inlinePatterns["entity"] = HtmlPattern(ENTITY_RE, self)
+ self.inlinePatterns["not_strong"] = SimpleTextPattern(NOT_STRONG_RE)
+ self.inlinePatterns["strong_em"] = \
+ DoubleTagPattern(STRONG_EM_RE, 'strong,em')
+ self.inlinePatterns["strong"] = SimpleTagPattern(STRONG_RE, 'strong')
+ self.inlinePatterns["emphasis"] = SimpleTagPattern(EMPHASIS_RE, 'em')
+ self.inlinePatterns["emphasis2"] = \
+ SimpleTagPattern(EMPHASIS_2_RE, 'em')
# The order of the handlers matters!!!
self.references = {}
@@ -1811,7 +1831,7 @@ class Markdown:
self.reset()
# Sort and add patterns only after all extensions are loaded.
- self.treeprocessors['inline'].patterns = self.inlinePatterns.heapsorted()
+ self.treeprocessors['inline'].patterns = self.inlinePatterns.values()
def registerExtensions(self, extensions, configs):
"""
@@ -1869,14 +1889,14 @@ class Markdown:
# Split into lines and run the line preprocessors.
self.lines = source.split("\n")
- for prep in self.preprocessors.heapsorted():
+ for prep in self.preprocessors.values():
self.lines = prep.run(self.lines)
# Parse the high-level elements.
root = self.parser.parseDocument(self.lines).getroot()
# Run the tree-processors
- for treeprocessor in self.treeprocessors.heapsorted():
+ for treeprocessor in self.treeprocessors.values():
newRoot = treeprocessor.run(root)
if newRoot:
root = newRoot
@@ -1887,7 +1907,7 @@ class Markdown:
xml = xml.strip()[44:-7] + "\n"
# Run the text post-processors
- for pp in self.postprocessors.heapsorted():
+ for pp in self.postprocessors.values():
xml = pp.run(xml)
return xml.strip()
diff --git a/markdown_extensions/tables.py b/markdown_extensions/tables.py
index 5339ae1..0e5cd96 100644
--- a/markdown_extensions/tables.py
+++ b/markdown_extensions/tables.py
@@ -62,7 +62,7 @@ class TableTreeprocessor(markdown.Treeprocessor):
class TableExtension(markdown.Extension):
def extendMarkdown(self, md, md_globals):
md.inlinePatterns.add('table', TablePattern(md), "<backtick")
- md.treeprocessors['table'] = TableTreeprocessor()
+ md.treeprocessors.add('table', TableTreeprocessor(), "<prettify")
def makeExtension(configs):
diff --git a/regression-tests.py b/regression-tests.py
index c8f784c..09dd313 100755
--- a/regression-tests.py
+++ b/regression-tests.py
@@ -75,74 +75,97 @@ class TestHtmlStash(unittest.TestCase):
self.assertEqual(self.stash.html_counter, 0)
self.assertEqual(self.stash.rawHtmlBlocks, [])
-class TestTreap(unittest.TestCase):
- """ Test Treap storage class. """
+class TestOrderedDict(unittest.TestCase):
+ """ Test OrderedDict storage class. """
def setUp(self):
- self.treap = markdown.Treap()
- self.treap.add('first', 'This', '_begin')
- self.treap.add('second', 'is', '>first')
- self.treap.add('fourth', 'self', '>second')
- self.treap.add('fifth', 'test', '>fourth')
- self.treap.add('third', 'a', '>second')
- self.treap['seventh'] = '.'
-
- def testHeapsorted(self):
- """ Test output of Treap.heapsorted(). """
- self.assertEqual(self.treap.heapsorted(),
- ['This', 'is', 'a', 'self', 'test','.'])
- self.assertEqual(self.treap.heapsorted(keys=1),
- ['first', 'second', 'third', 'fourth', 'fifth','seventh'])
- self.assertEqual(self.treap.heapsorted(items=1),
+ self.odict = markdown.OrderedDict()
+ self.odict['first'] = 'This'
+ self.odict['third'] = 'a'
+ self.odict['fourth'] = 'self'
+ self.odict['fifth'] = 'test'
+
+ def testValues(self):
+ """ Test output of OrderedDict.values(). """
+ self.assertEqual(self.odict.values(), ['This', 'a', 'self', 'test'])
+
+ def testKeys(self):
+ """ Test output of OrderedDict.keys(). """
+ self.assertEqual(self.odict.keys(),
+ ['first', 'third', 'fourth', 'fifth'])
+
+ def testItems(self):
+ """ Test output of OrderedDict.items(). """
+ self.assertEqual(self.odict.items(),
+ [('first', 'This'), ('third', 'a'),
+ ('fourth', 'self'), ('fifth', 'test')])
+
+ def testAddBefore(self):
+ """ Test adding an OrderedDict item before a given key. """
+ self.odict.add('second', 'is', '<third')
+ self.assertEqual(self.odict.items(),
[('first', 'This'), ('second', 'is'), ('third', 'a'),
- ('fourth', 'self'), ('fifth', 'test'), ('seventh','.')])
-
- def testDictStorage(self):
- """ Test Treap's Dict Storage. """
- self.treap._reset()
- self.assertEqual(self.treap.values(), self.treap._vals)
- self.assertEqual(self.treap.keys(), self.treap._keys)
- self.assertEqual(self.treap.items(), self.treap._items)
-
- def testDeleteNode(self):
- """ Test deletion of a Treap node. """
- del self.treap['second']
- self.assertEqual(self.treap.heapsorted(),
- ['This', 'a', 'self', 'test','.'])
- self.assertEqual(self.treap.heapsorted(keys=1),
- ['first', 'third', 'fourth', 'fifth','seventh'])
- self.assertEqual(self.treap.heapsorted(items=1),
- [('first', 'This'), ('third', 'a'), ('fourth', 'self'),
- ('fifth', 'test'), ('seventh','.')])
+ ('fourth', 'self'), ('fifth', 'test')])
- def testChangeValue(self):
- """ Test Treap change value. """
- self.treap['seventh'] = 'CRAZY'
- self.assertEqual(self.treap.heapsorted(),
- ['This', 'is', 'a', 'self', 'test','CRAZY'])
- self.assertEqual(self.treap.heapsorted(keys=1),
- ['first', 'second', 'third', 'fourth', 'fifth','seventh'])
- self.assertEqual(self.treap.heapsorted(items=1),
- [('first', 'This'), ('second', 'is'), ('third', 'a'),
- ('fourth', 'self'), ('fifth', 'test'), ('seventh','CRAZY')])
-
- def testChangePriority(self):
- """ Test Treap change priority. """
- self.treap.link('seventh', '<third')
- self.assertEqual(self.treap.heapsorted(),
- ['This', 'is', 'a', 'self', '.', 'test'])
- self.assertEqual(self.treap.heapsorted(keys=1),
- ['first', 'second', 'third', 'fourth', 'seventh', 'fifth'])
- self.assertEqual(self.treap.heapsorted(items=1),
+ def testAddAfter(self):
+ """ Test adding an OrderDict item after a given key. """
+ self.odict.add('second', 'is', '>first')
+ self.assertEqual(self.odict.items(),
[('first', 'This'), ('second', 'is'), ('third', 'a'),
- ('fourth', 'self'), ('seventh','.'), ('fifth', 'test')])
+ ('fourth', 'self'), ('fifth', 'test')])
+
+ def testAddAfterEnd(self):
+ """ Test adding an OrderedDict item after the last key. """
+ self.odict.add('sixth', '.', '>fifth')
+ self.assertEqual(self.odict.items(),
+ [('first', 'This'), ('third', 'a'),
+ ('fourth', 'self'), ('fifth', 'test'), ('sixth', '.')])
+
+ def testAdd_begin(self):
+ """ Test adding an OrderedDict item using "_begin". """
+ self.odict.add('zero', 'CRAZY', '_begin')
+ self.assertEqual(self.odict.items(),
+ [('zero', 'CRAZY'), ('first', 'This'), ('third', 'a'),
+ ('fourth', 'self'), ('fifth', 'test')])
+
+ def testAdd_end(self):
+ """ Test adding an OrderedDict item using "_end". """
+ self.odict.add('sixth', '.', '_end')
+ self.assertEqual(self.odict.items(),
+ [('first', 'This'), ('third', 'a'),
+ ('fourth', 'self'), ('fifth', 'test'), ('sixth', '.')])
+
+ def testAddBadLocation(self):
+ """ Test Error on bad location in OrderedDict.add(). """
+ self.assertRaises(ValueError, self.odict.add, 'sixth', '.', '<seventh')
+ self.assertRaises(ValueError, self.odict.add, 'second', 'is', 'third')
+
+ def testDeleteItem(self):
+ """ Test deletion of an OrderedDict item. """
+ del self.odict['fourth']
+ self.assertEqual(self.odict.items(),
+ [('first', 'This'), ('third', 'a'), ('fifth', 'test')])
+
+ def testChangeValue(self):
+ """ Test OrderedDict change value. """
+ self.odict['fourth'] = 'CRAZY'
+ self.assertEqual(self.odict.items(),
+ [('first', 'This'), ('third', 'a'),
+ ('fourth', 'CRAZY'), ('fifth', 'test')])
+
+ def testChangeOrder(self):
+ """ Test OrderedDict change order. """
+ self.odict.link('fourth', '<third')
+ self.assertEqual(self.odict.items(),
+ [('first', 'This'), ('fourth', 'self'),
+ ('third', 'a'), ('fifth', 'test')])
def suite():
""" Build a test suite of the above tests and extension doctests. """
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestMarkdownParser))
suite.addTest(unittest.makeSuite(TestHtmlStash))
- suite.addTest(unittest.makeSuite(TestTreap))
+ suite.addTest(unittest.makeSuite(TestOrderedDict))
for filename in os.listdir('markdown_extensions'):
if filename.endswith('.py'):
diff --git a/treap_test.py b/treap_test.py
deleted file mode 100644
index a1e2183..0000000
--- a/treap_test.py
+++ /dev/null
@@ -1,50 +0,0 @@
-from markdown import Treap
-
-if __name__ == '__main__':
- from pprint import pprint
-
- def test(t, b):
- if b is True:
- print t, "Passed"
- else:
- print t, "Failed"
-
- print "Testing..."
- r = Treap()
- r.add('first', 'This', '_begin')
- r.add('second', 'is', '>first')
- r.add('fourth', 'self', '>second')
- r.add('fifth', 'test', '>fourth')
- r.add('third', 'a', '>second')
- r['seventh'] = '.'
-
- print ".. Heapsort Test"
- test('.... vals', r.heapsorted() == ['This', 'is', 'a', 'self', 'test','.'])
- test('.... keys', r.heapsorted(keys=1) == ['first', 'second', 'third', 'fourth', 'fifth','seventh'])
- test('.... items', r.heapsorted(items=1) == [('first', 'This'), ('second', 'is'), ('third', 'a'), ('fourth', 'self'), ('fifth', 'test'), ('seventh','.')])
-
- print ".. Dict Storage Test"
- r._reset()
- test('.... vals', r.values() == r._vals)
- r._reset()
- test('.... keys', r.keys() == r._keys)
- r._reset()
- test('.... items', r.items() == r._items)
-
- print ".. Delete Node Test"
- del r['second']
- test('.... vals', r.heapsorted() == ['This', 'a', 'self', 'test','.'])
- test('.... keys', r.heapsorted(keys=1) == ['first', 'third', 'fourth', 'fifth','seventh'])
- test('.... items', r.heapsorted(items=1) == [('first', 'This'), ('third', 'a'), ('fourth', 'self'), ('fifth', 'test'), ('seventh','.')])
-
- print ".. Change value test."
- r['seventh'] = 'CRAZY'
- test('.... vals', r.heapsorted() == ['This', 'a', 'self', 'test','CRAZY'])
- test('.... keys', r.heapsorted(keys=1) == ['first', 'third', 'fourth', 'fifth','seventh'])
- test('.... items', r.heapsorted(items=1) == [('first', 'This'), ('third', 'a'), ('fourth', 'self'), ('fifth', 'test'), ('seventh','CRAZY')])
- print ".. Change priority test."
- r.link('seventh', '<third')
- test('.... vals', r.heapsorted() == ['This', 'a', 'self', 'CRAZY', 'test'])
- test('.... keys', r.heapsorted(keys=1) == ['first', 'third', 'fourth','seventh', 'fifth'])
- test('.... items', r.heapsorted(items=1) == [('first', 'This'), ('third', 'a'), ('fourth', 'self'), ('seventh','CRAZY'), ('fifth', 'test')])
-
1358'>1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901