Selaa lähdekoodia

Fix regression in previous commit on _ListProxy transformations (fixes #213)

tags/v0.5.3
Ben Kurtovic 5 vuotta sitten
vanhempi
commit
0ae5f6d641
2 muutettua tiedostoa jossa 19 lisäystä ja 5 poistoa
  1. +8
    -5
      mwparserfromhell/wikicode.py
  2. +11
    -0
      tests/test_wikicode.py

+ 8
- 5
mwparserfromhell/wikicode.py Näytä tiedosto

@@ -111,16 +111,19 @@ class Wikicode(StringMixIn):

def _is_child_wikicode(self, obj, recursive=True):
"""Return whether the given :class:`.Wikicode` is a descendant."""
nodes = obj.nodes
if isinstance(nodes, _ListProxy):
nodes = nodes._parent # pylint: disable=protected-access
if nodes is self.nodes:
def deref(nodes):
if isinstance(nodes, _ListProxy):
return nodes._parent # pylint: disable=protected-access
return nodes

target = deref(obj.nodes)
if target is deref(self.nodes):
return True
if recursive:
todo = [self]
while todo:
code = todo.pop()
if nodes is code.nodes:
if target is deref(code.nodes):
return True
for node in code.nodes:
todo += list(node.__children__())


+ 11
- 0
tests/test_wikicode.py Näytä tiedosto

@@ -225,6 +225,13 @@ class TestWikicode(TreeEqualityTestCase):
func(sec2, "\nbody")
self.assertEqual(expected[7], code8)

code9 = parse("{{foo}}")
meth(code9.get_sections()[0], code9.get_sections()[0], "{{bar}}")
meth(code9.get_sections()[0], code9, "{{baz}}")
meth(code9, code9, "{{qux}}")
meth(code9, code9.get_sections()[0], "{{quz}}")
self.assertEqual(expected[8], code9)

def test_insert_before(self):
"""test Wikicode.insert_before()"""
meth = lambda code, *args, **kw: code.insert_before(*args, **kw)
@@ -237,6 +244,7 @@ class TestWikicode(TreeEqualityTestCase):
"here cdis {{some abtext and a {{template}}}}",
"{{foo}}{{bar}}{{baz}}{{lol}}{{foo}}{{baz}}",
"lead\n== header ==\nbody",
"{{quz}}{{qux}}{{baz}}{{bar}}{{foo}}",
]
self._test_search(meth, expected)

@@ -252,6 +260,7 @@ class TestWikicode(TreeEqualityTestCase):
"here is {{somecd text andab a {{template}}}}",
"{{foo}}{{bar}}{{baz}}{{foo}}{{baz}}{{lol}}",
"lead\n== header ==\nbody",
"{{foo}}{{bar}}{{baz}}{{qux}}{{quz}}",
]
self._test_search(meth, expected)

@@ -267,6 +276,7 @@ class TestWikicode(TreeEqualityTestCase):
"here cd ab a {{template}}}}",
"{{foo}}{{bar}}{{baz}}{{lol}}",
"lead\n== header ==\nbody",
"{{quz}}",
]
self._test_search(meth, expected)

@@ -294,6 +304,7 @@ class TestWikicode(TreeEqualityTestCase):
"here a {{template}}}}",
"{{foo}}{{bar}}{{baz}}",
"== header ==",
"",
]
self._test_search(meth, expected)



Ladataan…
Peruuta
Tallenna